简体   繁体   English

在不同的测试中并行运行testng方法

[英]Run testng methods across different tests in parallel

I have more than one test tags in my testng.xml file that I am running using maven. 我正在使用maven运行的testng.xml文件中有多个测试标签。 I have set the parallel attribute at the suite level to methods and the thread-count as 5. The problem I am facing is that the tests are executed sequentially and only the methods inside the test cases are executed in parallel. 我在套件级别将parallel属性设置为方法,并将线程数设置为5。我面临的问题是测试是按顺序执行的,并且仅测试用例内部的方法是并行执行的。 To be more clear, though there are unused threads(Selenium nodes in the grid in my case) available the subsequent tests waits till all the methods in the previous test are executed. 更清楚地说,尽管有未使用的线程(在我的情况下为网格中的硒节点)可用,但随后的测试会一直等到之前测试中的所有方法都执行完为止。

Here is the testng.xml that i have used, 这是我使用过的testng.xml,

<suite name="Suite1" verbose="1" parallel="methods" thread-count="5" preserve-order="false">
  <test name="Login" >
    <classes>
       <class name="testSuite.TestSet1" />
    </classes>
  </test>

  <test name="Product Search">
    <classes>
      <class name="testSuite.TestSet2"/>
    </classes>
  </test>
</suite>

As I have more than 10 nodes available in my selenium grid, this behavior increases the execution time considerably and defeats the purpose of having a grid architecture. 由于我的硒网格中有10个以上的可用节点,因此,这种行为会大大增加执行时间,并且无法达到拥有网格体系结构的目的。 Please let me know if there's a way using which I can execute the test methods across the suite in parallel. 请让我知道是否有一种方法可以并行执行整个套件中的测试方法。 I am sure that I am missing something silly, but could you please help me point that? 我敢肯定我很想念一些东西,但是您能帮我指出吗?

在您的TestNG xml文件中输入parallel =“ tests”

Parallel=methods would do exactly that - "methods inside the test cases are executed in parallel". Parallel = method完全可以做到这一点-“测试用例中的方法是并行执行的”。

If you want your test tags to be executed parallely use parallel=tests. 如果要并行执行测试标签,请使用parallel = tests。
This would run all your test tags in parallel. 这将并行运行所有测试标签。

But you state you have 10 nodes available. 但是您声明有10个可用节点。 If above is the only xml you have then only two nodes would be used up at a time since you have just two test tags. 如果上面是您仅有的xml,则一次只有两个节点,因为您只有两个测试标签。

<suite name="Suite1" verbose="1" parallel="tests" thread-count="2" preserve-order="false">   
  <test name="Login" parallel="methods" thread-count="5">
    <classes>
       <class name="testSuite.TestSet1" />
    </classes>   
  </test>
  <test name="Product Search" parallel="methods" thread-count="5">
    <classes>
      <class name="testSuite.TestSet2"/>
    </classes>   
  </test> 

First allow your Suite to run "tests" in parallel with the number of test suites to run at a time (example 2). 首先,让您的套件与一次要运行的测试套件数量并行运行“测试”(示例2)。

Second allow your test to run "methods" parallel with the number of methods each can run (example 5 in each). 其次,允许您的测试与每种方法可以运行的方法数量并行运行“方法”(每种示例5)。

If you are bumping against the your thread limit be careful when adjusting these numbers. 如果您碰到螺纹极限,则在调整这些数字时要小心。 For example if you add another test group with thread-count of 5 and change your suite thread-count to 3. You'll now be at 15 threads. 例如,如果您添加另一个线程数为5的测试组,并将您的套件线程数更改为3,您现在将拥有15个线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM