Maven TestNG项目,将命令行参数传递给TestNG.xml文件

Maven TestNG项目,将命令行参数传递给TestNG.xml文件,maven,command-line,testng,pom.xml,Maven,Command Line,Testng,Pom.xml,我有一个Maven TestNG项目,正在尝试将两个命令行参数传递到TestNG.xml文件中 testng.xml文件如下所示: <suite name="Test Suite" parallel="classes" thread-count="100" > <test name="VIP Tests"> <parameter name="browser" value="${browser}" /> <groups>

我有一个Maven TestNG项目,正在尝试将两个命令行参数传递到TestNG.xml文件中

testng.xml文件如下所示:

<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>
<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>
我在命令行中遇到以下错误:

[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}

有人能帮忙吗?我已经被这个问题困扰了大约一周。

${var}符号

但是你可以用。然后,您必须选择已修改的资源:

<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>

4.0.0
测试项目

我使用的Maven命令是“mvn clean test-U-Dtest.scope=smoke-Dbrowser=chrome”。很抱歉遗漏了browser参数。@谢谢。
<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>