Skip to content


Subversion checkout URL

You can clone with
Download ZIP


ajax requests not working properly #493

abacha opened this Issue · 5 comments

5 participants


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: ""
      click_on "Salvar"
    # ap page.driver.alert_messages

    Person.exists?(email: "").should be_true

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: ''). 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



@abacha might be helpful in your case.
Code could look like:

expect{ Person.exists?(email: "") }.to become_true

look at this issue: jnicklas/capybara#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.