简体   繁体   English

在Maven构建中对Testng进行套装测试之前运行antrun插件

[英]Run antrun plugin before suit tests of testng in maven build

When I run the build of my project, before running the tests, I need to download and unzip the chromedriver. 在运行项目的构建时,在运行测试之前,我需要下载并解压缩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>

To download I'm using the antrun plugin, but, even declaring the surefire plugin later in pom.xml, as I saw in other questions , to run the tests later too, the build did not download the driver before. 要下载,我使用的是antrun插件,但是,即使稍后再在pom.xml中声明surefire插件(如我在其他问题中看到的那样),也要稍后再运行测试,该构建之前也没有下载驱动程序。

[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

What am I doing wrong? 我究竟做错了什么? Any help would be appreciated. 任何帮助,将不胜感激。

You need to be aware of the Maven lifecycle (see Introduction to the Build Lifecycle ), which dictates the order in which maven processes your build. 您需要了解Maven生命周期(请参阅Build Lifecycle简介 ),它规定了Maven处理构建的顺序。

In your case, you have specified <phase>package</phase> for your maven-antrun-plugin execution, which comes after test . 在您的情况下,您为maven-antrun-plugin执行指定了<phase>package</phase> ,它在test之后。

I would use something like <phase>process-test-resources</phase> for your use case. 我将在您的用例中使用<phase>process-test-resources</phase>的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM