-
Notifications
You must be signed in to change notification settings - Fork 131
Cross browser parallel test execution with SeleniumGrid or testing Cloud Providers
Jakub Raczek edited this page Apr 30, 2019
·
7 revisions
Running test in parallel on different browsers at the same time is possible with Selenium Grid, BrowserStack, TestingBot or e.g SauceLabs
Sample test case:
namespace Ocaramba.Tests.NUnit.Tests
{
using System.Collections.Generic;
using Automation.Tests.PageObjects.PageObjects.TheInternet;
using Common;
using global::NUnit.Framework;
[TestFixture("ChromeWindows")]
[TestFixture("Android")]
[TestFixture("Iphone")]
[TestFixture("FirefoxWindows")]
[TestFixture("SafariMac")]
[TestFixture("EdgeWindows")]
[TestFixture("IEWindows")]
[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="ChromeWindows" type="System.Configuration.NameValueSectionHandler" />
<section name="FirefoxWindows" type="System.Configuration.NameValueSectionHandler" />
<section name="SafariMac" type="System.Configuration.NameValueSectionHandler" />
<section name="EdgeWindows" type="System.Configuration.NameValueSectionHandler" />
<section name="IEWindows" type="System.Configuration.NameValueSectionHandler" />
<section name="Android" type="System.Configuration.NameValueSectionHandler" />
<section name="Iphone" type="System.Configuration.NameValueSectionHandler" />
</sectionGroup>
<appSettings>
...
<add key="RemoteWebDriverHub" value="http://localhost:4444/wd/hub"/>
<!--<add key="RemoteWebDriverHub" value="http://user:[email protected]/wd/hub"/>-->
<!--<add key="RemoteWebDriverHub" value="http://user:[email protected]:80/wd/hub"/>-->
<!--<add key="RemoteWebDriverHub" value="https://user:[email protected]/wd/hub/"/>-->
<add key="DriverCapabilities" value="CloudProvider"/>
</appSettings>
...
<DriverCapabilities>
<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" />
<add key="browserstack.local" value="false" />
<!-->saucelabs Settings/-->
<add key="extendedDebugging" value="true"/>
</DriverCapabilities>
<environments>
<ChromeWindows>
<add key="browser" value="chrome" />
<add key="os" value="Windows"/>
<add key="os_version" value="10"/>
<add key="name" value="parallel_test" />
</ChromeWindows>
<FirefoxWindows>
<add key="browser" value="firefox" />
<add key="os" value="Windows"/>
<add key="os_version" value="10"/>
<add key="name" value="parallel_test" />
</FirefoxWindows>
<SafariMac>
<add key="browser" value="safari" />
<add key="os" value="OS X"/>
<add key="os_version" value="Mojave"/>
<add key="name" value="parallel_test" />
<!-->saucelabs Settings/-->
<add key="platform" value="macOS 10.14" />
<add key="version" value="12.0" />
</SafariMac>
<EdgeWindows>
<add key="browser" value="edge" />
<add key="os" value="Windows"/>
<add key="os_version" value="10"/>
<add key="name" value="parallel_test" />
</EdgeWindows>
<IEWindows>
<add key="browser" value="IE" />
<add key="os" value="Windows"/>
<add key="os_version" value="10"/>
<add key="name" value="parallel_test" />
</IEWindows>
<Android>
<add key="device" value="Samsung Galaxy S8"/>
<add key="realMobile" value="true"/>
<add key="name" value="parallel_test" />
</Android>
<Iphone>
<add key="device" value="iPhone 7"/>
<add key="realMobile" value="true"/>
<add key="name" value="parallel_test" />
</Iphone>
</environments>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
Add this constructor to ProjectTestBase class.
namespace Ocaramba.Tests.NUnit.Tests
{
public class ProjectTestBase : TestBase
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly DriverContext
driverContext = new DriverContext();
public ProjectTestBase(string environment)
{
Logger.Info(CultureInfo.CurrentCulture, "environment {0}", environment);
this.DriverContext.CrossBrowserEnvironment = environment;
}
}
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.
- Home
- Getting started
- Parallel tests execution
- MsTest DataDriven tests from Xml and CSV files
- NUnit DataDriven tests from Xml, CSV and Excel files
- Comparing files by NUnit DataDriven tests
- Visual Testing
- Screen shots: full desktop, selenium. PageSource saving
- Verify-asserts without stop tests
- Downloading files
- Helpers
- Override browser profile preferences, install browser extensions, Headless mode
- Debugging Test.Automation framework
- Logging
- Performance measures
- Webdriver Extends
- More common locators
- Selenium-Grid-support
- Advanced Browser Capabilities and Options
- AngularJS synchronization
- Update App.config or appsettings.json
- Cross browser parallel test execution with testing-Cloud-Providers\SeleniumGrid
- Verifying Javascript Errors from browser
- Enabling Performance Log for Chrome
- Azure DevOps Support
- Edge browser Support
- Downloading and running Selenium Grid with Powershell
- Run Ocaramba tests with Docker container
- HTTP auth in Internet explorer
- ExtentReports Support