【发布时间】:2017-08-30 00:54:19
【问题描述】:
我有一个 Maven Web 项目,我正在尝试在 Eclipse 下使用 Selenium 和 Chromedriver 运行几个简单的 Spock Web UI 测试。如果我将以下内容添加到文件的运行配置 VM 参数中,我可以通过单击它并选择“Run As>Junit Test”来单独运行每个测试类:
-Dwebdriver.chrome.driver=/Users/mht/ChromeDriver/2.3.1/chromedriver
显然,这是 Chromedriver 在我的系统上的位置。然后我尝试在项目级别设置一个 Maven 构建目标来运行测试。我单击项目名称并选择“运行配置>Maven 构建”并创建一个“验证”配置以匹配我在 pom.xml 中定义的验证目标。在“目标”框中,我输入“验证”,在 JRE 选项卡上,我还在 VM 参数框中输入 chromedriver 的上述位置。当我运行这个目标时,或者在命令行输入“mvn verify”,我得到以下错误:
geb.driver.DriverCreationException:无法从回调“script15040527017471153797989$_run_closure1@1046d517”创建驱动程序 在 com.google.common.base.Preconditions.checkState(Preconditions.java:754) ...
这告诉我测试找不到 chromedriver。如果我将 chromedriver 复制到项目的基本目录中,那么测试将使用验证目标或在命令行上键入“mvn verify”来运行。为什么在 Maven 目标级别设置 chromedriver 位置不起作用?
我认为这并不重要,但我的 pom 的构建部分是
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*Spec.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<port>9081</port>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>tomcat-shutdown</id>
<goals>
<goal>shutdown</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
【问题讨论】:
标签: maven testing selenium-chromedriver spock geb