![](/img/trans.png)
[英]How to force TestNG to run all methods in class without switching to another thread in parallel mode
[英]How to force TestNG create new instance of test class for each method if run mode is parallel=“methods”
如果运行模式是parallel="methods"
如何强制 TestNG 为每个方法创建测试类的新实例?
JUnit 会自动执行此操作,但 TestNG 在方法之间重用相同的实例。
有没有办法改变这种行为?
我正在运行 selenium 测试并在@BeforeMethod
方法中创建 webdriver 并将其存储到类变量中以在测试方法中使用它并在@AfterMethod
上@AfterMethod
。
而且我希望能够在不共享 webdriver 的情况下并行运行一个测试类的方法。
没有办法强制 testng 这样做。 一种解决方案是将 webdriver 实例设置为 threadlocal 变量。 这将有助于做的是,它会为每个线程创建一个 webdriver 对象,如果你对变量进行了获取,它。 只会给你那个线程的对象。
我已经使用 TestNG 并行运行多个 selenium webdriver 测试。 要为每个方法设置新的 WebDriver,请使用 @DataProvider注释及其在 @Test 注释中的关联属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.