Reputation: 3722
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
Upvotes: 1
Views: 923
Reputation: 49890
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.
Upvotes: 1