2017-03-17 4 views
0

設定で定義されているスイートファイルを使用して、pom.xmlに次のエントリがあります。Mavenのコマンドラインからtestng.xmlを実行するには

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.19.1</version> 
    <configuration> 
     <suiteXmlFiles> 
      <suiteXmlFile>testng.xml</suiteXmlFile> 
     </suiteXmlFiles> 
    </configuration> 
</plugin> 

mavenを使用してcmdでこれを実行する正しい方法は何ですか?私は以下のコマンドでテストを実行することができますが、すでにpomに定義されているときにtestng.xmlを再度コマンドに指定するのは意味がありません。

mvn clean test -DsuiteXmlFile=testng.xml 

答えて

0

最初に、のpom.xmlに改善を追加してください...必要追加実行部:第二に

<executions> 
<execution> 
    <phase>test</phase> 
    <goals> 
     <goal>test</goal> 
    </goals> 
</execution> 
</executions> 

を、あなたは変数とのpom.xml内のセクションを作成することができます。そして、それをcmdから呼び出します。

<properties> 
<defaultSuiteFiles> 
     ./Sets/Suits/CMS_Administration_SiteBackup_029.xml, 
    </defaultSuiteFiles> 
    <suiteFile>${defaultSuiteFiles}</suiteFile> 
</defaultSuiteFiles> 
</properties> 
... 
... 
<suiteXmlFiles> 
    <suiteXmlFile>${suiteFile}</suiteXmlFile> 
</suiteXmlFiles> 

ので、プロトタイプのpom.xmlの結果

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 
..... 
..... 


<properties>   
    <defaultSuiteFiles> 
     ./Sets/Suits/CMS_Administration_SiteBackup_029.xml, 
    </defaultSuiteFiles> 
    <suiteFile>${defaultSuiteFiles}</suiteFile> 


    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

<profiles> 
    <profile> 
     <id>Base configuration</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <build> 
      <defaultGoal>install</defaultGoal> 
      <plugins>      
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.19.1</version> 
        <inherited>true</inherited> 
        <executions> 
         <execution> 
          <phase>test</phase> 
          <goals> 
           <goal>test</goal> 
          </goals> 
         </execution> 
        </executions> 
        <configuration> 
         <suiteXmlFiles> 
          <suiteXmlFile>${suiteFile}</suiteXmlFile> 
         </suiteXmlFiles>        
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 
<dependencies> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>3.3.1</version> 
    </dependency> 
</dependencies> 
</project> 

そして、これを使用して、どのようにcmdの例:mvn test -DdefaultSuiteFiles="./YOUR_DIRECTORY/YOUR_SUITE.xml,"

説明は:デフォルトのためのpom.xmlで、あなたのセットアップXMLS変数に配置します。また、cmdでvariableを使用すると、値が書き換えられます。

2

testng xmlが固定されている場合は、mvn clean testを入力するだけです。 surefireプラグインは、デフォルトでmavenのテスト段階で実行され、xmlのハードコードが選択されます。

+0

はこれをしようとしました。できます。 testng xmlをトリガーする最も簡単な方法と思われます。ありがとうございました! – jeffsia

0

最も簡単な解決策は、surefireプラグインに以下の行を追加することです。

<suiteXmlFiles> 
    <!-- pass testng.xml files as argument from command line --> 
    <suiteXmlFile>${suiteXmlFile}</suiteXmlFile> 
</suiteXmlFiles> 

し、以下のようにXMLファイルを実行し、

mvn clean test -Dsurefire.suiteXmlFiles=/path/to/testng.xml 
関連する問題