下面的testng.xml
文件有三个参数。我不想对参数 customerCode
进行硬编码。我想将不同的/不同的 customerCode
传递给以下 testng.xml
文件,但我也想将 Peter 作为默认 customerCode
如果只是如果我不通过 mvn
命令行提供一个,如下所示:
mvn test -DcustomerCode=customer1 -Ptestng.xml
下面是testng.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestSuite" parallel="false">
<test name="someTest">
<parameter name="browserType" value="chrome_win"></parameter>
<parameter name="Url" value="http://regression.mytest.com/?customerCode=" />
<parameter name="customerCode" value="Peter"/>
<groups>
<run>
<exclude name="navigateToHomePage" />
</run>
</groups>
<classes>
<class name="com.automation.customermanagement.createTest.myIntegrationTest" >
<methods>
<exclude name="deleteCustomer" />
</methods>
</class>
</classes>
</test>
</suite>
我该如何实现?有办法吗?
下面是我的 POM 文件。我应该将 customerCode
属性放在配置文件的什么位置?
<profile>
<id>AddMgmtTest</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>admgmttestng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
最佳答案
这是我实现的解决方案,它运行良好!
1) 将以下属性添加到POM.xml
文件
<systemProperties>
<property>
<name>customerCode</name>
<value>Subaru</value>
</property>
</systemProperties>
2) 将这一行添加到测试方法
String customerCode= System.getProperty("customerCode");
3) 上面一行拉取下面mvn命令行中提供的customerCode=customer1
mvn 测试 -DcustomerCode=customer1 -Ptestng.xml
如果您不在命令行中提供 customerCode
,它将采用 POM.xml
中上述属性中提供的默认值 Subaru
> 文件
关于java - 如何通过mvn命令行传递testng.xml参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43433315/