![](/img/trans.png)
[英]How to run dynamic testng.xml using maven mvn test command line?
[英]how to pass testng.xml parameter value through mvn command line
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 test -DcustomerCode = customer1 -Ptestng.xml
如果您不在命令行中提供customerCode
,则它将获取POM.xml
文件中上述属性中提供的Subaru
的默认值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.