For want of a nail, the shoe was lost; for want of a shoe, the horse was lost;
For want of a horse, the rider was lost; for want of a rider, the message was lost;
For want of a message the battle was lost; for want of a battle, the kingdom was lost . .
Thursday, February 13, 2014
Distributing Coded UI Scripts (with Selenium add-in) for Cross Browser Automation using Visual Studio Lab Management & Environment variables
Author: Ranjit Gupta and Raj Kamal
If you are not already aware, Coded UI now supports cross
browser testing using Selenium components. The Visual Studio add-in can be
that works if you are running VS 2012 Update 2 or above. There is also an
that talk topic in detail, if you are interested.
A large utility
service company in United Stated has retained us to implement its internet
facing web presence - USD 7
Million engagement. The website will provide timely, business driven
information along with functionality to its customers to do their regular
interactions, such as paying bills, checking historical usage data, turning
on/off services, and others mentioned in the business requirements section. As
it’s an external facing site, it needs to be supported on Firefox, Chrome as
well as IE 8 & IE 9. With the size and the criticality of the application
to customer’s core business, selective manual testing on non-IE browsers
is not an acceptable approach.
The power of Coded UI
+ Selenium & Visual Studio Lab Management
We wrote Coded UI Tests used this Selenium add-in along with
Visual Studio Lab feature to distribute our automated tests on multiple browsers.
Our goal was to dedicate each OS + Browser combination a dedicated agent
machine, so all our tests run in parallel on different browsers on pre-defined
One challenge was that, there is no way in Visual Studio Lab
settings to specify that a particular agent machine should be used for a
specific browser e.g. Chrome, Firefox, IE 8, IE 9 etc. We didn’t want to create multiple copies of
coded UI test methods and hardcode them to run against specific configurations.
We were looking for a solution that didn’t require us to write custom logic to
solve this very problem and fortunately we could achieve this without any
additional coding using the below proposed solution.
Solution – Simple yet
To get past this issue, we made use of environment variables.
The steps are explained below.
1.Create environment variable on each agent
machine and set its value as the desired browser name (IE8/IE9/Chrome/Firefox) against
which you want to run your automated tests.
2.Create a Test Initialize method and read the
value of the environment variable before test starts on each agent machine.
This will return the name of the browser that needs to be used for playing back