2017-04-16 7 views
1

testng.xml以下のファイルには3つのパラメータがあります。私はパラメータcustomerCodeをハードコードしたくありません。私は次のtestng.xmlファイルに/ diffent customerCodeを変える渡したいが、また、私は念のため、私はmvnコマンドラインから1を提供しない場合は、次のようにデフォルトcustomerCodeとしてピーターを持つようにしたい:以下mvnコマンドラインからtestng.xmlパラメータ値を渡す方法

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> 

答えて

0

これは私が実装したソリューションで、うまくいきます!

1)行の上customerCode=customer1は、以下MVNコマンドラインに設けられたプル)法

String customerCode= System.getProperty("customerCode"); 

3をテストするためにPOM.xmlファイル

    <systemProperties> 
         <property> 
          <name>customerCode</name> 
          <value>Subaru</value> 
         </property> 
        </systemProperties> 

2)を追加し、このラインにプロパティ以下追加

mvn test -DcustomerCode = customer1 -Ptestng.xml

コマンドラインにcustomerCodeを指定しないと、上記のプロパティで提供されているSubaruのデフォルト値ファイル

が使用されます
関連する問題