Skip to content

Instantly share code, notes, and snippets.

@nakov
Last active February 8, 2021 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakov/9799f266bb29d61d35a0c1c406445050 to your computer and use it in GitHub Desktop.
Save nakov/9799f266bb29d61d35a0c1c406445050 to your computer and use it in GitHub Desktop.
Run Selenium tests in two Web browsers in parallel with NUnit
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using System;
namespace Selenium_Examples
{
[TestFixture(typeof(FirefoxOptions))]
[TestFixture(typeof(ChromeOptions))]
[Parallelizable(ParallelScope.Self)]
public class MultiTest<TOptions> where TOptions : DriverOptions, new()
{
private IWebDriver driver;
[OneTimeSetUp]
public void Setup()
{
var options = new TOptions();
driver = new RemoteWebDriver(
new Uri("http://localhost:4444/wd/hub"), options);
}
[Test]
public void Test_NakovCom_Title()
{
driver.Navigate().GoToUrl("https://nakov.com");
Assert.That(driver.Title.Contains("Svetlin Nakov"));
}
[Test]
public void Test_Wikipedia_Title()
{
driver.Navigate().GoToUrl("https://wikipedia.org");
Assert.That(driver.Title.Contains("Wikipedia"));
}
[Test]
public void Test_Google_Title()
{
driver.Navigate().GoToUrl("https://google.com");
Assert.That(driver.Title.Contains("Google"));
}
[OneTimeTearDown]
public void Shutdown()
{
driver.Quit();
}
}
}
@nakov
Copy link
Author

nakov commented Feb 8, 2021

This example will run two Web browsers in parallel:

  • Chrome
  • Firefox
    The tests inside the browsers will run sequentially, one after another.

This is due to the scope we use:

[Parallelizable(ParallelScope.Self)]

It says that text fixtures will run in paralle, but th etests in each text fixture will remain in sequential execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment