Last active
February 8, 2021 15:29
-
-
Save nakov/9799f266bb29d61d35a0c1c406445050 to your computer and use it in GitHub Desktop.
Run Selenium tests in two Web browsers in parallel with NUnit
This file contains 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
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example will run two Web browsers in parallel:
The tests inside the browsers will run sequentially, one after another.
This is due to the scope we use:
It says that text fixtures will run in paralle, but th etests in each text fixture will remain in sequential execution.