Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
#8 added pom snippet, which downloads geckodriver used by the examples.
Browse files Browse the repository at this point in the history
Adjusted assumption to check if FirefoxDriver can be constructed with
default settings to have tests ignored in maven.
  • Loading branch information
liptga committed May 2, 2017
1 parent 77b1c20 commit 1f04557
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ It happens sometimes, that a Selenium HUB has some weird problems like "Connecti
rule it is possible to retry tests if the exception matches a given matcher.

```java
public class RetryExample {
public class RetryExampleTest {
private static int counter;

@Rule
Expand Down
110 changes: 110 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,114 @@
<scope>test</scope>
</dependency>
</dependencies>

<properties>
<geckodriver.version>v0.16.1</geckodriver.version>
<geckodriver.type>This will be overwritten by a profile for the specific platform</geckodriver.type>
<geckodriver.archive>geckodriver-${geckodriver.version}-${geckodriver.type}</geckodriver.archive>
<geckodriver.url>https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/${geckodriver.archive}</geckodriver.url>
<geckodriver.extension></geckodriver.extension>
<geckodriver.folder>${project.build.directory}</geckodriver.folder>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dwebdriver.gecko.driver=${geckodriver.folder}${file.separator}geckodriver${geckodriver.extension}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<executions>
<execution>
<id>download-geckodriver</id>
<phase>generate-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source><![CDATA[
String url = project.properties['geckodriver.url'];
String archiveName = project.properties['geckodriver.archive'];
AntBuilder ant = new AntBuilder();
String geckodriverFolder = project.properties['geckodriver.folder'];
String archivePath = geckodriverFolder + File.separator + archiveName;
File archiveFile = new File(archivePath);
if (!archiveFile.exists()) {
println("Downloading geckodriver from " + url + "...");
ant.mkdir(dir: geckodriverFolder);
ant.get(
src: url,
dest: archivePath,
skipexisting: false);
if (archiveName.endsWith("tar.gz")) {
ant.untar(src: archivePath, dest: geckodriverFolder, compression: 'gzip');
ant.chmod(file:geckodriverFolder + File.separator + 'geckodriver',perm:'+x');
} else {
ant.unzip(src: archivePath, dest: geckodriverFolder);
}
}
]]></source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>mac</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<geckodriver.type>macos.tar.gz</geckodriver.type>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<family>unix</family>
<arch>amd64</arch>
</os>
</activation>
<properties>
<geckodriver.type>linux64.tar.gz</geckodriver.type>
</properties>
</profile>
<profile>
<id>win32</id>
<activation>
<os>
<family>windows</family>
<arch>x86</arch>
</os>
</activation>
<properties>
<geckodriver.type>win32.zip</geckodriver.type>
<geckodriver.extension>.exe</geckodriver.extension>
</properties>
</profile>
<profile>
<id>win64</id>
<activation>
<os>
<family>windows</family>
<arch>x64</arch>
</os>
</activation>
<properties>
<geckodriver.type>win64.zip</geckodriver.type>
<geckodriver.extension>.exe</geckodriver.extension>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

import java.time.Duration;
import java.time.temporal.TemporalUnit;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

Expand All @@ -28,6 +31,7 @@ public static void beforeClass() {
//with withDefaultFirefoxSettings settings is getting your location is granted.
//See at.willhaben.willtest.config.DefaultFirefoxConfigurationParticipant
.withDefaultFirefoxSettings()
.withImplicitWait(Duration.ofSeconds(30))
.withFirefoxConfigurationParticipant(
new FirefoxConfigurationParticipant() {
@Override
Expand All @@ -46,7 +50,11 @@ public void postConstruct(WebDriver webDriver) {
public void testMyLocation() {
WebDriver webDriver = seleniumRule.getWebDriver();
webDriver.get("https://mycurrentlocation.net/");
assertThat(webDriver.findElement(By.cssSelector("td#latitude")).getText(),is("48.20102"));
By latitudeLocator = By.cssSelector("td#latitude");
seleniumRule
.getDefaultWebDriverWait()
.until(wd -> !wd.findElement(latitudeLocator).getText().isEmpty());
assertThat(webDriver.findElement(latitudeLocator).getText(),is("48.20102"));
assertThat(webDriver.findElement(By.cssSelector("td#longitude")).getText(),is("15.62025"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import static org.hamcrest.CoreMatchers.containsString;

public class RetryExample {
public class RetryExampleTest {
private static int counter;
private static String originalProvider;

Expand Down
25 changes: 19 additions & 6 deletions examples/src/test/java/at/willhaben/willtest/examples/Utils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package at.willhaben.willtest.examples;

import at.willhaben.willtest.config.DefaultFirefoxBinaryProvider;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
Expand All @@ -10,11 +13,21 @@ public final class Utils {
private Utils() {}

public static void assumeHavingFirefoxConfigured() {
assumeThat(
"Please define the path to your firefox executable using " +
DefaultFirefoxBinaryProvider.FIREFOX_BINARY_LOCATION_SYSTEM_PROPERTY_KEY + " system property! " +
"This is just an assumption to keep our build green.",
System.getProperty(DefaultFirefoxBinaryProvider.FIREFOX_BINARY_LOCATION_SYSTEM_PROPERTY_KEY),
is(notNullValue()));
try {
new FirefoxBinary();
}
catch ( WebDriverException e ) {
if ( e.getMessage().contains("Cannot find firefox binary in PATH") ) {
assumeThat(
"Please define the path to your firefox executable using " +
DefaultFirefoxBinaryProvider.FIREFOX_BINARY_LOCATION_SYSTEM_PROPERTY_KEY +
" system property, or add your firefox executable to the PATH variable! " +
"This is just an assumption to keep our build green.",
System.getProperty(DefaultFirefoxBinaryProvider.FIREFOX_BINARY_LOCATION_SYSTEM_PROPERTY_KEY),
is(notNullValue()));
} else {
throw e;
}
}
}
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down

0 comments on commit 1f04557

Please sign in to comment.