2014-08-28 482 views
0

我有一個應用程序正在使用Selenium WebDriver和TestNG進行測試。 我有15個方法用@Test註釋標記。 當我開始測試點擊鼠標右鍵測試所有測試15成功完成,但是當我使用命令行用「MVN測試」開始測試Maven的輸出是:當在IDEA中運行時測試完成但在Maven中運行時失敗

[INFO] Scanning for projects... 
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.company.tests:Selenium:jar:1.0-SNAPSHOT 
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 43, column 21 
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. 
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects. 
[WARNING] 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Selenium 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Selenium --- 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory C:\Users\ai\mysel\alexander-aut-webdriver-selenium\fwk\java\trunk\src\main\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Selenium --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Selenium --- 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 1 resource 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Selenium --- 
[INFO] Changes detected - recompiling the module! 
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! 
[INFO] Compiling 5 source files to C:\Users\ai\mysel\alexander-aut-webdriver-selenium\fwk\java\trunk\target\test-classes 
[INFO] 
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ Selenium --- 
[INFO] Surefire report directory: C:\Users\ai\mysel\alexander-aut-webdriver-selenium\fwk\java\trunk\target\surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running TestSuite 
Starting ChromeDriver (v2.9.248315) on port 21287 
Tests run: 22, Failures: 2, Errors: 0, Skipped: 12, Time elapsed: 26.223 sec <<< FAILURE! 

Results : 

Failed tests: 
    openLoginPage(com.company.selenium.tests.LoginTest) 
    openRegistrationPage(com.company.selenium.tests.RegistrationTest) 

Tests run: 22, Failures: 2, Errors: 0, Skipped: 12 

openLoginPage()並打開註冊甚至沒有標記爲@Test,他們用@BeforeMethod註釋標記

爲什麼有22個測試當我在maven中運行? 如何解決這個所以Maven將運行所有測試15

回答

0

我建議你以下幾點: 1)在項目的pom.xml看一看:http://gyazo.com/7a9015de5e0f9801848e9ecba62a18e9 ,並在確保你有以下依賴性您的POM.xml:

<dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>2.41.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-support</artifactId> 
      <version>2.41.0</version> 
     </dependency> 

...... 

    <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.3.1</version> 
      <scope>test</scope> 
     </dependency> 


.......... 
    <dependency> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.17</version> 
     </dependency> 
    </dependencies> 

2)第二步是導航到您的項目文件夾(確切的一個POM.xml文件所在的位置)。 打開命令窗口並運行有

mvn clean test 

http://gyazo.com/9526e807be8a6fc4ad6211d4aab19b5c

3)還注重營造/插件部分的pom.xml

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 

      </configuration> 
     </plugin> 
    </plugins> 

</build> 

也許根本原因是在<version>2.3.2</version>這一個據我所知可以從日誌提供:

ests:Selenium:jar:1.0-SNAPSHOT 
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 43, column 21 

希望這可以幫助你。

+0

感謝您的回答,但它沒有爲我工作 – Alexander 2014-08-28 15:25:23

+0

@亞歷山大,我用第三點更新了我的答案。 – 2014-08-28 15:31:31

+0

仍然有比應該更多的測試,但我以某種方式認識到,重新命名我的一個文件與測試減少了錯誤的數量。用測試重命名其他文件根本沒有幫助。所以現在我有19個測試,而不是15個,而@OneMethod中的1個失敗不是測試 – Alexander 2014-08-29 09:12:47

相關問題