Skip to content

Instantly share code, notes, and snippets.

@andidev
Last active September 3, 2017 11:32
Show Gist options
  • Save andidev/ad006a454edfd9f0e9e5 to your computer and use it in GitHub Desktop.
Save andidev/ad006a454edfd9f0e9e5 to your computer and use it in GitHub Desktop.
Example of a WebDriver Extensions Test
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname</groupId>
<artifactId>projectname</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>webdriverextensions</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>webdriverextensions-maven-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<goals>
<goal>install-drivers</goal>
</goals>
</execution>
</executions>
<configuration>
<drivers>
<driver>
<name>internetexplorerdriver</name>
<version>3.2.0</version>
</driver>
<driver>
<name>chromedriver</name>
<version>2.27</version>
</driver>
<driver>
<name>geckodriver</name>
<version>0.14.0</version>
</driver>
</drivers>
</configuration>
</plugin>
</plugins>
</build>
</project>
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.WebElement;
import com.github.webdriverextensions.junitrunner.WebDriverRunner;
import com.github.webdriverextensions.junitrunner.annotations.*;
import static com.github.webdriverextensions.Bot.*;
import static java.util.concurrent.TimeUnit.SECONDS;
@RunWith(WebDriverRunner.class)
@Firefox
@Chrome
@InternetExplorer
public class WebDriverExtensionsExampleTest {
@FindBy(name = "q")
WebElement queryInput;
@FindBy(name = "btnG")
WebElement searchButton;
@FindBy(id = "search")
WebElement searchResult;
@Test
public void searchGoogleForHelloWorldTest() {
open("http://www.google.com");
assertCurrentUrlContains("google");
type("Hello World", queryInput);
click(searchButton);
waitFor(3, SECONDS);
assertTextContains("Hello World", searchResult);
}
}
@andidev
Copy link
Author

andidev commented Feb 11, 2015

  1. Download gist
  2. Extract
  3. cd into extracted folder
  4. move WebDriverExtensionsExampleTest.java into src/test/java (you need to create the folders first since they do not exist)
  5. Run with mvn test

The test preforms a Google search for "Hello World" and then asserts that the search result contains the text "Hello World"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment