Thursday, January 14, 2010

Watir Tutorial: Quick trick to identify IE browser version

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.

3 comments:

  1. Great site. Plenty of useful info here. I'm sending it to a few buddies ans additionally sharing in delicious. And of course, thank you in your sweat!
    My web-site - weight loss

    ReplyDelete
  2. Very good article. I certainly love this site.

    Continue the good work!

    my website: acheter Vue Youtube

    ReplyDelete
  3. Usually I don't read post on blogs, however I wish to say that this write-up very compelled me to take a look at and do so! Your writing taste has been amazed me. Thanks, very great article.

    My website: silk scarf

    ReplyDelete