【问题标题】:Multiple instances of chrome are not opening up in grid using webdriver使用 webdriver 在网格中未打开多个 chrome 实例
【发布时间】:2013-02-06 15:43:38
【问题描述】:

为了使用 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 实例。如果我做错了什么,请告诉我。

【问题讨论】:

    标签: webdriver testng selenium-grid


    【解决方案1】:

    在 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 文件,com.testapp 类中的 @Test 方法将在两个不同的线程中运行(即并行模式)。

    如果您想以并行模式运行单个@Test 方法,则将 XML 文件 parallel 属性配置为 methods

    【讨论】:

    • 不能在多个浏览器实例中运行相同的测试吗?
    • 是的,可以在多个浏览器实例中运行相同的 @test 方法。为此,您必须修改您的 testng.xml 文件。查看编辑后的帖子。
    【解决方案2】:

    在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 中指定的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-06
      • 1970-01-01
      • 2017-05-26
      • 2017-01-13
      • 2022-01-04
      • 2014-11-04
      • 2015-07-27
      • 1970-01-01
      相关资源
      最近更新 更多