我正在尝试使用Webdriver Hub和TestNG并行机制设置Webdriver并行执行。我正面临线程问题使用Selenium Grid for Webdriver + TestNG并行执行问题
我有这个类扩展了TestBaseSetUp,它有一个BeforeMethod和AfterMethod并设置为始终运行。对于webdriver并行执行,我想使用ThreadLocal,但@Test和@ Before/@ After方法在不同的线程中。因此,如果我在我的TestBaseSetUp中将webdriver设置为ThreadLocal,并尝试使用我的测试方法,它将返回null。
public class TestCheck extends TestBaseSetUp {
@Test
public void test(){
System.out.println("Thread in test " + Thread.currentThread().getId());
}}
我们有没有办法让@Test也是相同的线程中@前/ @方法
感谢您的回复。我将检查链接,但我想知道在这种情况下我将如何使用BeforeMethod和AfterMethod等。除了Test注释之外,我将不得不离开testNG的所有这些优秀功能,因为它们与Test不在同一个线程中。对这些的任何建议。 –
如果我的建议适合你,请帮忙接受答案。 要回答你的问题,我不认为BeforeMethod,Test,AfterMethod运行在不同的线程上。我在testng google论坛上回答了您的问题,并附上了一个示例。 https://groups.google.com/d/msg/testng-users/8XYt-El2_JU/o5Mm6gklAQAJ –