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) 機能を提供し、RemoteWebDriver をインスタンス化する Java コード。

  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 のインスタンスが利用可能ですが、mvn コマンドを実行すると、クロムのインスタンスが 1 つだけ開かれます。

4

2 に答える 2

2

Suite.xmlで、属性を構成しましたparallel = teststestただし、実際には、xmlファイルにはタグが1つしかありません。したがって、2つの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は2つの異なるスレッドで実行されます(つまり、並列モード)。

個々の@Testメソッドを並列モードで実行する場合は、XMLファイルparallel属性をに設定しますmethods

于 2013-02-21T11:31:06.563 に答える