首先,请在pom.xml中添加改进...需要添加执行部分:
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
其次,您可以使用变量在pom.xml中创建部分。然后,从cmd调用它。
<properties>
<defaultSuiteFiles>
./Sets/Suits/CMS_Administration_SiteBackup_029.xml,
</defaultSuiteFiles>
<suiteFile>${defaultSuiteFiles}</suiteFile>
</defaultSuiteFiles>
</properties>
...
...
<suiteXmlFiles>
<suiteXmlFile>${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
那么,原型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">
.....
.....
<properties>
<defaultSuiteFiles>
./Sets/Suits/CMS_Administration_SiteBackup_029.xml,
</defaultSuiteFiles>
<suiteFile>${defaultSuiteFiles}</suiteFile>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<profiles>
<profile>
<id>Base configuration</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<inherited>true</inherited>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
</project>
并使用此,如何以cmd为例:mvn test -DdefaultSuiteFiles="./YOUR_DIRECTORY/YOUR_SUITE.xml,"
说明:在 pom.xml中,您将 xml 设置为默认值并放置为变量。而且,如果要在cmd中使用变量,则将重写值。