Java – if the running mode is parameter = “methods”, how to force TestNG to create a new test class instance for each method

If the running mode is parameter = "methods", how to force TestNG to create a new test class instance for each method?

JUnit executes automatically, but TestNG reuses the same instance between methods

Are there any options to change this behavior?

I'm running the selenium test and creating a webdriver in the @ beforemethod method method and storing it in the class variable so that I can use it in the test method and use closures on @ aftermethod

And I want to be able to run the methods of a test class in parallel without sharing webdriver

Solution

There is no way to force TestNG to do so One solution is to set the webdriver instance to a ThreadLocal variable This helps to do this. It creates a webdriver object for each thread if you get it on a variable Will only give you thread objects

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>