Forum: Ruby How can I catch browser error in watir-webdriver?

Posted by Prog Rammer (proggrammer)
on 2012-10-03 09:30
Like I want to catch two errors saparately:
1. when somebody closes the browser intentionally. Or it is closed by
some error, I mean any browser related error.
Posted by Prog Rammer (proggrammer)
on 2012-10-05 10:14
ajay paswan wrote in post #1078471:
> Like I want to catch two errors saparately:
> 1. when somebody closes the browser intentionally. Or it is closed by
> some error, I mean any browser related error.

Please help me somebody. I am stuck here.
Posted by Jam Bees (Guest)
on 2012-10-05 15:18
(Received via mailing list)
On 5 Oct 2012, at 02:15, ajay paswan <lists@ruby-forum.com> wrote:

> ajay paswan wrote in post #1078471:
>> Like I want to catch two errors saparately:
>> 1. when somebody closes the browser intentionally. Or it is closed by
>> some error, I mean any browser related error.
>
> Please help me somebody. I am stuck here.
>

What have you tried so far?
Posted by Joel Pearson (virtuoso)
on 2012-10-05 21:30
Use something along these lines to record the types of error and 
simulate them. Once you have the exact error reported, like "end of file 
reached", you can rescue that error by using rescue like a case 
statement: http://rubylearning.com/satishtalim/ruby_exceptions.html

______________________________________
require 'watir-webdriver'

begin

  b = Watir::Browser.new
  10.times {
    b.goto "www.google.com"
    sleep 5
    #Close or disconnect the browser here
    #and see what error message you get
    b.goto "about:blank"
  }

rescue
  puts "Your error message was: #{$!}"
  exit
ensure
  b.close rescue nil
end
______________________________________
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.