Tuesday, April 4, 2017

Parallel testing on Selenium Grid C# MStest

This is to explain how to use parallel test execution on Selenium grid using MStest.

As on the previous Post you have to create some remote web browsers  
So i have 5 free FireFox, 5 Chrome and a 1 IE  instances available on a server.

192.168.134.67 is my remote server.
5557 is the connection port to the Selenium Grid Host server.

So my 1st test method will looks like this.
I have used one and only IE instance which was available on my selenium grid.
I dont have any asserts ,Only navigating to Yahoo.


[TestMethod]
        public void SeleniumGridYahoo()
        {
            Uri hub = new Uri("http://192.168.134.67:5557/wd/hub");
            DesiredCapabilities capabilities = DesiredCapabilities.InternetExplorer();
            Environment.SetEnvironmentVariable("webdriver.IE.driver", @"C:\Documents\SeleniumGrid\IEDriverServer.exe");

            RemoteWebDriver driver3 = new RemoteWebDriver(hub, capabilities);
            driver3.Navigate().GoToUrl("http://www.yahoo.com");
        }

And then going to utilizing one of my FireFox instance this time,

[TestMethod]
        public void SeleniumGridFacebook()
        {
            Uri hub = new Uri("http://192.168.134.67:5557/wd/hub");
            DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
          Environment.SetEnvironmentVariable("webdriver.geko.driver", @"C:\Users\ugljenkins\Documents\SeleniumGrid\geckodriver.exe");
            RemoteWebDriver driver3 = new RemoteWebDriver(hub, capabilities);
            driver3.Navigate().GoToUrl("http://www.facebook.com");

        }

So now i have two test cases.

If i run these test cases individually by the test explorer it will open a IE or FireFox browser at the  192.168.134.67 server and execute the test.

If i run these test cases as a group by the test explorer it will open a IE and FireFox browser one after another at the  192.168.134.67 server and execute the test.






But if i do the Test execution in a Parallel way ,
Both browsers will open same time at the server and start navigating the relevant web URL.

So it will cut down the half of my execution time.


  1. Simply add a new XML file to the project.
  2. Add parallelTestCount attribute to the excel file.
  3. Set it as 2 (two means you can run up to two test cases parallelly)
  4. Save and rename it to testsettings.



Sample XML file.


<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="953cfca7-2c66-4909-bc08-b8ce43651474" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
  <Description>These are default test settings for a local test run.</Description>
  <Deployment enabled="false" />
  <Execution parallelTestCount="2">
    <TestTypeSpecific />
    <AgentRule name="Execution Agents">
    </AgentRule>
  </Execution>

</TestSettings>

DONE.

No comments:

Post a Comment