capybara-webkit icon indicating copy to clipboard operation
capybara-webkit copied to clipboard

ajax requests not working properly

Open abacha opened this issue 13 years ago • 5 comments

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

abacha avatar Mar 19 '13 18:03 abacha

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.

jferris avatar Mar 19 '13 18:03 jferris

thanks

abacha avatar Mar 19 '13 18:03 abacha

@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

DimaSamodurov avatar Mar 19 '13 21:03 DimaSamodurov

look at this issue: https://github.com/jnicklas/capybara/issues/1039 I think it belongs to capybara-webkit

daniel-g avatar Apr 05 '13 01:04 daniel-g

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

mhoran avatar Apr 05 '13 01:04 mhoran