Skip to content
Merged
Show file tree
Hide file tree
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
Expand Down
11 changes: 9 additions & 2 deletions spec/support/wait_for_websocket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

module WaitForWebsocket
def wait_for_websocket
Timeout.timeout(Capybara.default_max_wait_time) do
loop until websocket_finished?
start_time = Time.current
timeout = Capybara.default_max_wait_time

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

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

def websocket_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('CodeOceanEditorWebsocket?.websocket?.getReadyState() === WebSocket.CLOSED').present?
end
end
Expand Down