Wednesday, July 15, 2015

Run your Coded UI tests against different browsers using the Selenium components


Run your coded ui tests against the different browsers using the
selenium components.

If we have a dedicated agent machines with browser to run the 
coded ui test with out modifying the code.

For this i am using the system variables. In each machine i will 
create a system variable name:browser and value is like "IE" 
or "Chrome" or "Firefox" ect 

Ex: Agent-1 should run with IE browser and Agent-2 should run
 with Chrome browser...

Download the Selenium components from below link

After installing the cross-browser testing installer, verify that
Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowserProxy.dll
 is found in the following location:

"%ProgramFiles%\Common Files\microsoft shared\VSTT\Cross 
Browser Selenium Components" (for 32 bit machines)

"%ProgramFiles(x86)%\Common Files\microsoft shared\VSTT\Cross
 Browser Selenium Components" (for 64 bit machines)

Download chrome driver from below link

Download selenium dot net bindings from:

Right click on the downloaded zip files.

Select "properties".

Under "General" tab, click on the "Unblock" button.

Now unzip both the files and copy the contents to the following path
(for the selenium-dotnet 2.43.1 binaries, copy the contents of net40                  folder):

"%ProgramFiles%\Common Files\microsoft shared\VSTT\Cross 
Browser Selenium Components" (for 32 bit machines)

"%ProgramFiles(x86)%\Common Files\microsoft shared\VSTT\Cross             Browser Selenium Components" (for 64 bit machines)

Supported versions
This installer works with VS 2012 Update 4, VS 2013 VS 2013 update 3
 and VS 2013 Update 4.

Supported Browser versions
The following versions of browsers have been verified and are 
supported: Firefox 33.
Latest version of Chrome (version 38.0.2125.111 m as of 11/14/2014)

Setting Environment Variables for Coded UI
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.
1.Go to “My Computer” Right click and select “Properties


2.Click on “Advance System Settings


3.Go to “Advance Tab” and the click on “Environment Variables” 


4.Under “system variables” section click on “New


5.Give the “Variable Name” and “Variable Value


6.Click on “ok” and again click on “ok” and again click on “ok”.

7.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 automation.

String browser;
        [TestInitialize]
        public void Init()
        {
            browser                            = Environment.GetEnvironmentVariable("LaunchBrowser");
        }

8.Inside your test method, set “BrowserWindow.CurrentBrowser
   value as “browser” which holds the browser name stored in 
   environment variable

Sample code…
[TestMethod]
public void CodedUITestMethod1()
{
    BrowserWindow.CurrentBrowser = browser;
    this.UIMap.RecordedMethod1();
    this.UIMap.AssertMethod1();
}

Depending on the value stored in the environment variable, Coded UI launches the browser and runs the test against launched browser.


7 comments:

  1. Hi Anvesh,

    A great article! I might use it soon when setting up the virtual environment for running coded ui test in Firefox.

    Have you btw have any troubles with starting Firefox browser from coded ui? I can run tests in IE and GC, but so far the Firefox process does not start at all. I guess it has something to do with the browser startup settings (profiles, start screen etc). Did you have any similar to this problem?

    Thanks, Olena

    ReplyDelete
  2. Hi Olena,

    coded ui cross browsing will work for a specific firefox browser version for 33 or 32..

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Tagged "Titan's Red" - titanium white dominus
    Tagged "Titan's Red". This product has been mens titanium wedding rings tested titanium necklace mens and is titanium for sale a fully working product. The "Titan's Red" logo is ford fusion hybrid titanium still in titanium oxide formula the plastic case.

    ReplyDelete