Capybara increase max allowed page load time

半城伤御伤魂 提交于 2019-12-23 09:32:08

问题


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's implicit_wait, script_timeout and page_load.
  • Looping through the entire object space and setting all Selenium::WebDriver::Remote::Http::Default's timeout value.
  • Looping through the entire object space and setting all Net::HTTP's read_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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!