Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase WebDriver network timeout for a single test

There is a some heavy page, that after visiting it Selenium doesn't respond to Capybara for a minute, so whatever do I call, throws Net::ReadTimeout.
I could edit it globally somehow like:

http_client = Selenium::WebDriver::Remote::Http::Default.new
http_client.timeout = 120
Capybara::Selenium::Driver.new(app,
  http_client: http_client,

But in the case of some repetitive timeouts my tests would last for too long, so I do not want to increase timeout globally.
I want to increase it for a single test somehow like:

before do
  @timeout = page.driver.bridge.http.timeout
  page.driver.bridge.http.timeout = 120
end
after do
  page.driver.bridge.http.timeout = @timeout
end

But in /lib/selenium/webdriver/common/driver.rb the bridge method is private, while only browser and capabilities are exposed to public.

So what is the correct way to edit this timeout attribute globally?

UPD: Even if I find how to set this attribute, seems like the before/after approach doesn't work, because @http ||= ( saves the default timeout value in the first before in the chain of setUps, that precede mine.

like image 544
Nakilon Avatar asked May 15 '26 06:05

Nakilon


1 Answers

Capybara has a default_wait_time that can be changed in the middle of tests:

using_wait_time 120 do
  foo(bar)
end
like image 117
Phil Avatar answered May 16 '26 22:05

Phil