2017-01-31 40 views
0

我想通過maven和命令行運行test.xml文件。我的test.xml有4個班級,但不幸的是'mvn test'命令只能選擇一個班級。無法在java selenium中通過maven和命令行運行test.xml文件

以下是我的項目結構。 Project structure

這裏是pom.xml

<groupId>com.mobikon.commontestapp</groupId> 
<artifactId>commontestapp</artifactId> 
<version>1.0-SNAPSHOT</version> 

<repositories> 
    <repository> 
     <id>central</id> 
     <name>bintray</name> 
     <url>http://jcenter.bintray.com</url> 
    </repository> 
</repositories> 

<dependencies> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.53.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.9.10</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.uncommons</groupId> 
     <artifactId>reportng</artifactId> 
     <version>1.1.2</version> 
     <scope>test</scope> 
     <exclusions> 
      <exclusion> 
       <groupId>org.testng</groupId> 
       <artifactId>testng</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>commons-lang</groupId> 
     <artifactId>commons-lang</artifactId> 
     <version>2.5</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.19.1</version> 
    </dependency> 

    <dependency> 
     <groupId>commons-configuration</groupId> 
     <artifactId>commons-configuration</artifactId> 
     <version>1.10</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-configuration2</artifactId> 
     <version>2.1</version> 

    </dependency> 

</dependencies> 

<profiles> 

    <profile> 
     <id>test</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.19.1</version> 


        <configuration> 
         <properties> 
          <property> 
           <name>usedefaultlisteners</name> 
           <value>false</value> 
          </property> 
          <property> 
           <name>listener</name> 
           <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value> 
          </property> 
         </properties> 

         <suiteXmlFiles> 
          <suiteXmlFile>test.xml</suiteXmlFile> 
         </suiteXmlFiles> 
         <!--<workingDirectory>target/</workingDirectory>--> 
        </configuration> 

       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

的代碼,這裏是test.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > 
<suite name="Mobikon Automation Tests" verbose="1" > 

    <test name="mEngage" > 
     <classes> 
      <class name="mengage.tests.LoginScenarios"></class> 
      <class name="mengage.tests.PurchaseCreditsTest"></class> 
      <class name="mengage.tests.VerifyTotalCustomers"></class> 
      <class name="mengage.tests.VerifyCredits"></class> 
     </classes> 
    </test> 
</suite> 

代碼,所以現在如果我在命令行運行Maven是這樣的output.It只採取PurchaseCredits類。

命令 - mvn clean test

如果我從直接的IntelliJ它運行正常運行,所以我面臨的唯一的問題是我不能夠運行從行家

適當test.xml文件後MVN -Ptest乾淨的測試,這是Maven的截圖 enter image description here

回答

1

必須激活激活相應的surefire配置文件:

mvn -Ptest clean test 

默認情況下,surefire只運行Test**Test類。這就解釋了爲什麼只有PurchaseCreditsTest在你的情況下。

+0

非常感謝您的幫助..但現在我得到的錯誤,test.xml不是一個有效的文件..你能請同樣的幫助 –

+0

什麼是說xml失敗是錯誤的? IntelliJ和/或maven?如果僅使用IntelliJ,請嘗試更新的版本,因爲您可能會嵌入太舊的testng版本。 – juherr

+0

我使用Intellij作爲Maven框架的工具。而在pom.xml中我已經提到 org.testng TestNG的 6.10 測試 但還是錯誤保持不變。 **「在分支進程中出現錯誤 [錯誤] org.apache.maven.surefire.testset.TestSetFailedException:套件文件D:\ repos \ mobikontestapp \ src \ test \ java \ test.xml不是有效的文件「** –