My Innovative Solution to Test Automation: Run the same test against a different browser at a click of a button
Simple and Efficient.
This is included in the “My Innovative Solution to Test Automation and Continuous Testing” series.
A decade ago, cross-browser testing was a hot topic. Why? There was no absolute dominated browser then (now, there is, Chrome). A serious web app needs to be verified on at least three major browsers: Internet Explorer, Chrome, and Firefox. SauceLabs and BrowserStack are two companies that grew rapidly because of the need for cross-browser testing. Compared to the above, I had a much simpler and cheaper way to conduct cross-browser testing, using the BuildWise CT server. But it was the perspective of test suite execution. How to effectively perform cross-browser testing at the individual test level, i.e, at developing/debugging time?
Seeing this need, I worked out an easy solution with TestWise IDE: run the same test against a different browser with a click of a button.
Table of Contents:
· Selenium Tests that support multi-browsers
· Run the same test against different browsers with a click of a button
∘ From Command Line
∘ In TestWise tool
Selenium Tests that support multi-browsers
Selenium WebDriver provides the best multi-browser support as it is the only automation framework that is supported by all major browser vendors. To run one test with a specific browser is simple.
driver = Selenium::WebDriver.for(:chrome)
To change from Chrome to Firefox,
driver = Selenium::WebDriver.for(:firefox)
To make the switch easy for all test scripts, I introduce a helper method browser_type
.
@driver = Selenium::WebDriver.for(browser_type)
In the test helper (shared by all test scripts, see Maintainable Automated Test Design):
def browser_type
:chrome # or :firefox, :ie
end
Most automated testers can reach this stage.
Run the same test against different browsers at a click of a button
On one project, I needed (as a Java developer) to verify web pages frequently on IE and Chrome. I found switching between:chrome
and :ie
in the test helper file was not efficient. Therefore, I decided to explore a better way, with two goals:
In Testing Tool and from the command line.
Quick and simple
I worked out the solution that same day and have been using it ever since (over 15 years).
From Command Line
I started with the command line option (100% tool independent). A common convention is to pass the environment variable over, such as BROWSER
.
def browser_type
if ENV["BROWSER"]
ENV["BROWSER"].downcase.to_sym # => :chrome, :firefox, or :ie
else
:chrome
end
end
The benefit: no need to change of test script. This is important in the context of CI/CD. A single change of code/test script marks a new build.
From a command line (or terminal on macOS/Linux):
# on Linux or macOS
$ export BROWSER=chrome
$ rspec spec/login_spec.rb
On Windows:
> set BROWSER=chrome
> rspec spec\login_spec.rb
In TestWise tool
On that project, all team members (yes, including manual testers, business analysts, programmers and the architect) used my TestWise tool to run automated tests. As it was not realistic to ask non-programmers to run tests from the command line (as shown above), I had to implement this in TestWise.
To make the method as simple as possible for everyone to use, my solution was to show three browser options as toggle buttons on the toolbar. To change the target browser, just click the chosen browser button and then run your selected test case or test script. Below are two screenshots showing running the same test against two browsers: one FAILED, and one PASS.
How was it implemented? Very simple. Before TestWise started executing a test, it would pass chosen browser as the environment variable BROWSER
to the execution process. By the way, the default browser can be set.
A final note, this feature was well received by TestWise users, for its simplicity.
Related reading: