【发布时间】:2019-10-22 13:45:06
【问题描述】:
TextFixture 和测试
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();
}
}
家庭测试
[TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
public sealed class HomeTest : AuthTest
{
}
个人资料测试
[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();
}
几天前我写了这段代码,它用来创建 1 个浏览器实例。我今天又开始了这个项目,现在突然夹具被执行了两次,它打开了两个单独的浏览器(这导致我的测试失败)。我认为IClassFixture 应该只执行一次,就像 NUnit 中的[OneTimeSetUp] 属性一样。为什么我的夹具执行了两次?
当我运行所有测试(所有测试都运行ProfileTest 和HomeTest)时会发生这种情况。例如,如果我单独运行两个测试之一,那么只会打开 1 个浏览器实例并且测试通过。
我正在使用 XUnit 2.4.0。
- 编辑-
当我使用时:
VS 2019(运行所有测试):它同时打开 2 个浏览器并失败。
VS 2019(调试所有测试):它同时打开 2 个浏览器并失败。
Jetbrain 的 Rider IDE(运行所有测试):它同时打开 2 个浏览器并失败。
Jetbrain 的 Rider IDE(调试所有测试):它打开 1 个浏览器直到 HomeTest 完成,然后打开另一个浏览器 ProfileTest,两个测试都通过(包括 LoginTest)。
最后一个是它应该如何工作的,当我以前使用 NUnit 时它曾经是这样的。
【问题讨论】:
-
我不认为是因为 xUnit,而是硒的问题。
-
但是如果我更改代码以使用 NUnit
[OneTimeSetUp]而不是 XUnit,它会做我想要的。 -
仔细观察后,我认为您的
TestFixture方法也被识别为测试。用Fact[(skip="some reason")]属性装饰它。 -
Rider 测试执行器会在附加调试器的情况下一一运行测试,其他情况下默认并行执行不同的类测试
标签: c# selenium-webdriver xunit xunit.net xunit2