Maven TestNG项目,将命令行参数传递给testng.xml文件 [英] Maven TestNG project, pass command line arguments to testng.xml file
问题描述
我有一个Maven TestNG项目,正在尝试将几个命令行参数传递到testng.xml文件中.
I have a Maven TestNG project, and am trying pass couple of command line arguments into the testng.xml file.
testng.xml文件如下所示:
The testng.xml file looks like below:
<suite name="Test Suite" parallel="classes" thread-count="100" >
<test name="VIP Tests">
<parameter name="browser" value="${browser}" />
<groups>
<run>
<include name="${test.scope}" />
</run>
</groups>
<packages>
<package name="com.tests.*" />
</packages>
</test>
</suite>
pom.xml文件如下所示:
The pom.xml file looks like below:
<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>Test_Project</groupId>
<artifactId>TP_X</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<resources>
<resource>
<directory>src/test/resources</directory>
</resource>
</resources>
<sourceDirectory>${src.dir}</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
现在,每次我尝试执行Maven测试命令
Now, every time I attempt to execute the Maven test command
mvn clean test -U -Dtest.scope=smoke -Dbrowser=chrome
我在命令行中遇到以下错误:
I get the following error in the command line:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project VIP_QE: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process
[ERROR] java.util.regex.PatternSyntaxException:
[ERROR] Illegal repetition near index 0
[ERROR] ${test.scope}
有人可以帮忙吗?我已经被这个问题困扰了大约一个星期.
Can someone please help? I have been stuck with this problem for about a week.
推荐答案
TestNG和surefire不支持${var}
表示法.
TestNG and surefire are not supporting the ${var}
notation.
但是您可以使用 Maven的过滤功能.然后,您必须选择修改后的资源:
But you can use the filtering feature of Maven. Then you'll have to choose the modified resource:
<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>Test_Project</groupId>
<artifactId>TP_X</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<sourceDirectory>${src.dir}</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>target/test-classes/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
请注意testResources
和resources
之间的区别:如何我如何过滤Maven中的测试资源?
Note the difference between testResources
and resources
: How do I filter test resources in maven?
这篇关于Maven TestNG项目,将命令行参数传递给testng.xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!