如果运行模式为parallel =" methods"如何强制TestNG为每个方法创建测试类的新实例 [英] How to force TestNG create new instance of test class for each method if run mode is parallel="methods"
问题描述
如果运行模式为 parallel =methods
?如何强制TestNG为每个方法创建测试类的新实例?
How to force TestNG create new instance of test class for each method if run mode is parallel="methods"
?
JUnit会自动执行,但TestNG会在方法之间重复使用相同的实例。
JUnit does it automatically but TestNG reuses same instance between methods.
有没有更改此行为的选项?
Is there any option to change this behavior?
我正在运行selenium测试并在 @BeforeMethod
方法中创建webdriver并将其存储到类变量中以在测试方法中使用它并在<$ c $中使用clos c> @AfterMethod 。
I'm running selenium tests and create webdriver in @BeforeMethod
method and store it to class variable to use it in test methods and clos on @AfterMethod
.
我希望能够并行运行一个测试类的方法,而无需共享webdriver。
And I want to have ability to run methods of one test class in parallel without sharing webdriver.
推荐答案
没有办法强迫testng这样做。解决方案是将webdriver实例设置为threadlocal变量。这将有助于做到这一点,它将为每个线程创建一个webdriver对象,如果你对变量进行获取,它。只给你那个线程的对象。
There is no way to force testng to do that. A solution is to set webdriver instance to a threadlocal variable. What this would help doing is, it would create one webdriver object per thread, if u do a get on the variable, it. Would give u that thread's object only.
这篇关于如果运行模式为parallel =" methods"如何强制TestNG为每个方法创建测试类的新实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!