mardi 29 août 2017

Trouble launching chromedriver in Spock test

I have a Maven web project for which I'm trying to run a couple of simple Spock web UI tests under Eclipse with Selenium and Chromedriver. I can run each test class individually by clicking on it and selecting "Run As>Junit Test" if I add the following to the file's run configuration VM arguments:

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

Obviously, this is the location of the Chromedriver on my system. Then I tried to set up a Maven build goal at the project level to run the tests. I click on the project name and select "Run Configurations>Maven Build" and create a "Verify" configuration to match the verify goal defined in my pom. In the "Goals, box I enter "verify" and on the JRE tab I also enter the above location for the chromedriver in the VM arguments box. When I run this goal, or on the command line type "mvn verify", I get the following error:

geb.driver.DriverCreationException: failed to create driver from callback 'script15040527017471153797989$_run_closure1@1046d517' at com.google.common.base.Preconditions.checkState(Preconditions.java:754) ...

This tells me the test can not locate the chromedriver. If I copy the chromedriver into the base directory of the project, the then the test will run using the verify goal or by typing "mvn verify" on the command line. Why isn't setting the chromedriver location not working at the maven goal level?

I don't think this really matters, but the build section of my pom is

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

Aucun commentaire:

Enregistrer un commentaire