Last active
March 30, 2016 12:02
-
-
Save stenver/87f56519ae495a6b7d47bd08816c129d to your computer and use it in GitHub Desktop.
Selenium chrome timeout workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def connect(retry_count = 0) | |
# Selenium sometimes loses commands. This can cause a situation when browser is ready and waiting | |
# while at the same time test is waiting for response from the browser. Eventually the test times out | |
# This issue is confirmed on Chrome | |
Timeout::timeout(5) do | |
# Start the browser on a safe page. | |
visit_blank_page | |
@session_start_time ||= Time.now | |
end | |
rescue Timeout::Error | |
if retry_count == 5 | |
raise FailedToConnectWithBrowser.new("Driver #{@driver_name} with metadata #{fetch_driver_metadata} failed to start") | |
else | |
connect(retry_count + 1) | |
end | |
end | |
def visit_blank_page | |
session.driver.browser.navigate.to("https://#{@host}/blank") | |
end | |
def fetch_driver_metadata | |
if config[:grid_url] | |
grid_url = config[:grid_url].gsub("/wd/hub", "") | |
uri = URI("#{grid_url}/grid/api/testsession?session=#{session.driver.browser.session_id}") | |
response = Net::HTTP.get(uri) | |
return JSON.parse(response) | |
end | |
{} | |
rescue Exception | |
{} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment