Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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