small medium large xlarge

Generic-user-small
25 Jul 2017, 10:27
John Yeates (8 posts)

When I run the tests on pp211-212, I get the following:

E

Error:
OrdersTest#test_cheque_routing_number:
Capybara::ElementNotFound: Unable to find select box "pay_type"
    test/system/orders_test.rb:15:in `block in <class:OrdersTest>'


bin/rails test test/system/orders_test.rb:4

The screenshot that Capybara saves shows the pay_type select box is visible.

PayTypeSelector/index.jsx has this in it:

          <label htmlFor="pay_type">Pay type</label>
          <select id="pay_type" onChange={this.onPayTypeSelected} name="order[pay_type]">

so I can’t see where this could be going wrong (note I changed the htmlFor in the to match what the id of the is :)

I’ve tried setting Capybara.default_max_wait_time = 10 in test_helper.rb but it just makes me wait longer before it fails.

Does anybody have any ideas why it’s not seeing a control that’s blatantly there?

Generic-user-small
25 Jul 2017, 10:40
John Yeates (8 posts)

Despite the fact that the Capybara docs say you can search by name, id or label of the select box, only using the name seems to work. Replacing the line in the test with select 'Cheque', from: 'order[pay_type]' fixes the issue. But how come searching by id or label don’t work when the docs say they do?

Dmfcb_pragsmall
25 Jul 2017, 14:26
David Copeland (467 posts)

That’s odd. The code is tested when the book is built, so it should work. Capybara often falls victim to odd timing issues.

I’ve added this to our errata and will look into it before the next beta.

Generic-user-small
26 Jul 2017, 09:22
John Yeates (8 posts)

Thanks — I’m also having problems at page 231, where the tests have started failing with

Error:
OrdersTest#test_cheque_routing_number:
ActionView::Template::Error: undefined method `javascript_pack_tag' for #<#<Class:0x007fc4cf5ac120>:0x007fc4cf59d878>
Did you mean?  javascript_path
               javascript_tag
    app/views/orders/new.html.erb:8:in `_app_views_orders_new_html_erb__1793964980887965413_70241634575120'

even though webpack-dev-server is running. Do you have any idea what could be going on there?

Dmfcb_pragsmall
26 Jul 2017, 11:50
David Copeland (467 posts)

That sounds like you don’t have webpacker installed. Webpacker provides that helper. If you do believe it’s installed, can you post your in-progress app somewhere, e.g. github?

Generic-user-small
26 Jul 2017, 13:19
John Yeates (8 posts)

Thanks — the bizarre thing is that it’s running fine in dev, and the webpacker gem isn’t in the development group…

The code’s up on Bitbucket

Generic-user-small
05 Oct 2017, 14:37
Nikolay Donchev (8 posts)

It is not working here too. Here is the error:

Error: OrdersTest#test_check_routing_number: Capybara::ElementNotFound: Unable to find visible select box “pay_type” that is not disabled test/system/orders_test.rb:24:in `block in '

Here is my code

assert_no_selector "#order_routing_number"

    select 'Check', from: 'pay_type'

    assert_selector "#order_routing_number"
Dmfcb_pragsmall
06 Oct 2017, 12:15
David Copeland (467 posts)

Can you post your code?

Also does it work in dev?

If yes, it might be a race condition where the test is executed before the page is rendered. Looking at your code might help figure that out

Generic-user-small
06 Oct 2017, 12:19
Nikolay Donchev (8 posts)

Thanks for your quick answer, David!

Here is the code:

require "application_system_test_case"

class OrdersTest < ApplicationSystemTestCase
  include ActiveJob::TestHelper

  test "check routing number" do
    LineItem.delete_all
    Order.delete_all

    visit store_index_url

    visit store_index_url

    first('.catalog li').click_on 'Add to Cart'

    click_on 'Checkout'

    fill_in 'order_name', with: 'Dave Thomas'
    fill_in 'order_address', with: '123 Main Street'
    fill_in 'order_email', with: 'dave@example.com'

    assert_no_selector "#order_routing_number"

    select 'Check', from: 'pay_type'

    assert_selector "#order_routing_number"

    fill_in "Routing #", with: "123456"
    fill_in "Account #", with: "987654"

    perform_enqueued_jobs do
      click_button "Place Order"
    end

    orders = Order.all
    assert_equal 1, orders.size

    order = orders.first

    assert_equal "Dave Thomas", order.name
    assert_equal "123 Main Street", order.address
    assert_equal "dave@example.com", order.email
    assert_equal "Check", order.pay_type
    assert_equal 1, order.line_items.size

    mail = ActionMailer::Base.deliveries.last
    assert_equal ["dave@example.com"], mail.to
    assert_equal 'Sam Ruby <depot@example.com>', mail[:from].value
    assert_equal "Pragmatic Store Order Confirmation", mail.subject
  end
end

Thanks once again!

Dmfcb_pragsmall
06 Oct 2017, 12:41
David Copeland (467 posts)

Do you have your entire app somewhere public? Seeing the code being tested is helpful, too.

Generic-user-small
06 Oct 2017, 14:04
Nikolay Donchev (8 posts)

Please provide an e-mail and I will add you to my hidden BitBucket repository.

Generic-user-small
10 Oct 2017, 12:38
Nikolay Donchev (8 posts)

Please let me know how to proceed. It’s been four days and I still don’t know what to do.

Dmfcb_pragsmall
10 Oct 2017, 13:17
David Copeland (467 posts)

Can you post your code somewhere public? I don’t want to have to sign up for bitbucket if I don’t have to.

Generic-user-small
10 Oct 2017, 13:19
Nikolay Donchev (8 posts)

I opened to public my repository for you: https://by_ivanov@bitbucket.org/by_ivanov/depot-application.git

Dmfcb_pragsmall
10 Oct 2017, 14:31
David Copeland (467 posts)

The critical information was if it was working in dev—it’s not, meaning your config is messed up.

You should not feel bad—the configuration is very complicated for reasons I can’t comprehend.

But, it looks like if you add "react" to your .babelrc file, it will fix things:

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": "> 1%",
        "uglify": true
      },
      "useBuiltIns": true
    }],
    "react"
  ],

  "plugins": [
    "syntax-dynamic-import",
    "transform-object-rest-spread",
    ["transform-class-properties", { "spec": true }]
  ]
}

Not sure why that wasn’t there for you already—the rake task in webpacker should’ve set it up like this.

Generic-user-small
10 Oct 2017, 14:37
Nikolay Donchev (8 posts)

I added it to my .babelrc , restart the server too, but none of these things helped. It still shows me the same error.

Dmfcb_pragsmall
10 Oct 2017, 16:23
David Copeland (467 posts)

That is what I had locally and your app worked for me.

Generic-user-small
11 Oct 2017, 13:27
Nikolay Donchev (8 posts)

Okay, I installed a React again with Webpacker and it worked, but now I received something like this:

Failure: OrdersTest#test_check_routing_number [/depot/test/system/orders_test.rb:38]: expected to find visible css “#order_routing_number” but there were no matches

I pushed the changes to my repository.

Dmfcb_pragsmall
13 Oct 2017, 12:18
David Copeland (467 posts)

You should always try the app in development if you are having trouble with the tests passing. Your app is broken in development, so the tests are definitely going to fail.

This is the error I get selecting “Check” from the pay type drop down:

https://www.evernote.com/l/AEcwWigBJEpGopb0KAyxEOv9VJb6n1Gt3ZQ

You must be logged in to comment