Skip to content

Instantly share code, notes, and snippets.

@RobertFischer
Created August 6, 2014 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertFischer/af21ce4b4b88a480f470 to your computer and use it in GitHub Desktop.
Save RobertFischer/af21ce4b4b88a480f470 to your computer and use it in GitHub Desktop.
Geb Boilerplate Script
// The first time you run this, it will take a very long, annoyingly silent pause while it loads libraries
@Grapes([
@Grab("org.gebish:geb-core:0.9.3"),
@Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.41.0"),
@Grab("org.seleniumhq.selenium:selenium-support:2.41.0")
])
import geb.Browser
Browser.drive {
/* Put your Geb code here. For instance...
System.out.println("Going to Google");
go "http://google.com/ncr"
// make sure we actually got to the page
assert title == "Google"
// enter wikipedia into the search field
$("input", name: "q").value("wikipedia")
// wait for the change to results page to happen
// (google updates the page dynamically without a new request)
System.out.println("Waiting for search");
waitFor { title.endsWith("Google Search") }
// is the first link to wikipedia?
def firstLink = $("li.g", 0).find("a.l")
assert firstLink.text() == "Wikipedia"
// click the link
firstLink.click()
// wait for Google's javascript to redirect to Wikipedia
System.out.println("Waiting for Wikipedia");
waitFor { title == "Wikipedia" }
System.out.println("At Wikipedia");
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment