ajax requests not working properly #493

Closed
abacha opened this Issue Mar 19, 2013 · 5 comments

Comments

Projects
None yet
5 participants

abacha commented Mar 19, 2013

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: "newmail@mail.com"
      click_on "Salvar"
    end
    # ap page.driver.alert_messages

    Person.exists?(email: "newmail@mail.com").should be_true
  end
Owner

jferris commented Mar 19, 2013

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: 'newmail@mail.com'). 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.

@jferris jferris closed this Mar 19, 2013

abacha commented Mar 19, 2013

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: "newmail@mail.com") }.to become_true

daniel-g commented Apr 5, 2013

look at this issue: jnicklas/capybara#1039 I think it belongs to capybara-webkit

Collaborator

mhoran commented Apr 5, 2013

@daniel-g, could you check out the master branch? I may have pushed a fix for your issue yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment