Last active
February 8, 2021 15:29
-
-
Save nakov/4db8afa21894fe8dd9e73944c66e7bcc to your computer and use it in GitHub Desktop.
Run Selenium tests in parallel with NUnit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestFixture(typeof(FirefoxOptions))] | |
[TestFixture(typeof(ChromeOptions))] | |
[Parallelizable(ParallelScope.All)] | |
public class MultiSeleniumTest<TOptions> where TOptions : DriverOptions, new() | |
{ | |
[ThreadStatic] | |
private static IWebDriver driver; | |
[SetUp] | |
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")); | |
} | |
[TearDown] | |
public void Shutdown() | |
{ | |
driver.Quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example will run 6 Web browsers in parallel to execute 6 tests concurrently:
Create a separate
IWebDriver
instance before each test in[SetUp]
and release it in[TearDown]
.Define the driver as
[ThreadStatic]
+static
to get a separate instance for each test execution.