Skip to content

Instantly share code, notes, and snippets.

@carstenlenz
Last active August 9, 2016 11:48
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 carstenlenz/251fc0a9eac240bd6ca5f5330889bc2b to your computer and use it in GitHub Desktop.
Save carstenlenz/251fc0a9eac240bd6ca5f5330889bc2b to your computer and use it in GitHub Desktop.
Use a Groovy Console for an interactive Geb Session

Interactive Geb session

This uses a Groovy Console that is connected to a Geb Browser session. It allow for a responsive interaction with Geb to evaluate / test expressions.

It has the project's test code in the classpath so you can use all your page objects or utility code directly in the Console.

dependencies {
// ...
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile "org.gebish:geb-spock:0.13.1"
}
task gebConsole(dependsOn: 'testClasses', type: JavaExec) {
main = 'my.ConsoleRunner'
classpath = sourceSets.test.runtimeClasspath
args = ['startup_script.groovy']
}
package my
/**
* This pre-initializes the Console
*/
class ConsoleRunner {
static void main(String[] args) {
def script = args[0]
def console = new Console()
console.run()
console.loadScriptFile(new File(script))
console.runScript()
}
}
import geb.Browser
// import your.page.objects.here.*
// missing here: setting baseurl etc.
Browser.drive {
go "www.google.de"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment