问题
I have a page that sometimes loads in over a minute. Assume this is the expected behavior and wont change. In these cases, I get Net::ReadTimeout
.
Note that this is after navigating to a page by clicking a button on the previous page, not an ajax request. Therefore Capybara.using_wait_time
doesn't help.
I have tried a number of radical things (some of which I knew wouldn't work) like:
- Setting
page.driver.browser.manage.timeouts
'simplicit_wait
,script_timeout
andpage_load
. - Looping through the entire object space and setting all
Selenium::WebDriver::Remote::Http::Default
'stimeout
value. - Looping through the entire object space and setting all
Net::HTTP
'sread_timeout
. page.driver.browser.send(:bridge).http.instance_variable_get(:@http).read_timeout=
None seem to work. This should be very trivial, still I couldn't find a way to do it.
If you know of a webdriver agnostic solution that would be great. If not - I am using selenium.
回答1:
Selenium has a lot of different timeout settings, some of which can be changed at runtime, others which have to be set when the driver is initialized. You are most likely running into the Http::Default timeout which defaults to 60 seconds. You can override this by passing your own instance into the Selenium driver as http_client
Capybara.register_driver :slow_selenium do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120
Capybara::Selenium::Driver.new(app, http_client: client)
end
and then use the :slow_selenium driver for tests which will take over a minute to load the page
来源:https://stackoverflow.com/questions/31383385/capybara-increase-max-allowed-page-load-time