2017-08-30 119 views
1

我有一个Maven web项目,我正尝试在Eclipse下使用Selenium和Chromedriver运行一些简单的Spock Web UI测试。如果我将以下内容添加到文件的运行配置虚拟机参数中,我可以单独运行每个测试类并单击它并选择“Run As> Junit Test”:在Spock测试中启动chromedriver时遇到麻烦

-Dwebdriver.chrome.driver =/Users/mht/ChromeDriver /2.3.1/chromedriver

很明显,这是我的系统上的Chromedriver的位置。然后我尝试在项目级设置一个Maven构建目标来运行测试。我点击项目名称并选择“运行配置> Maven Build”,并创建一个“验证”配置以匹配我的pom中定义的验证目标。在“目标”框中输入“verify”,然后在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目标水平上工作?

我不认为这真的很重要,但我的聚甲醛的生成部分是

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

回答

1

Maven的参数不被传递给每默认情况下,神火和故障安全配置。这两个新的JVM都没有得到这些参数。有关argLine,请参阅文档SurefireFailsafe。因此mvn verify -DargLine="-Dwebdriver.chrome.driver=/Users/mht/ChromeDriver/2.3.1/chromedriver"应该为你工作。

但是,更好的方法是使用WebDriver Extensions Maven Plugin这可用于自动下载相应的驱动程序。然后,您可以通过一些简单的脚本来通过geb配置来定位驱动程序,或者对已知的相对位置进行硬编码。

顺便说一句gmaven-plus插件已过时。