Chu*_*hoo 5 java xml maven selenium-webdriver
下面的testng.xml文件有三个参数。我不希望参数customerCode被硬编码。我想将变量/差异传递customerCode给以下testng.xml文件,但我也希望将 Peter 作为默认值customerCode,以防万一我不通过mvn命令行提供一个,如下所示:
mvn test -DcustomerCode=customer1 -Ptestng.xml
Run Code Online (Sandbox Code Playgroud)
下面是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>
Run Code Online (Sandbox Code Playgroud)
我如何做到这一点?有没有办法做到这一点?
下面是我的 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>
Run Code Online (Sandbox Code Playgroud)
这是我实施的解决方案,并且运行良好!
1)将以下属性添加到POM.xml文件中
<systemProperties>
<property>
<name>customerCode</name>
<value>Subaru</value>
</property>
</systemProperties>
Run Code Online (Sandbox Code Playgroud)
2)将此行添加到测试方法中
String customerCode= System.getProperty("customerCode");
Run Code Online (Sandbox Code Playgroud)
3)以上行拉取customerCode=customer1以下 mvn 命令行中提供的内容
mvn 测试 -DcustomerCode=customer1 -Ptestng.xml
如果您未在命令行中提供,它将采用文件中上述属性中提供的customerCode默认值SubaruPOM.xml
| 归档时间: |
|
| 查看次数: |
6457 次 |
| 最近记录: |