How to configure read_timeout and open_timeout for Selenium in Ruby? - ruby

I'm getting this exception when calling goto() via Watir:
Net::ReadTimeout with #<TCPSocket:(closed)>
/usr/lib/ruby/2.6.0/net/protocol.rb:217:in `rbuf_fill'
/usr/lib/ruby/2.6.0/net/protocol.rb:191:in `readuntil'
/usr/lib/ruby/2.6.0/net/protocol.rb:201:in `readline'
/usr/lib/ruby/2.6.0/net/http/response.rb:40:in `read_status_line'
/usr/lib/ruby/2.6.0/net/http/response.rb:29:in `read_new'
/usr/lib/ruby/2.6.0/net/http.rb:1509:in `block in transport_request'
/usr/lib/ruby/2.6.0/net/http.rb:1506:in `catch'
/usr/lib/ruby/2.6.0/net/http.rb:1506:in `transport_request'
/usr/lib/ruby/2.6.0/net/http.rb:1479:in `request'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:129:in `response_for'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:82:in `request'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/common.rb:64:in `call'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/bridge.rb:167:in `execute'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:567:in `execute'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:59:in `get'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/navigation.rb:32:in `to'
/var/lib/gems/2.6.0/gems/watir-6.16.5/lib/watir/navigation.rb:16:in `goto'
It seems that I can modify the timeouts, but I don't understand how.
They are used here, but how do I configure them?

You can refer to Documentation Ruby-Bindings : Internal timeouts
From Documentation : Internal timeouts Internally, WebDriver uses
HTTP to communicate with a lot of the drivers (the JsonWireProtocol).
By default, Net::HTTP from Ruby's standard library is used, which has
a default timeout of 60 seconds. If you call e.g. Driver#get,
Driver#click on a page that takes more than 60 seconds to load, you'll
see a Timeout::Error raised from Net::HTTP. You can configure this
timeout (before launching a browser) by doing:
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 120 # seconds
driver = Selenium::WebDriver.for :remote, http_client: client
In Watir it may be something like
caps = Selenium::WebDriver::Remote::Capabilities.chrome
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 600
client.open_timeout = 600
driver = Watir::Browser.new :chrome, :desired_capabilities => caps,
:http_client => client

Related

undefined method `query_options' for nil:NilClass, resque, unicorn, Rails 4, mysql

I get this error when i try to send an update mail.
undefined method `query_options' for nil:NilClass
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:218:in `execute'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:300:in `execute_and_free'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:461:in `columns'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:114:in `block in prepare_default_proc'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `yield'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `default'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:208:in `columns'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:217:in `columns_hash'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `block in valid?'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `each'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `all?'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `valid?'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:18:in `method_missing'
/home/user_name/work/app_name/app/mailers/user_mailer.rb:12:in `update_message'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionpack-4.0.0/lib/abstract_controller/base.rb:189:in `process_action'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionpack-4.0.0/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:373:in `_run__1485230712795781007__process_action__callbacks'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionpack-4.0.0/lib/abstract_controller/callbacks.rb:17:in `process_action'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionpack-4.0.0/lib/abstract_controller/base.rb:136:in `process'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionpack-4.0.0/lib/abstract_controller/rendering.rb:44:in `process'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:503:in `process'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:497:in `initialize'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:48:in `new'
/home/user_name/.rvm/gems/ruby-1.9.3-p551#app_name/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:48:in `perform'
We are using Rails 4, unicorn 4.7 and resque 1.25.
For sending emails on the application we use different mailer.
The recovery email that uses the object to send the emails, works fine, but the email that sends the profile update, which queries the user by id, does not work and throws the above error.
This is the unicorn config:
worker_processes 1
working_directory "correct/path" # available in 0.94.0+
listen "correct/path", :backlog => 64
timeout 30
pid "correct/path"
stderr_path "correct/path"
stdout_path "correct/path"
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if old_pid != server.pid
begin
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
I have tried various answer from stack overflow, or Github issues with no result.
I finally fixed the problem, I had to restart the worker(s) after removing the octopus gem.
That error message is because octopus does not work very well out of the box with unicorn so I did configured it, but I forgot to close the worker, and it kept the octopus setting thus throwing this error.
Unfortunately I could not find a good way to use octopus with our applications because we got this error, that as far as I could see is related to Resque, more precisely when any of the workers forks a process, it fails to connect to an outside database, ex: x model connecting to y database., which works well for the application using octopus_connect, but not for the workers.
Our solution was to use instead taskrabbit/makara as the connection proxy.

Preventing timeout when connecting to a URL

I want to see the time taken to access a url using Benchmark in the code below. I also tried to do the same thing without benchmark. That is, get time at start of test and end of test, subtract the two to get the time. Both methods end in the same timeout error.
require 'open-uri'
require 'benchmark'
response = nil
puts "opening website with benchmark..."
puts Benchmark.measure{
response = open('http://mywebsite.com')
}
puts "Done !"
status = response.status
puts status
Error:
opening website with benchmark...
C:/ruby/lib/ruby/1.8/timeout.rb:64:in `rbuf_fill': execution expired (Timeout::Error)
from C:/ruby/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
from C:/ruby/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
from C:/ruby/lib/ruby/1.8/net/protocol.rb:126:in `readline'
from C:/ruby/lib/ruby/1.8/net/http.rb:2028:in `read_status_line'
from C:/ruby/lib/ruby/1.8/net/http.rb:2017:in `read_new'
from C:/ruby/lib/ruby/1.8/net/http.rb:1051:in `request'
from C:/ruby/lib/ruby/1.8/open-uri.rb:248:in `open_http'
from C:/ruby/lib/ruby/1.8/net/http.rb:543:in `start'
from C:/ruby/lib/ruby/1.8/open-uri.rb:242:in `open_http'
from C:/ruby/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'
from C:/ruby/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
from C:/ruby/lib/ruby/1.8/open-uri.rb:162:in `catch'
from C:/ruby/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
from C:/ruby/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
from C:/ruby/lib/ruby/1.8/open-uri.rb:518:in `open'
from C:/ruby/lib/ruby/1.8/open-uri.rb:30:in `open'
from C:/code/test.rb:7
from C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
from C:/code/test.rb:6
When I try to connect to this URL in my browser, it takes about 2-3 minutes to access, all the time.
I searched google, but found no useful answers to my problem. I know that I have to
change the timeout setting for something, but not able to figure out which one. Can someone please help ?
Use the :read_timeout option, specified in seconds, e.g.,
open('foo.com', :read_timeout => 10)
http://ruby-doc.org/stdlib-1.8.7/libdoc/open-uri/rdoc/OpenURI/OpenRead.html
The BufferedIO class that Net::HTTP uses for the connection that open-uri then uses for the request has a read_timeout attribute set to 60 seconds.
The Net::HTTP class provides a setter read_timeout for that.
Unfortunately, the way open-uri sets up that request doesn't provide you with a way to get at that setting before the request or the easily override the default of 60.
You will probably need to use Net::HTTP yourself.
link = URI.parse(url)
request = Net::HTTP::Get.new(link.path)
response = Net::HTTP.start(link.host, link.port) {|http|
http.read_timeout = 100 #Default is 60 seconds
http.request(request)
}
Code stolen from this answer
edit: or upgrade to 1.9 which supports the :read_timeout = x option Dave Newton noted.

100% unending CPU usage fetching SSL page without cert

Using Mechanize 2.6.0 on Ruby 1.9.3 I'm trying to fetch a web page over HTTPS from Windows 7x64. When I attempt to get() the URL the CPU usage goes to 100% and the method never returns:
require 'mechanize'
uri = "https://my.com/wiki/api.php?action=query&titles=US4&prop=info&format=xml"
agent = Mechanize.new
u,p = %w[myusername mypassword]
agent.add_auth( uri, u, p )
agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
info = agent.get( uri )
When I interrupt it, I get these stack traces (three different runs):
>> info = agent.get( page_api )
IRB::Abort: abort then interrupt!
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/www_authenticate_parser.rb:27:in `call'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/www_authenticate_parser.rb:27:in `parse'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/agent.rb:716:in `response_authenticate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/agent.rb:306:in `fetch'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize.rb:431:in `get'
from (irb):10
from C:/Ruby193/bin/irb:12:in `<main>'
>> info = agent.get( page_api )
IRB::Abort: abort then interrupt!
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/www_authenticate_parser.rb:29:in `call'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/www_authenticate_parser.rb:29:in `new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/www_authenticate_parser.rb:29:in `parse'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/agent.rb:716:in `response_authenticate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/agent.rb:306:in `fetch'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize.rb:431:in `get'
from (irb):11
from C:/Ruby193/bin/irb:12:in `<main>'
>> info = agent.get( page_api )
IRB::Abort: abort then interrupt!
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/www_authenticate_parser.rb:114:in `call'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/www_authenticate_parser.rb:114:in `token'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/www_authenticate_parser.rb:31:in `parse'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/agent.rb:716:in `response_authenticate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize/http/agent.rb:306:in `fetch'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.6.0/lib/mechanize.rb:431:in `get'
from (irb):12
from C:/Ruby193/bin/irb:12:in `<main>'
How can I work around this problem and properly fetch an HTTPS URL via Ruby on Windows? (If there's a better solution than Mechanize for this—since I only need the source of the page to feed to Nokogiri anyhow—I'm open to not using Mechanize at all.)
Another datapoint: trying the same code on OS X produces the same result.
Here's the actual content of the page, using the alternative fetching method described in my workaround answer below:
p fetch_https_without_ssl_verification(uri, u, p)
#=> "\t\t <?xml version=\"1.0\"?><api><query><normalized><n from=\"Devtools/UI_Composer/DesignSpec/US7294\" to=\"Devtools/UI Composer/DesignSpec/US7294\" /></normalized><pages><page ns=\"0\" title=\"Devtools/UI Composer/DesignSpec/US7294\" missing=\"\" /></pages></query></api>"
If you simply need the contents of the URL (as I do) then using curl instead of Mechanize is far easier, and it works:
def fetch_https_without_ssl_verification( uri, user=nil, pass=nil )
`curl -s -k #{%Q{-u "#{user}#{":"<<pass if pass}"} if user} "#{uri}"`
end

Skipping slow websites when looping through an array of URLs using watir-webdriver

I'm trying to loop through an array of websites in Chrome using watir-webdriver, but I always encounter an error on certain websites. Recently, I have had this problem with http://adage.com. The loop will execute perfectly until it reaches http://adage.com and then it will hang until the following error is displayed:
/Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error)
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:2551:in `read_new'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:1316:in `catch'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:1293:in `request'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:1286:in `block in request'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:745:in `start'
from /Users/default/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:1284:in `request'
from /Users/default/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:82:in `response_for'
from /Users/default/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:38:in `request'
from /Users/default/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from /Users/default/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:598:in `raw_execute'
from /Users/default/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:576:in `execute'
from /Users/default/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:536:in `getActiveElement'
from /Users/default/.rvm/gems/ruby-1.9.3-p125/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/common/target_locator.rb:60:in `active_element'
from /Users/default/.rvm/gems/ruby-1.9.3-p125/gems/watir-webdriver-0.6.1/lib/watir-webdriver/browser.rb:136:in `send_keys'
from /Users/default/Dropbox/beta_scripts/loop_test.rb:16:in `rescue in <main>'
from /Users/default/Dropbox/beta_scripts/loop_test.rb:11:in `<main>'
I have no idea how to avoid this. I have tried setting timeouts and even sending the ESC key during rescue to stop Chrome from loading the page, but have not had any success. Ultimately, I want to be able to reliably load an array of 500+ websites in succession, but this seems impossible given the likelihood that one of the websites will hang. Is there any way to stop a slow page from loading and move on to the next element in the array?
Below is a shortened version of my code that isolates the problem:
#!/usr/bin/env ruby
require 'watir-webdriver'
b = Watir::Browser.new :chrome
sites = ["twitter.com", "cars.com", "autotrader.com", "rolex.com", "newyorker.com", "adage.com", "theatlantic.com", "pcmag.com"]
sites.each do |uri|
begin
Timeout::timeout(10) do
b.goto uri
end
rescue Timeout::Error => e_time
sleep 5
b.send_keys :escape
p "#{uri} is taking forever to load (#{e_time})"
rescue Exception => e_exception
p e_exception
end
end
b.close
Well I can understand your frustration mate because I have encountered the same when dealing with selenium webdriver. Here it is what you need to do to be 100% sure that your script will run flawless and robust till the end for your 500+ websites.
sites.each do |uri|
!30.times { if ((b.goto uri)rescue false)then break else sleep 1; end }
end
The code above will try to access each website for a maximum of 30sec and then move to the next website.

How do I catch this exception in Ruby?

I'm a ruby beginner so bear with me.
I am using the selenium-webdriver and rb-appscript gems to do some webscraping. The navigation to websites seems to be driven by the Net::Http object, which has a rbuf_fill method.
Running the following code:
sites = File.open("sites.txt", "r") if File::exists?( "sites.txt" )
if sites != nil
while (line = sites.gets)
driver.switch_to.default_content
begin
driver.navigate.to line
rescue Exception
line = line.split.join("\n")
puts line + " caused a timeout."
end
end
...
Produces this error:
/opt/local/lib/ruby1.9/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error)
from /opt/local/lib/ruby1.9/1.9.1/net/protocol.rb:134:in `rbuf_fill'
from /opt/local/lib/ruby1.9/1.9.1/net/protocol.rb:116:in `readuntil'
from /opt/local/lib/ruby1.9/1.9.1/net/protocol.rb:126:in `readline'
from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:2219:in `read_status_line'
from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:2208:in `read_new'
from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:1191:in `transport_request'
from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:1177:in `request'
from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:1170:in `block in request'
from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:627:in `start'
from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:1168:in `request'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/selenium-webdriver-2.2.0/lib/selenium/webdriver/remote/http/default.rb:73:in `response_for'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/selenium-webdriver-2.2.0/lib/selenium/webdriver/remote/http/default.rb:41:in `request'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/selenium-webdriver-2.2.0/lib/selenium/webdriver/remote/http/common.rb:34:in `call'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/selenium-webdriver-2.2.0/lib/selenium/webdriver/remote/bridge.rb:406:in `raw_execute'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/selenium-webdriver-2.2.0/lib/selenium/webdriver/remote/bridge.rb:384:in `execute'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/selenium-webdriver-2.2.0/lib/selenium/webdriver/remote/bridge.rb:171:in `switchToDefaultContent'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/selenium-webdriver-2.2.0/lib/selenium/webdriver/common/target_locator.rb:68:in `default_content'
from auto.rb:25:in `<main>'
I have no idea why I can't catch this exception. Using rescue Exception should catch everything, but as you can see my script still crashes.
I have also found sources that say you must catch the timeout explicitly so I also tried:
rescue Timeout::Error
without any luck.
Any help is greatly appreciated on this one.
Ruby version: ruby 1.9.2p290 (2011-07-09 revision 32553)
OS: MacOS Snow Leopard 10.6.8 64-bit
Selenium Webdriver version: 2.2.0
The file 'timeout.rb' in Ruby's standard library defines:
module Timeout
# Raised by Timeout#timeout when the block times out.
class Error < RuntimeError
So what you need to rescue is not Timeout::Exception but rather Timeout::Error or more generically RuntimeError. Then it should work.

Resources