Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine browser type (IE, FF, Chrome, etc.)

I'm in the process of switching my Watir / FireWatir scripts over to use watir-webdriver and need a means in watir-webdriver to determine which type of browser the test is currently being executed against, (IE, FF, Chrome).

With Watir / FireWatir looking at the class of the browser would return either "Watir::IE" or "FireWatir:Firefox". Using that the code could be branched to execute browser specific code.

In watir-webdriver, the class of the browser is always "Watir::Browser", it doesn't vary when running IE, Firefox, or Chrome.

Does anyone know of a way in Ruby with watir-web-driver to identify the browser's type (i.e. IE, Firefox, Chrome)?

For example: With Watir / Firewatir define methods:

def is_ie?()

return self.class.to_s == "Watir::IE"
end
def is_firefox?()
return self.class.to_s == "FireWatir::Firefox"
end

Then invoke them like this...

if(browser.is_ie?)

# run the IE specific code
end
if(browser.is_firefox?)
# run the firefox specific code
end



Thanks in advance,
Joe

like image 376
Joe Avatar asked Aug 20 '11 20:08

Joe


1 Answers

Try

browser.driver.browser #=> :firefox

like image 131
jarib Avatar answered Nov 03 '22 00:11

jarib