Reputation: 11
I have the question about the NUnit test setup (.NET Core 3.1 and NUnit 3) for Selenium tests in Visual Studio 2019.
In AssemblyInfo.cs, I add 2 lines.
[assembly: Parallelizable(ParallelScope.Children)]
[assembly: LevelOfParallelism(4)]
The Code is easy. Initialize the driver in the SetUp(). However, when using the test explorer to run 2 tests, 2 chrome windows are open. But they are not running in parallel ( Still not working using Setup, OneTimeSetup attributes)
If I initialize the driver in the TestMethod directly, it is fine , but it is the dupe code.
Does it mean NUnit Selenium Tests inside the same TestFixture cannot be running in parallel?
Thanks, Ray
[TestFixture]
public class Account : BaseTest
{
[SetUp]
public void Setup()
{
_driver = new ChromeDriver();
_driver.Manage().Window.Maximize();
}
[Test]
[Category("UAT")]
[Order(1)]
public void Test1()
{
_driver.Navigate().GoToUrl("https://www.msn.com");
Assert.AreEqual("https://www.msn.com/", _driver.Url);
}
[Test]
[Category("UAT")]
[Order(0)]
public void Test2()
{
_driver.Navigate().GoToUrl("https://www.google.com");
Assert.AreEqual("https://www.google.com/", _driver.Url);
}
Upvotes: 0
Views: 407
Reputation: 51
I had the same question, but I've managed to put together an example where VS2019 + Selenium + Parallelism does work, though I believe there is a limitation that seems likely to be what you are encountering (I'll speak to it at the end) based upon your example.
To make it work, I added an AssemblyInfo.cs file with the two attributes you noted:
[assembly: Parallelizable(ParallelScope.Children)]
[assembly: LevelOfParallelism(6)]
I tested having with the "Parallelizable" attributed to the class or in the AssemblyInfo.cs file and both worked. Including the "LevelOfParallelism" was required -- but in my tests, it was not required for parallel execution of non-Selenium unit tests.
My model involves executing my tests against multiple WebDrivers, which I am currently doing by passing an IEnumerable collection to each test using the [TestCaseSource] or [ValueSource] attributes. This allows me to reuse a WebDriver instance with each test to reduce the overall execution time (it is so expensive to spin up/down instances) and ensure correct clean-up, but I observed that although the tests are run in parallel, each WebDriver instance can only execute one test at a time. If you were using a different WebDriver instance with the second test, they would be executed in parallel.
Upvotes: 0