【问题标题】:Tests completes when running in IDEA but fails when running in maven在 IDEA 中运行时测试完成,但在 maven 中运行时失败
【发布时间】:2014-08-28 14:13:41
【问题描述】:

我有一个使用 Selenium WebDriver 和 TestNG 测试的应用程序。 我有 15 个标有 @Test 注释的方法。 当我开始测试用鼠标右键单击测试时,所有 15 个测试都成功完成,但是当我使用带有“mvn test”的命令行开始测试时,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() 和 openRegistration 甚至没有标记为@Test,它们都用@BeforeMethod 注释标记

为什么我在 maven 中运行时有 22 个测试? 我该如何解决这个问题,所以 Maven 将运行所有 15 个测试

【问题讨论】:

    标签: java maven testing selenium testng


    【解决方案1】:

    我向您推荐以下内容: 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 中的 build/plugins 部分

            <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>
    

    据我从您提供的日志中了解到,可能根本原因在于&lt;version&gt;2.3.2&lt;/version&gt;

    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
    

    希望对你有所帮助。

    【讨论】:

    • 仍然有比应有的更多测试,但我以某种方式认识到用测试重命名我的文件之一减少了错误数量。用测试重命名其他文件根本没有帮助。所以现在我有 19 次测试而不是 15 次,@BeforeMethod 中有 1 次失败,这不是测试
    猜你喜欢
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多