简体   繁体   中英

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

Is there any way to make NUnit run tests within same class using same browser window and parallel to tests in other classes?

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
  ...
 }

}

You could create a class variable of IWebDriver and initialize it in a default constructor. Then just use that instance of the driver for all of your tests in that particular class. In order to quit the diver after the last test has run you can keep some sort of counter or indicator as a class variable as well then in the TearDown method check that variable and if it matches the value for the last test call driver.Dispose()

Edit If you prefer to initialize IWebDriver in a Setup method, still use a field to hold your instance of IWebDriver and in the Setup method check if the IWebDriver variable (field) is null or not. If it's not null then just don't do anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM