Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium: Refactor WaitFor* scripts to prevent crashes #1718

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions spec/support/wait_for_ajax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

module WaitForAjax
def wait_for_ajax
Timeout.timeout(Capybara.default_max_wait_time) do
loop until ajax_requests_finished?
start_time = Time.current
timeout = Capybara.default_max_wait_time

loop do
break if ajax_requests_finished? || (Time.current - start_time) > timeout

sleep 0.1 # Short sleep time to prevent busy waiting
end
end

def ajax_requests_finished?
# This method MUST NOT be interrupted. Hence, Timeout.timeout is not used here.
# Otherwise, Selenium and the browser driver might crash, preventing further tests from running.
page.evaluate_script('jQuery.active').zero?
end
end
Loading