ajax requests not working properly
My spec is failing because its not waiting for ajax requests, I've tried increasing the "default_wait_time" but it also didn't work.
The odd thing is if I uncomment the debug on page.driver.alert_messages it passes
scenario "updating email", js: true, focus: true do
person = create(:person)
login_as create(:user, role: "Operacional")
visit "/people"
find(:xpath, '//*[@id="body"]/table/tbody/tr[1]/td[6]/a[2]').click
within "#edit_email" do
fill_in "Email", with: "[email protected]"
click_on "Salvar"
end
# ap page.driver.alert_messages
Person.exists?(email: "[email protected]").should be_true
end
Capybara has no control over your database, so checking Person.exists? will execute immediately before asynchronous requests finish and fail.
A better solution is to verify that something is on the page. For example, page.should have_css('.person', text: '[email protected]'). When checking for elements on the page, Capybara will retry up to two seconds if it doesn't find it the first time.
Checking through the UI has the added benefit that it keeps your acceptance tests at the user's perspective. Users don't care that their email is in a database; they just care that it appears correctly on the page.
thanks
@abacha http://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara might be helpful in your case. Code could look like:
expect{ Person.exists?(email: "[email protected]") }.to become_true
look at this issue: https://github.com/jnicklas/capybara/issues/1039 I think it belongs to capybara-webkit
@daniel-g, could you check out the master branch? I may have pushed a fix for your issue yesterday.