Skip to content

Cross browser parallel test execution with SeleniumGrid or testing Cloud Providers

Jakub Raczek edited this page Nov 20, 2018 · 7 revisions

Running test in parallel on different browsers at the same time is possible with Selenium Grid, TestingBot, SauceLabs or e.g BrowserStack

Sample test case:

namespace Objectivity.Test.Automation.Tests.NUnit.Tests
{
    using System.Collections.Generic;
    using Automation.Tests.PageObjects.PageObjects.TheInternet;
    using Common;
    using global::NUnit.Framework;

    [TestFixture("Chrome")]
    [TestFixture("Firefox")]
    [TestFixture("Safari")]
    [TestFixture("Edge")]
    [TestFixture("IE")]
    [Parallelizable(ParallelScope.Fixtures)]
    public class HerokuappTestsNUnit : ProjectTestBase
    {
        public HerokuappTestsNUnit(string environment)
            : base(environment)
        {
        }

        [Test]
        public void ContextMenuTest()
        {
            const string H3Value = "Context Menu";
            var browser = BaseConfiguration.TestBrowser;
            if (browser.Equals(BrowserType.Firefox))
            {
                var contextMenuPage = new InternetPage(this.DriverContext)
                    .OpenHomePage()
                    .GoToContextMenuPage()
                    .SelectTheInternetOptionFromContextMenu();

                Assert.AreEqual("You selected a context menu", contextMenuPage.JavaScriptText);
                Assert.True(contextMenuPage.ConfirmJavaScript().IsH3ElementEqualsToExpected(H3Value), "h3 element is not equal to expected {0}", H3Value);
            }
        }

        [Test]
        public void SlowResourcesTest()
        {
            int timeout = 35;
            new InternetPage(this.DriverContext)
                .OpenHomePage()
                .GoToSlowResources()
                .WaitForIt(timeout);
        }
    }
}

Add section group "environments" in App.config. Set "browser" value to "RemoteWebDriver" and "DriverCapabilities" value to "CloudProvider". Set "RemoteWebDriverHub" value to "http://localhost:4444/wd/hub" to use your own Selenium Grid server instead of BrowserStack:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
...
    <sectionGroup name="environments">
      <section name="Chrome" type="System.Configuration.NameValueSectionHandler" />
      <section name="Firefox" type="System.Configuration.NameValueSectionHandler" />
      <section name="Safari" type="System.Configuration.NameValueSectionHandler" />
      <section name="Edge" type="System.Configuration.NameValueSectionHandler" />
      <section name="IE" type="System.Configuration.NameValueSectionHandler" />
    </sectionGroup>
 <appSettings>
...
    <add key="browser" value="RemoteWebDriver"/>
    <add key="RemoteWebDriverHub" value="http://hub-cloud.browserstack.com/wd/hub"/>
    <add key="DriverCapabilities" value="CloudProvider"/>
  </appSettings>
...
  <DriverCapabilities>
    <add key="browserstack.user" value=""/>
    <add key="browserstack.key" value=""/>
    <add key="project" value="Test.Automation"/>
    <add key="browserstack.debug" value="true" />
    <add key="build" value="Objectivity.Test.Automation.Tests.BrowserStackCrossBrowser" />
    <!--<add key="RemoteWebDriverHub" value="http://ondemand.saucelabs.com:80/wd/hub"/>-->
    <!--<add key="RemoteWebDriverHub" value="https://hub.testingbot.com/wd/hub/"/>-->
  <DriverCapabilities>
    <add key="browserstack.user" value=""/>
    <add key="browserstack.key" value=""/>
    <add key="project" value="Test.Automation"/>
    <add key="browserstack.debug" value="true" />
    <add key="build" value="Objectivity.Test.Automation.Tests.CloudProviderCrossBrowser" />
    <add key="browserstack.networkLogs" value="true" />
    <!-->testingbot Settings/-->
    <add key="key" value=""/>
    <add key="secret" value=""/>
    <!-->saucelabs Settings/-->
    <add key="username" value=""/>
    <add key="accessKey" value=""/>
    <add key="extendedDebugging" value="true"/>
  </DriverCapabilities>
  <environments>
    <Chrome>
      <add key="browser" value="chrome" />
      <add key="os" value="Windows"/>
      <add key="os_version" value="10"/>
      <add key="name" value="parallel_test" />
    </Chrome>
    <Firefox>
      <add key="browser" value="firefox" />
      <add key="os" value="Windows"/>
      <add key="os_version" value="10"/>
      <add key="name" value="parallel_test" />
    </Firefox>
    <Safari>
      <add key="browser" value="safari" />
      <add key="os" value="OS X"/>
      <add key="os_version" value="High Sierra"/>
      <add key="name" value="parallel_test" />
      <!-->testingbot Settings/-->
      <add key="platform" value="HIGH-SIERRA" />
      <add key="version" value="11" />
    </Safari>
    <Edge>
    <add key="browser" value="edge" />
      <add key="os" value="Windows"/>
      <add key="os_version" value="10"/>
      <add key="name" value="parallel_test" />
    </Edge>
    <IE>
      <add key="browser" value="IE" />
      <add key="os" value="Windows"/>
      <add key="os_version" value="10"/>
      <add key="name" value="parallel_test" />
    </IE>
  </environments>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

You can also execute tests in parallel on one browser and repeat it for different browsers. Here you can found Update App.config instruction how App.config file can be modified by powershell script.

Clone this wiki locally