-
-
Save bartolsthoorn/4713871 to your computer and use it in GitHub Desktop.
Chrome Webdriver, lose connection => lose RAM!
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
require 'selenium-webdriver' | |
client = Selenium::WebDriver::Remote::Http::Default.new | |
client.timeout = 1 # seconds | |
driver = Selenium::WebDriver.for( | |
:chrome, | |
:http_client => client, | |
:switches => %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate] | |
) | |
# The driver only has 1 second, and likely times out | |
driver.navigate.to 'http://maps.google.com' | |
# Now for some reason it's impossible to quit the driver | |
# net/protocol.rb:146:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error) | |
driver.quit |
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
# I let the browser go to a htaccess protected page, to simulate a long loading page, and let it time out. | |
# The timing out works great! The only thing is that after it times out, I can no longer close the browser to clean it up.. | |
[45] pry(main)> http_client = Selenium::WebDriver::Remote::Http::Default.new | |
=> #<Selenium::WebDriver::Remote::Http::Default:0x007ff646b1c698 @timeout=nil> | |
[46] pry(main)> http_client.timeout = 10 | |
=> 10 | |
[47] pry(main)> driver = Selenium::WebDriver.for(:chrome, :http_client => http_client) | |
driver.=> #<Selenium::WebDriver::Driver:0x..fa262b71adb240f5e browser=:chrome> | |
[53] pry(main)> driver.navigate.to "http://sproffer.nl/admin" | |
Timeout::Error: Timeout::Error | |
from /Users/bartolsthoorn/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill' | |
[54] pry(main)> driver.close | |
Timeout::Error: Timeout::Error | |
from /Users/bartolsthoorn/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill' | |
# Example that it doesn't always fail | |
[56] pry(main)> driver = Selenium::WebDriver.for(:chrome, :http_client => http_client) | |
=> #<Selenium::WebDriver::Driver:0x5acad44a1ab63f76 browser=:chrome> | |
[57] pry(main)> driver.navigate.to "http://google.nl" | |
=> {} | |
[58] pry(main)> driver.close | |
=> {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment