2013-02-21 29 views
0

要使用testng和selenium网格运行并行测试,我的确按照步骤操作。使用webdriver在网格中打开多个chrome实例

1)注册毂和网格: -

java -jar selenium-server-standalone-2.26.0.jar -role hub 
java -jar selenium-server-standalone-2.26.0.jar -role node - 
Dwebdriver.chrome.driver="C:\D\chromedriver.exe" -hub 
http://localhost:4444/grid/register -browser browserName=chrome,version=24,maxInstances=15,platform=WINDOWS 

2)的Java代码,以提供能力和实例RemoteWebDriver。

DesiredCapabilities capability=null; 
    capability= DesiredCapabilities.chrome(); 
    capability.setBrowserName("chrome"); 
    capability.setVersion("24"); 
    capability.setPlatform(org.openqa.selenium.Platform.WINDOWS); 
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability); 
    driver.get(browsingUrl); 

3)Suite.xml

<suite name="testapp" parallel="tests" > 
<test verbose="2" name="testapp" annotations="JDK"> 
    <classes> 
     <class name="com.testapp" /> 
    </classes> 
</test> 

<profile> 
     <id>testapp</id> 
     <build> 
     <plugins> 
      <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.6</version> 
      <configuration> 
       <testFailureIgnore>true</testFailureIgnore> 
       <parallel>tests</parallel> 
        <threadCount>10</threadCount> 
        <suiteXmlFiles>       
         <suiteXmlFile>target/test-classes/Suite.xml</suiteXmlFile>      
        </suiteXmlFiles> 
      </configuration> 
      </plugin> 
     </plugins> 
     </build> 
    </profile> 

运行行家测试

mvn test -Ptestapp 

调用枢纽配置

http://localhost:4444/grid/console?config=true&configDebug=true 

告诉铬的15个实例也有,但运行MVN命令只镀铬的一个实例是opened.Tell我,如果我做错什么。

回答

2

在您的Suite.xml中,您配置了属性parallel = tests。但实际上,您在xml文件中只有一个test标记。所以,没有机会启动两个chrome实例。

参见TestNG的文档here for more about parallelism.

编辑:

<suite name="testapp" parallel="classes" > 
    <test verbose="2" name="testapp" annotations="JDK"> 
     <classes> 
     <class name="com.testapp"/> 
     <class name="com.testapp"/> 
     </classes> 
    </test> 
    </suite> 

通过上述XML文件中@Test方法,其存在于类com.testapp将在两个不同的线程运行(即并行模式) 。

如果要在并行模式下运行单个的@Test方法,则需要将XML文件parallel属性配置为methods

+0

在浏览器的多个实例中是否无法运行相同的测试? – sandy 2013-02-21 12:25:05

+0

是的,可以在浏览器的多个实例中运行相同的'@ test'方法。要做到这一点,你必须修改你的testng.xml文件。查看编辑过的帖子。 – Manigandan 2013-02-22 04:26:18

0

在testng中,对于并行属性,parallel =“methods”表示用@Test注释的所有方法都是并行运行的。

平行= “测试” 的手段,如果你有

<test name = "P1"> 
    <classes>....</classes> 
</test> 
<test name = "P2"> 
    <classes>....</classes> 
</test> 

P1和P2将并行运行。如果两个测试中的类都相同,则可能会发生相同的方法开始并行运行。

此外,POM部分有

<parallel>tests</parallel> 
<threadCount>10</threadCount> 

会永远支持你的testng.xml文件指定的内容被覆盖。所以没有必要为你的surefire部分包含这些数据,因为如果你指定了一个xml,它会采用你在xml中指定的内容,如果xml没有为parallel指定任何值,那么false的默认值将覆盖你在ur pom中指定了什么。

相关问题