Reputation: 5126
I'm using chromedriver 2.30 with capybara 2.14.4 under rspec 3.6.0
fill_in "total-amount", with: "33"
expect(find_by_id("total-amount").value).to have_text("33")
click_on "create_btn"
Sometimes I will get the error
1) Create purchase with discount transaction creates a Sales Return Transaction
Failure/Error: expect(find_by_id("total-amount").value).to have_text("33")
expected to find text "33" in "3"
# ./spec/integration/transactions/create_purchase_with_discount_spec.rb:67:in `block (2 levels) in <top (required)>'
It is like fill_in is entering the characters one at a time. How do I get fill_in to put all the characters in at once?
Update
I tried
expect(page).to have_field('total-amount', with: "33")
but got this flaky error
expected to find field "total-amount" with value "33" but there were no matches. Also found "", which matched the selector but not all filters.
It's finding the element, but the value hasn't been entered in there yet even though the fill_in line is before it. I'm using material design and there are calculations going on all these fields which may affect the time in which these elements update.
Update
Changed default_max_wait_time to 20seconds, still get the problem
Update
If I put sleeps around the fill_in "total-amount", with: "33" like so;
sleep 1
fill_in "total-amount", with: "33"
sleep 1
expect(find_by_id("total-amount").value).to have_text("33")
click_on "create_btn"
This works, but putting sleeps is wrong! So I still need a way to check that what I've entered into the material design box is actually in there and set to the angular model before continuing.
Upvotes: 2
Views: 2054
Reputation: 21
Chromedriver with Selenium does not support well unfocused fill in
user experience for any input have 2 steps:
to make your tests done, use this code:
area = find("#total-amount").click # user usually click before input
area.send_keys "33"
Upvotes: 2
Reputation: 10409
It looks like you're bumping into the race condition mentioned in the Capybara, a patient animal section of this post.
I can't find a canonical list of methods which wait provided by the Capybara docs, but based on the list provided in that blog post, #has_field?
should wait and prevent the race condition you're seeing.
page.has_field?('total-amount', :with => '33')
Upvotes: 0