首页 > 解决方案 > 使用 Maven、Gauge-Java 框架在不同配置上运行并行测试

问题描述

当我尝试在 LambdaTest Selenium Grid 上运行时,我的测试按顺序运行,但不是并行运行。下面是我的 maven pom 文件的一小部分:

<executions> 
                        <execution>
                        <id>test-chrome</id>
                        <phase>test</phase>
                        <configuration>
                            <env>chrome</env>
                            <inParallel>true</inParallel>
                            <nodes>4</nodes>
                            <specsDir>specs</specsDir>
                        </configuration>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                    </execution>

                    <execution>
                        <id>test-firefox</id>
                        <phase>test</phase>
                        <configuration>
                            <env>firefox</env>
                            <inParallel>true</inParallel>
                            <nodes>4</nodes>
                            <specsDir>specs</specsDir>
                        </configuration>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        </execution>
</executions>

我为 chrome 和 firefox 创建了 2 个不同的目录,其中包含两个不同的属性文件:

chrome.properties 文件:

BROWSER = chrome
BROWSER_VERSION = 78
PLATFORM = WIN10

firefox.properties 文件:

BROWSER = firefox
BROWSER_VERSION = 69
PLATFORM = WIN8

我在我的 java 类文件中使用了这些环境变量:

DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("browserName", System.getenv("BROWSER"));
        capabilities.setCapability("version", System.getenv("BROWSER_VERSION"));
        capabilities.setCapability("platform", System.getenv("PLATFORM"));

任何帮助将不胜感激,非常感谢:)

标签: javamavenseleniumgaugegetgauge

解决方案


尝试用这个替换 chrome.properties:

BROWSER = chrome (PropertyName)
BROWSER_VERSION = 78 
PLATFORM = WIN10

并从属性文件或您想要动态化的任何其他参数中添加驱动程序版本

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <configuration>
         <parallel>tests</parallel>
          <threadCount>10</threadCount>
           <systemPropertyVariables>
            <propertyName>Firefox</propertyName>
            <propertyName>Chrome</propertyName>
          </systemPropertyVariables>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>

        </configuration>
      </plugin>
</plugins>
    </build>
  <dependencies>
    <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>2.47.1</version>
</dependency>   
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>2.47.1</version>
</dependency>
        <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.47.1</version>
    </dependency>  
</dependencies> 

推荐阅读