Skip to content

Instantly share code, notes, and snippets.

@andidev
Last active June 27, 2017 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andidev/b182c59a92d5ad66b035 to your computer and use it in GitHub Desktop.
Save andidev/b182c59a92d5ad66b035 to your computer and use it in GitHub Desktop.
Example of a WebDriver Extensions Test written in Groovy
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;
@Grab(group='com.github.webdriverextensions', module='webdriverextensions', version='3.3.0')
@RunWith(WebDriverRunner)
@Firefox
@Chrome
@InternetExplorer
class WebDriverExtensionsGroovyExampleTest {
@FindBy(name = "q")
WebElement queryInput;
@FindBy(name = "btnG")
WebElement searchButton;
@FindBy(id = "search")
WebElement searchResult;
@Test
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. Download and extract the Chrome Driver and the Internet Explorer Driver (currently you can find the Chrome Driver here and the Internet Explorer Driver here)
  5. Run with groovy -Dwebdriver.chrome.driver=path/to/chromedriver -Dwebdriver.ie.driver=path/to/iedriver WebDriverExtensionsGroovyTest.groovy

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