Watir Tutorials: Quick trick to identify IE browser version
Sometimes your testcases are browser version dependent and you need to perform tasks depending on the IE browser version. E.g. handling file chooser dialog boxes in IE7 and IE8. I'll discuss this IE7 and IE8 file chooser dialog box compatibility issue in my next blog.
In this kind of situation, the correct approach would be - itentify the version of the browser at runtime and excute the testcase for that browser. So you do not end up with three versions of same testcase, ecah for IE6, IE7 and IE8. It is easy to identify the version of the IE browser at runtime.
Following few lines of code will accomplish that:
$browser = Watir::IE.new()
full_ver = $browser.document.invoke('parentWindow').navigator.appVersion
tmp_str =/MSIE\s(.*?);/.match(full_ver)
$ie_ver = tmp_str[1]
puts "IE VERSION = #{$ie_ver}"
Once you know the browser version then you can use any control structure of your choice to exceute browser specific test cases.