简体   繁体   中英

Rspec, Capybara, selenium_chrome_headless. Wait for response after submit remote form

In use Rails 6, Rspec rspec-rails (3.9.0) , Capybara capybara (3.31.0) , selenium_chrome_headless

I try to submit ajax form with remote: true . How can I wait for response?

Now works sleep 0.2 but I really don't like approach like this.

I found another way:

  Timeout.timeout(Capybara.default_wait_time) do
    loop do
      active = page.evaluate_script('jQuery.active')
      break if active == 0
    end
  end

but it doesn't work.

My recodr should dissapear after request:

expect(page).to_not have_content('User name')

Any suggestion? Thanks for advance

You should set an expectation for whatever visibly changes in the page when the request is done. If that means the text "User name" disappears from the page when the request has finished then your expectation of

expect(page).not_to have_content('User name')

or

expect(page).to have_no_content('User name')

will wait until that content (same as have_text) isn't visible on the page anymore (up to Capybara.default_wait_time seconds), which would imply the request has completed. If that text is on the page multiple times and only being removed from one location then you could use a count option in have_content or scope your not have content expectation to the specific section of the page where the text is being removed from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM