【问题标题】:Run antrun plugin before suit tests of testng in maven build在 Maven 构建中测试 testng 之前运行 antrun 插件
【发布时间】:2016-12-22 21:15:19
【问题描述】:

当我运行项目的构建时,在运行测试之前,我需要下载并解压缩 chromedriver。

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.relevantcodes</groupId>
        <artifactId>extentreports</artifactId>
        <version>2.41.2</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <configuration>
                        <target>
                            <get src="https://chromedriver.storage.googleapis.com/2.26/chromedriver_win32.zip"
                                 dest="${project.basedir}"
                                 verbose="false"
                                 usetimestamp="true" />
                            <unzip src="${project.basedir}/chromedriver_win32.zip" dest="${project.basedir}/drivers/" />
                            <delete file="${project.basedir}/chromedriver_win32.zip" />
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <executions>
                <execution>
                    <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                            <configuration>
                                <suiteXmlFiles>
                                    <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                                </suiteXmlFiles>
                            </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

要下载我正在使用 antrun 插件,但是,即使稍后在 pom.xml 中声明了surefire插件,正如我在other questions 中看到的那样,稍后也运行测试,构建之前没有下载驱动程序。

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building identificationkey 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ identificationkey ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\malibu\workspace\identificationkey\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ identificationkey ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ identificationkey ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ identificationkey ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ identificationkey ---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 4, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 1.32 sec <<< FAILURE! - in TestSuite
setUp(br.ufrn.imd.ihc.identificationkey.run.LoginTest)  Time elapsed: 0.743 sec  <<< FAILURE!
java.lang.IllegalStateException: The driver executable does not exist: C:\Users\malibu\workspace\identificationkey\drivers\chromedriver.exe
    at br.ufrn.imd.ihc.identificationkey.run.LoginTest.setUp(LoginTest.java:25)


Results :

Failed tests: 
  LoginTest.setUp:25 » IllegalState The driver executable does not exist: C:\Use...

Tests run: 4, Failures: 1, Errors: 0, Skipped: 3

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.784 s
[INFO] Finished at: 2016-12-22T17:52:02-03:00
[INFO] Final Memory: 18M/244M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project identificationkey: There are test failures.
[ERROR] 
[ERROR] Please refer to C:\Users\malibu\workspace\identificationkey\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我做错了什么?任何帮助将不胜感激。

【问题讨论】:

    标签: java maven maven-surefire-plugin maven-antrun-plugin


    【解决方案1】:

    您需要了解 Maven 生命周期(请参阅 Introduction to the Build Lifecycle),它规定了 maven 处理您的构建的顺序。

    在您的情况下,您为执行 maven-antrun-plugin 指定了 &lt;phase&gt;package&lt;/phase&gt;,它位于 test 之后。

    我会为您的用例使用类似 &lt;phase&gt;process-test-resources&lt;/phase&gt; 的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-30
      • 2017-01-09
      • 1970-01-01
      • 2012-08-11
      • 2014-02-11
      • 2011-04-16
      • 1970-01-01
      相关资源
      最近更新 更多