capybara: fill_in sometimes does not finish filling in a field
Meta
Capybara Version: 2.13.0 Driver Information (and browser if relevant): selenium-webdriver (3.4.3) with chrome Version 59.0.3071.115
Expected Behavior
Using fill_in finishes filling in the field before moving on.
Actual Behavior
Sometimes when filling in a text field with fill_in, the desired content is not done filling in before capybara moves on, causing subsequent expectations to fail.
Steps to reproduce
- Fill in a text field with capybara
- Have an expectation later that checks for the content of that field
- Sometimes (not always), the expectation will fail because the field was only partially filled in
Example:
fill_in 'my_text_field', with: 'This is a test'
click_on 'Submit'
expect(page).to have_content 'This is a test'
=> Failure/Error: expect(page).to have_content 'This is a test'
expected to find text "This is a test" in "This is a te"
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 8
- Comments: 16 (5 by maintainers)
Commits related to this issue
- Remove event handler for autofocus on modal shown This resolves a timing issue affecting the Event Config feature. Although the Bootstrap documentation advises adding this snippet, the docs do not a... — committed to rubyberlin/cfp-app by myabc 6 years ago
- Remove event handler for autofocus on modal shown This resolves a timing issue affecting the Event Config feature. Although the Bootstrap documentation advises adding this snippet, the docs do not a... — committed to rubyberlin/cfp-app by myabc 6 years ago
- Disable bootstrap modal fades to fix integration tests. Our CSS approach to disable animations doesn't seem sufficient for some reason with headless chrome. So go ahead and disable the fades complete... — committed to NREL/api-umbrella by GUI 6 years ago
After switching from poltergeist/phantomjs to headless chrome, I had similar issues which were related to CSS3 animations with Bootstrap modals. The final solution was to remove the
fadeclass for those modals, other ways of disabling animations in tests didn’t work for me.I tried the solutions listed here, and others like checking for any elements matching jQuery’s
:animatedselector, but the only thing that consistently worked was to removefadelike @lacco suggested.i’m using send_keys
I also ran into this issue, and was able to come up with a simple repro-script. The culprit is a bootstrap modal, so the problem seems to be caused by animated elements. This script fails always for me:
I guess the reason why this comes up more often now is that headless chrome is more susceptible to this than phantomjs (this test passes when poltergeist is used as a driver).
I was able to get this to pass by doing the following:
This also makes the problems go away in my test suite.
So in conclusion: this most probably has nothing to do with capybara.
Another approach was to disable animations/transitions/transformations in CSS. But there still were ~ 30% probability of errors when we have been using Bootstrap modals with
fadeclass. Removingfadeclass in test environment solved the problem. Thanks @lacco!