2017-10-12 153 views
0

需要一点帮助,以获得正确的方法来并行运行testng测试用例。使用testng |并行运行硒测试用例maven

当前设置。 在本地机器上使用单个驱动程序实例运行所有测试用例。 Selenium WebDriver TestNg Maven

必需。 想要在本地运行具有多个驱动程序实例的测试用例。

<build> 
    <sourceDirectory>src</sourceDirectory> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

的testng.xml

<suite name="testSuite" verbose="10" preserve-order="true" configfailurepolicy="continue"> 

<test name="SanityTest" parallel="none"> 
    <classes> 
     <class name="test.java.HeaderTests"/> 
    </classes> 
</test> 
</suite> 

驱动

driver = new InternetExplorerDriver(capabilities); 
driver.manage().window().maximize(); 
driver.get(url); 
+0

嗯..你在找什么,准确的?您是否尝试过使用TestNG parallel [属性](http://testng.org/doc/documentation-main.html#parallel-running)设置并运行测试? – user2611581

+0

感谢您的回复。我正在研究如何设置驱动程序并行运行测试用例。我需要为不同的线程创建多个实例吗?或者我可以只使用单个驱动程序实例吗? – iamvroon

回答

0

您必须修改的testng.xml文件,并告诉它在

并行运行: 类平行:方法

,请访问:https://howtodoinjava.com/testng/testng-executing-parallel-tests/

+1

这似乎没有足够好的格式,无论如何,我不清楚你的解决方案是什么。并且:与外部的链接通常不是一个好主意,例如因为网站可能会消失,然后我们就会迷失在这里。 – dr0i

0

看来,在你的testng.xml您的并行值设置为“无”。为了并行运行,您必须将它设置为 “class”:它将并行运行类或“方法”:它将运行方法,而不管类或包是否并行运行。

不过只是一个说明,它很难说出你是如何处理你的驱动程序,但你需要使它具体线程,否则你的命令可能会被发送到错误的驱动程序。

希望这会有所帮助。

+0

感谢您的回复。我正在研究如何设置驱动程序并行运行测试用例。我需要为不同的线程创建多个实例吗?或者我可以只使用单个驱动程序实例吗? – iamvroon

0

根据您的问题和澄清,似乎您正在寻找并行运行测试。对于例如 - 并行运行多个测试类,以便缩短测试执行时间。在这种情况下,建立测试运行器的多个线程(比如TestNG)并且不要设置多个线程/ webdriver实例更为明智。类似这样的:

<suite name="Parallel test runs" parallel="tests" thread-count="2"> 
     <test name="test1"> 
      <classes> 
       <class name="com.company.test1" ></class> 
      </classes> 
     </test> 

     <test name="test2"> 
      <classes> 
       <class name="com.company.test2" ></class> 
      </classes> 
     </test> 
    </suite> 

这将并行运行test1和test2。使用TestNG,您可以并行运行方法,类或组。为WebDriver设置多个线程的一种可能的用例是在测试运行时,您想要继续检查是否存在警报。 (我个人不赞成这种风格,但我曾看到球队正在这样做)。 对于这样的工作方法,测试类不应该是相互依赖的。此外,每个测试都应该设置(开始时)并拆除(在测试结束时)Webdriver的一个实例。