在maven构建的testng的套装测试之前运行antrun插件

时间:2016-12-22 21:15:20

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

当我运行项目的构建时,在运行测试之前,我需要下载并解压缩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

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

1 个答案:

答案 0 :(得分:0)

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

在您的情况下,您已为<phase>package</phase>之后的maven-antrun-plugin执行指定了test

我会使用类似<phase>process-test-resources</phase>的内容作为您的用例。

相关问题