2013-02-21 102 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中指定了什麼。

相關問題