[英]TestNG classes run in parallel, but methods don't. How do I configure my testng.xml file and test classes so methods will also run in parrallel?
I have a suite of Selenium WebDriver tests that I'm running with Grid. 我有一套与Grid一起运行的Selenium WebDriver测试。 When I run this testng.xml file:
当我运行此testng.xml文件时:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="classes" thread-count="20">
<test name="Test">
<classes>
<class name="testcases.test1"/>
<class name="testcases.test2"/>
<class name="testcases.test3"/>
<class name="testcases.test4"/>
<class name="testcases.test5"/>
<class name="testcases.test6"/>
<class name="testcases.test7"/>
<class name="testcases.test8"/>
<class name="testcases.test9"/>
<class name="testcases.test10"/>
<class name="testcases.test11"/>
<class name="testcases.test12"/>
<class name="testcases.test13"/>
<class name="testcases.test14"/>
<class name="testcases.test15"/>
<class name="testcases.test16"/>
<class name="testcases.test17"/>
<class name="testcases.test18"/>
<class name="testcases.test19"/>
<class name="testcases.test20"/>
<class name="testcases.test21"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Multiple browsers open, each running the @BeforeClass method and the first @Test method. 打开多个浏览器,每个浏览器都运行@BeforeClass方法和第一个@Test方法。 However, after each browser finishes that first @Test method, it will wait for all the other browsers to finish their respective first @Test method.
但是,每个浏览器完成第一个@Test方法后,它将等待所有其他浏览器完成各自的第一个@Test方法。
The tests are structured like this: 测试的结构如下:
public class sampleTestClass {
@BeforeClass
public void setup(){
//setup Remote WebDriver
}
@Test
public void method1(){
//do things
}
@Test(dependsOnMethods = "method1")
public void method2(){
//do things
}
@Test(dependsOnMethods = "method2")
public void method3(){
//do things
}
@AfterClass
public void teardown(){
//call teardown
}
}
with multiple @Test methods in each class. 每个类中有多个@Test方法。 I will add that everything runs the way I prefer when I use this .xml file:
我将补充一点,当我使用此.xml文件时,所有内容都按照我喜欢的方式运行:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="MySuite" parallel="tests" thread-count="20">
<test name="First Test">
<classes>
<class name="testcases.test1"/>
</classes>
</test>
<test name="Second Test">
<classes>
<class name="testcases.test2"/>
</classes>
</test>
<test name="Third Test">
<classes>
<class name="testcases.test3"/>
</classes>
</test>
<test name="Fourth Test">
<classes>
<class name="testcases.test4"/>
</classes>
</test>
<!--<test name="Fifth Test">
<classes>
<class name="testcases.test5"/>
</classes>
</test>-->
<test name="Sixth Test">
<classes>
<class name="testcases.test6"/>
</classes>
</test>
<test name="Seventh Test">
<classes>
<class name="testcases.test7"/>
</classes>
</test>
</suite>
The reason I'm not okay with this configuration is that one, I don't think it preserves the semantic meaning of the tags at all, and two (and most importantly) I'd like to be able to run the automatically generated suite of failures in parallel, but the configuration of that .xml file is the same as the top one that I'm having trouble with. 我对此配置感到不满意的原因是,一个,我认为它根本没有保留标签的语义,而两个(最重要的是)我希望能够运行自动生成的套件并行失败,但该.xml文件的配置与我遇到问题的前一个相同。
It seems to me that specifying parallel="classes" in the suite tag is consistent with the TestNG documentation, but doesn't achieve asynchronous execution of the @Test methods in the separate classes. 在我看来,在套件标签中指定parallel =“ classes”与TestNG文档一致,但是在单独的类中无法实现@Test方法的异步执行。
Why doesn't this configuration of the .xml file work? 为什么.xml文件的此配置不起作用? What do I need to do differently to make it work?
要使其正常工作,我需要做些什么?
In the context of a webdriver test class having multiple methods, given that there is one instance of a webdriver in that class, i dont see how it would be possible to share one webdriver instance simultanously between methods. 在具有多个方法的webdriver测试类的上下文中,假定该类中有一个webdriver实例,我看不到如何在方法之间同时共享一个webdriver实例。 I seems it would HAVE TO call methods one at a time so that each method had its turn with the webdriver instance.
我似乎必须一次调用一个方法,以便每个方法都可以通过webdriver实例轮流使用。 Otherwise it seems you would get some sort of concurrent exception.
否则,您似乎会得到某种并发异常。
I've tried many times to get parallel methods working with TestNG but never succeeded. 我已经尝试过很多次,以获得与TestNG一起使用的并行方法,但从未成功。 There is an example in the source code though that might be a clue;
源代码中有一个示例,但这可能是一个线索。 just look at the testng.xml in the same folder.
只需查看同一文件夹中的testng.xml。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.