The Issue 

A basic but fundamental Watir Webdriver command is setting your browser type. Websites/Applications may react differently to different browsers, and testing across different browser types/versions can be essential. Lets take a look at the Watir Webdriver command to open a browser, and how to set it to our desired browser.

The Answer

You can set your different browser types within the Watir Webdriver command. Once you have set it, you can change the browser type within the command; alternatively, you can create three separate steps for each major browser (Chrome, Firefox, and IE in this case).

The Code

We’ll be opening the Watir Webdriver demo page using the Chrome browser.

The Result

We can save the file (NewBrowser.rb) and run it from the command line, with the following result:

  • Our defined browser opens
  • Browser navigates to the Watir Webdriver demo page

The Takeaway

This basic Watir Webdriver command to set your browser will provide you a foundation to begin your testing. Additionally, the command works multiple functions into one; you are opening the browser and defining browser as a variable for your Watir scripts.