TextFixture and Test
public class TestFixture : IDisposable
{
public TestFixture()
{
var options = new ChromeOptions();
options.AddExcludedArgument("enable-automation");
options.AddAdditionalCapability("useAutomationExtension", true);
WebDriver.Init("https://localhost:44335/", Browser.Chrome, options);
WebDriver.GetDriver.Manage().Window.Maximize();
}
public void Dispose()
{
WebDriver.Close();
}
}
public abstract class Test : IClassFixture<TestFixture>
{
}
AuthTest
public abstract class AuthTest : Test
{
[Fact, Priority(-1)]
public void LoginTest()
{
var home = GetPage<HomePage>();
home.LoginModal.Open();
home.LoginModal.EnterLoginText(new Login("user", "pw"));
home.LoginModal.Login();
GetPage<DashboardPage>().IsAt();
}
}
HomeTest
[TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
public sealed class HomeTest : AuthTest
{
}
ProfileTest
[TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
public sealed class ProfileTest : AuthTest
{
[Fact, Priority(0)]
public void OpenProfilePageTest()
{
var profile = GetPage<ProfilePage>();
profile.GoTo();
profile.IsAt();
}
[Fact, Priority(1)]
public void LogoutTest() => GetPage<DashboardPage>().Logout();
}
A few days ago I wrote this code and it used to create 1 browser instance. I started the project today again and now suddenly the fixture gets executed twice and it opens two seperate browsers (which causes my tests to fail). I thought the IClassFixture
was supposed to only execute once like [OneTimeSetUp]
attribute in NUnit. Why is my fixture executing twice?
This happens when I run all tests (all tests runsProfileTest
and HomeTest
). If I run for example one of the two tests individually, then just 1 browser instance opens and the test passes.
I'm using XUnit 2.4.0.
- EDIT -
When I use:
VS 2019 (run all tests): It opens 2 browsers at same time and fails.
VS 2019 (debug all tests): It opens 2 browsers at same time and fails.
Jetbrain's Rider IDE (run all tests): It opens 2 browsers at same time and fails.
Jetbrain's Rider IDE (debug all tests): It opens 1 browser till HomeTest
finishes and then another browser for ProfileTest
, and both tests pass (including LoginTest
).
This last is how it is supposed to work and it used to be like this when I used NUnit before.