java - 使用 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"));
任何帮助将不胜感激,非常感谢:)
解决方案
尝试用这个替换 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>
推荐阅读
- ruby-on-rails - Heroku Ruby-on-Rails 应用程序无法加载,日志看起来不错
- sql - 如果表节点存在,SQL XML .node .query() 返回空字符串而不是 NULL
- java - 画一个直角三角形
- ios - Swift 符合协议子类
- drupal - Drupal 菜单链接到外部站点
- c# - 使用通用标签从 XML 获取特定数据
- php - 将逗号分隔值更改为换行符
- javascript - 无法使用 npm 安装任何软件包
- kubernetes - 如何从 K8 pod 向同一集群中的 NodePort 服务发出 HTTP 请求
- c++ - OpenCV 4.0 中的 cvCreateMat