From what I understand of Capybara's autowait feature, it waits for the DOM to change, so I guess it's waiting for all AJAX requests to complete and/or the main frame to finish loading.
I have a test case in which I need to:
- fill in a field (
name_1
) - click a save button
- check the object is saved properly
When I fill in the name_1
field, some JS from the app I'm testing fills in other mandatory fields automatically (notably, link_rewrite_1
).
Problem is, when I check for the other field to be actually filled, it is not! I'm thinking the JS that fills the other fields has not had time to complete when the test is run, and the test doesn't wait since there is no AJAX call pending.
Here is the relevant code snippet:
fill_in 'name_1', :with => 'Bob' #some javascript should run and fill link_rewrite_1
find('#link-Seo').click
page.should_not have_field('link_rewrite_1', with: "")
In plain English, I fill in name_1
and expect link_rewrite_1
not to be empty.
I've tried to insert a sleep 1
before the last check, but it doesn't change anything. Since sleep will pause the execution of the entire ruby thread, maybe it just freezes webkit and changes nothing, I don't know.
Am I right in suspecting a timing issue or is there likely something else going on here?