Ardesco / driver-binary-downloader-maven-plugin

A Maven plugin that will download the WebDriver stand alone server executables for use in your mavenised Selenium project.
Apache License 2.0
92 stars 52 forks source link

Setting the maven properties does not persist to the application layer. #35

Closed AnthonyClink closed 8 years ago

AnthonyClink commented 8 years ago

I may be doing this wrong or have the wrong expectations... but here is the problem.

when I run the below maven configuration I do not get expected results. Inside my project I have a class:

public class Main{

    public static void main(String[] args){
        System.out.prinln(System.getEnv("webdriver.chrome.driver"));
    }

}

when I run the command mvn clean install exec:java

id expect the output to show the path to the webdriver, however I get null.

Thank you for any input.

plugin definintion:

        <plugin>
            <groupId>com.lazerycode.selenium</groupId>
            <artifactId>driver-binary-downloader-maven-plugin</artifactId>
            <version>1.0.8</version>
            <configuration>
                <rootStandaloneServerDirectory>tmp/binaries</rootStandaloneServerDirectory>
                <downloadedZipFileDirectory>tmp/zips</downloadedZipFileDirectory>
                <customRepositoryMap>RepositoryMap.xml</customRepositoryMap>
                <operatingSystems>
                    <mac>true</mac>
                </operatingSystems>
                <thirtyTwoBitBinaries>true</thirtyTwoBitBinaries>
                <sixtyFourBitBinaries>true</sixtyFourBitBinaries>
                <onlyGetLatestVersions>true</onlyGetLatestVersions>
                <fileDownloadRetryAttempts>2</fileDownloadRetryAttempts>
                <fileDownloadConnectTimeout>20000</fileDownloadConnectTimeout>
                <fileDownloadReadTimeout>10000</fileDownloadReadTimeout>
                <overwriteFilesThatExist>false</overwriteFilesThatExist>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>selenium</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.4.0</version>
            <configuration>
                <mainClass>com.clinktest.Main</mainClass>
            </configuration>
        </plugin>
Ardesco commented 8 years ago

The plugin exposes a maven variable that you can inject into other plugins, you would need to configure it like so:

<plugin>
    <groupId>com.lazerycode.selenium</groupId>
    <artifactId>driver-binary-downloader-maven-plugin</artifactId>
    <version>1.0.8</version>
    <configuration>
        <rootStandaloneServerDirectory>tmp/binaries</rootStandaloneServerDirectory>
        <downloadedZipFileDirectory>tmp/zips</downloadedZipFileDirectory>
        <customRepositoryMap>RepositoryMap.xml</customRepositoryMap>
        <operatingSystems>
            <mac>true</mac>
        </operatingSystems>
        <thirtyTwoBitBinaries>true</thirtyTwoBitBinaries>
        <sixtyFourBitBinaries>true</sixtyFourBitBinaries>
        <onlyGetLatestVersions>true</onlyGetLatestVersions>
        <fileDownloadRetryAttempts>2</fileDownloadRetryAttempts>
        <fileDownloadConnectTimeout>20000</fileDownloadConnectTimeout>
        <fileDownloadReadTimeout>10000</fileDownloadReadTimeout>
        <overwriteFilesThatExist>false</overwriteFilesThatExist>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>selenium</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.4.0</version>
    <configuration>
        <systemProperties>
            <phantomjs.binary.path>${phantomjs.binary.path}</phantomjs.binary.path>
            <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
            <webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
            <webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
        </systemProperties>
        <mainClass>com.clinktest.Main</mainClass>
    </configuration>
</plugin>

It doesn't set env variables or system properties as part of the build because there is no guarantee that the next step will be spun up in the same JVM.

Once you have done the above the following should work:

public class Main{

    public static void main(String[] args){
        System.out.println(System.getProperty("webdriver.chrome.driver"));
    }

}
AnthonyClink commented 8 years ago

Thank you very much for the advice and the assistance. Closing this card.