Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
In-build selenium-server to run your tests headless in any operating system.
<profile>
<id>selenium-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-selenium-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>selenium.standalone.server.port</portName>
</portNames>
<minPortNumber>4444</minPortNumber>
<maxPortNumber>5000</maxPortNumber>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/test-config</outputDirectory>
<fileNameFiltering>true</fileNameFiltering>
<resources>
<resource>
<directory>test</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>process-test-resources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>target/test-config/selenium-config.json</file>
<replacements>
<replacement>
<token>4444</token>
<value>${selenium.standalone.server.port}</value>
</replacement>
<replacement>
<token>selenium.webdriver</token>
<value>${selenium.webdriver}</value>
</replacement>
<replacement>
<token>selenium.baseUrl</token>
<value>${selenium.baseUrl}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>1.0.14</version>
<configuration>
<rootStandaloneServerDirectory>target/selenium-server</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>target/selenium-drivers</downloadedZipFileDirectory>
<sixtyFourBitBinaries>true</sixtyFourBitBinaries>
<onlyGetDriversForHostOperatingSystem>true</onlyGetDriversForHostOperatingSystem>
<overwriteFilesThatExist>false</overwriteFilesThatExist>
<useSystemProxy>true</useSystemProxy>
<customRepositoryMap>test/selenium-repositories.xml</customRepositoryMap>
</configuration>
<executions>
<execution>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>selenium-server-standalone</includeArtifactIds>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.bazaarvoice.maven.plugins</groupId>
<artifactId>process-exec-maven-plugin</artifactId>
<version>0.8</version>
<executions>
<execution>
<id>start-jar</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<workingDir>lib</workingDir>
<name>Selenium Server</name>
<healthcheckUrl><!-- Properties from pom or maven-build-helper-plugin -->
http://${selenium.standalone.server.hostname}:${selenium.standalone.server.port}/wd/hub
</healthcheckUrl>
<arguments>
<argument>java</argument><!-- Properties below populated by driver-binary-downloader-maven-plugin -->
<argument>-Dwebdriver.chrome.driver=${webdriver.chrome.driver}</argument>
<argument>-jar</argument>
<argument>
${project.build.directory}/lib/selenium-server-standalone-${selenium.standalone.server.version}.jar
</argument>
<argument>-port</argument>
<argument>${selenium.standalone.server.port}</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>stop-jar-process</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-all</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>run-selenium-tests</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${script.execution}runGrunt${script.extension}</executable>
<arguments>
<argument>selenium-tests</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server-standalone</artifactId>
<version>${selenium.standalone.server.version}</version>
</dependency>
</dependencies>
</profile>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment