In the latest installment of our Cucumber Automation Framework series, learn how to run WebDriver with multiple browsers.
Blog nine of a series.
So far in our WebDriver lessons, we have been using a single browser: Firefox. This is due to the fact that Selenium natively uses the Firefox browser.
The PageObjects gem is built on the WATiR-WebDriver gem, which is built on the Selenium-webdriver gem. So if you are going to use WATiR or PageObjects, keep in mind that you will, by default, be able to use Firefox with no additional configuration needed.
Unfortunately, to run your framework with any other browser takes a little bit more work.
To refresh your memory, refer to my blog titled Driving a Browser using WATiR-WebDriver. In this lesson, you learned about the Before and After hooks in the the hooks.rb file.
Running WebDriver with Chrome
During that lesson we opened the default Firefox browser. Now we are going to run it with the Chrome browser. To do this is (almost) really simple: change :firefox to :chrome
Go ahead and run the framework. Did you get an all pass? If yes, then you are cheating and skipping ahead.
The rest of you are seeing a “Selenium::WebDriver::Error::WebDriverError: Unable to find the chromedriver executable.
Please download the server from this link and place it somewhere on your PATH” error message:
The wonderful thing about Cucumber error messages is they often give you the solution. Here, we need to go to this link and download the ChromeDriver server. Go ahead and do that and place it in your C:Rubyxxxbin directory.
Now run your script. Here is how it might look:
Running WebDriver with IEExplorer
Now that we have figured out Chrome, getting IE running is easy. First, change :chrome to :ie
Running this will once again lead you to a message that reads: a “Selenium::WebDriver::Error::WebDriverError: Unable to find standalone executable.
Please download the IEDriverServer from this link and place the executable on your PATH.” error message:
Similar to the Chrome error, Cucumber tells us what we need to do: go to this link and download IEDriverServer.exe. Place it in the same C:Rubyxxxbin directory and re-run your framework.
You should see an all pass.
Wasn’t that simple? Lots of thanks to the creators of the Cucumber automation framework for making WATiR-WebDriver using Firefox, Chrome and IE so simple to do.
With the drivers in place, you can now easily test with all three of the major browsers. You can also get creative with your rake tasks and control which browser you run tests with. But that is another lesson.