Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

ajax requests not working properly #493

Closed
abacha opened this Issue · 5 comments

5 participants

@abacha

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
@jferris
Owner

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
@abacha

thanks

@DimaSamodurov

@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

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

@mhoran
Collaborator

@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.