0

要使用 testng 和 selenium 网格运行并行测试,我确实遵循了步骤。

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> 

运行maven测试

  mvn test -Ptestapp

呼叫中心配置

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

告诉我有 15 个 chrome 实例可用,但运行 mvn 命令只打开了一个 chrome 实例。如果我做错了什么,请告诉我。

4

2 回答 2

2

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

有关并行性的更多信息,请参阅此处的 Testng 文档

编辑:

  <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.

于 2013-02-21T11:31:06.563 回答
0

在 testng 中,对于 parallel 属性,parallel = "methods" 表示所有带有@Test 注解的方法都是并行运行的。

parallel = "tests" 的意思是,如果你有

<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没有为并行指定任何值,那么默认值false将覆盖您在 pom.xml 中指定的内容。

于 2013-02-21T13:34:44.447 回答