在 Maven 中指定多个目标并分别 运行 它们
Specifying multiple goals in Maven and running them separately
我已经使用 Cucumber、Selenium 和 Maven 创建了一个测试框架。我正在使用 cucumber-jvm-parallel
插件并行 运行 我的测试。下面是我的 pom.xml
的样子:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tests</groupId>
<artifactId>test-project</artifactId>
<version>1.0</version>
<name>Test Project</name>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>1.2.3</cucumber.version>
<extentreports.version>2.41.0</extentreports.version>
<selenium.version>2.53.1</selenium.version>
<cucumber.jvm.parallel.version>2.1.0</cucumber.jvm.parallel.version>
</properties>
<dependencies>
<dependency>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>${cucumber.jvm.parallel.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>com.sitture</groupId>
<artifactId>cucumber-jvm-extentreport</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.codec</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>win</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<webdriver.chrome.path>${basedir}${file.separator}resources${file.separator}chromedriver.exe</webdriver.chrome.path>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<family>!windows</family>
</os>
</activation>
<properties>
<webdriver.chrome.path>resources${file.separator}chromedriver</webdriver.chrome.path>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>${cucumber.jvm.parallel.version}</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
<featuresDirectory>src/test/resources/features</featuresDirectory>
<cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
<format>json,html,rerun</format>
<strict>true</strict>
<monochrome>true</monochrome>
<useTestNG>false</useTestNG>
<namingPattern>Parallel{c}IT</namingPattern>
<namingScheme>simple</namingScheme>
<parallelScheme>FEATURE</parallelScheme>
<glue>com.cucumber.stepdefinitions</glue>
<tags>"~@ignore"</tags>
<filterFeaturesByTags>true</filterFeaturesByTags>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>resources</additionalClasspathElement>
</additionalClasspathElements>
<!-- Increase Fork Count to increase parallel execution count.
Currently it is set to 2 which means 2 runners will run in parallel-->
<forkCount>2</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/Parallel*IT.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>perform</goal>
</goals>
<configuration>
<pomFileName>${basedir}${file.separator}pom.xml</pomFileName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我用
mvn clean install
到运行我的套房。 运行 完成后,我在 Jenkins 中配置了一个下游作业,该作业生成一些失败的案例文件。我为这些创建了单独的 运行ners。现在我正在寻找重新 运行 失败的测试用例,并且我创建了名为 failedScenario1.java
、failedScenario2.java
等的文件。我现在想运行这些。我假设我需要在上面的 POM 中定义类似于 org.apache.maven.plugins
的东西并触发 运行。有人可以让我知道如何将它包含在同一个 POM 中吗?另外,如何为 failedScenario*.java
.
触发此 运行
恐怕无法在同一个 POM 中完全按照您的意愿进行。
您需要如下内容:
<profiles>
<profile>
<id>suite</id>
<activation>
<property>
<name>re-test</name>
<value>!true</value>
</property>
<activation>
... your suite's declarations ...
</profile>
<profile>
<id>failed-scenario</id>
<activation>
<property>
<name>re-test</name>
<value>true</value>
</property>
<activation>
<build>
<testSourceDirectory>${project.build.directory}/generated-test-sources/cucumber</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>failed-scenario-test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
...
但是,请参阅 Introduction to Build Profiles, Profiles in POMs:
Profiles specified in the POM can modify the following POM elements:
...
a subset of the <build>
element, which consists of:
• <defaultGoal>
• <resources>
• <testResources>
• <finalName>
因此,那里缺少 <testSourceDirectory>
。
如果您要 generate-test-sources
默认 <testSourceDirectory>${project.basedir}/src/test/java
,您可以在 re-test
配置文件中使用 maven-surefire-plugin
的 <excludes>/<includes>
。缺点是所有 failedScenarioX
将在您下次构建套件时也成为 运行,除非您之前删除它们。
我已经使用 Cucumber、Selenium 和 Maven 创建了一个测试框架。我正在使用 cucumber-jvm-parallel
插件并行 运行 我的测试。下面是我的 pom.xml
的样子:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tests</groupId>
<artifactId>test-project</artifactId>
<version>1.0</version>
<name>Test Project</name>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>1.2.3</cucumber.version>
<extentreports.version>2.41.0</extentreports.version>
<selenium.version>2.53.1</selenium.version>
<cucumber.jvm.parallel.version>2.1.0</cucumber.jvm.parallel.version>
</properties>
<dependencies>
<dependency>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>${cucumber.jvm.parallel.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>com.sitture</groupId>
<artifactId>cucumber-jvm-extentreport</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.codec</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>win</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<webdriver.chrome.path>${basedir}${file.separator}resources${file.separator}chromedriver.exe</webdriver.chrome.path>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<family>!windows</family>
</os>
</activation>
<properties>
<webdriver.chrome.path>resources${file.separator}chromedriver</webdriver.chrome.path>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>${cucumber.jvm.parallel.version}</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
<featuresDirectory>src/test/resources/features</featuresDirectory>
<cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
<format>json,html,rerun</format>
<strict>true</strict>
<monochrome>true</monochrome>
<useTestNG>false</useTestNG>
<namingPattern>Parallel{c}IT</namingPattern>
<namingScheme>simple</namingScheme>
<parallelScheme>FEATURE</parallelScheme>
<glue>com.cucumber.stepdefinitions</glue>
<tags>"~@ignore"</tags>
<filterFeaturesByTags>true</filterFeaturesByTags>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>resources</additionalClasspathElement>
</additionalClasspathElements>
<!-- Increase Fork Count to increase parallel execution count.
Currently it is set to 2 which means 2 runners will run in parallel-->
<forkCount>2</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/Parallel*IT.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>perform</goal>
</goals>
<configuration>
<pomFileName>${basedir}${file.separator}pom.xml</pomFileName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我用
mvn clean install
到运行我的套房。 运行 完成后,我在 Jenkins 中配置了一个下游作业,该作业生成一些失败的案例文件。我为这些创建了单独的 运行ners。现在我正在寻找重新 运行 失败的测试用例,并且我创建了名为 failedScenario1.java
、failedScenario2.java
等的文件。我现在想运行这些。我假设我需要在上面的 POM 中定义类似于 org.apache.maven.plugins
的东西并触发 运行。有人可以让我知道如何将它包含在同一个 POM 中吗?另外,如何为 failedScenario*.java
.
恐怕无法在同一个 POM 中完全按照您的意愿进行。
您需要如下内容:
<profiles>
<profile>
<id>suite</id>
<activation>
<property>
<name>re-test</name>
<value>!true</value>
</property>
<activation>
... your suite's declarations ...
</profile>
<profile>
<id>failed-scenario</id>
<activation>
<property>
<name>re-test</name>
<value>true</value>
</property>
<activation>
<build>
<testSourceDirectory>${project.build.directory}/generated-test-sources/cucumber</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>failed-scenario-test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
...
但是,请参阅 Introduction to Build Profiles, Profiles in POMs:
Profiles specified in the POM can modify the following POM elements:
...
a subset of the
<build>
element, which consists of:•
<defaultGoal>
•
<resources>
•
<testResources>
•
<finalName>
因此,那里缺少 <testSourceDirectory>
。
如果您要 generate-test-sources
默认 <testSourceDirectory>${project.basedir}/src/test/java
,您可以在 re-test
配置文件中使用 maven-surefire-plugin
的 <excludes>/<includes>
。缺点是所有 failedScenarioX
将在您下次构建套件时也成为 运行,除非您之前删除它们。