(NUnit) 运行 使用相同浏览器 window 测试(在相同 class 内)

(NUnit) Run tests (within same class) using same browser window

是否有任何方法可以在相同的 class 中使用相同的浏览器 window 进行 NUnit 运行 测试并与其他 class 中的测试并行?

Login.cs

class Login {
 [SetUp]
 public void login() {
  //Must Login-in once before the "Test Suite" on CustomerCRUD class  
  ...
 }
}

CustomerCRUD.cs

[Parallelizable]
class CustomersCrud: Login {

 [WebTest]
 public void Test1() {
  //Test something and when done, even if failed must go to test2 using the same browser window
  ...
 }

 [WebTest]
 public void Test2() {
  //Test something and when done, even if failed, must tear down
  ...
 }

}

您可以创建 IWebDriver 的 class 变量并在默认构造函数中对其进行初始化。然后只需将该驱动程序实例用于该特定 class 中的所有测试。为了在最后一次测试有 运行 后退出潜水员,您可以将某种计数器或指示器也保留为 class 变量,然后在 TearDown 方法中检查该变量,如果它与最后一次测试调用 driver.Dispose()

编辑 如果您更喜欢在 Setup 方法中初始化 IWebDriver,仍然使用一个字段来保存您的 IWebDriver 实例,并在 Setup 方法中检查 IWebDriver 变量(字段)是否为空。如果它不为空,则什么都不做。