Examples of Geb test automation of various popular use cases available, well… on the Internet :)
A list of such use cases has been collected by Dave Heaffner, and it’s available on https://github.com/tourdedave/the-internet
Available examples from The Internet
-
Done! A/B Testing
-
Done! Add/Remove Elements
-
Done! Basic Auth (user and pass: admin)
-
Done! Broken Images
-
Done! Challenging DOM
-
Done! Checkboxes
-
Digest Authentication (user and pass: admin)
-
Done? Drag and Drop - problem…
-
W-I-P Inputs
-
Done! Large & Deep DOM
-
Done! Multiple Windows
-
Done! Redirect Link
-
Done! Typos
-
Install rvm
-
Install ruby 2.4.1
rvm install ruby-2.4.1
-
Install bundler
gem install bundler
-
Install dependencies
bundle install
-
Start the server:
rackup
-
Pages will be available locally:
http://localhost:9292/url_path
See more at: https://guides.gradle.org/building-groovy-libraries
In build.gradle
pass the gradle project property to system property:
tasks.withType(Test) {
systemProperty 'org.askucins.webdriver', project.findProperty('webdriver')
// [...]
}
Then in the GebConfig.groovy
select your webdriver based on the passed system property:
import org.openqa.selenium.firefox.FirefoxDriver
import static org.askucins.utils.WebDriverConfiguration.chromeDriver
switch (System.getProperty('org.askucins.webdriver')) {
case 'firefox':
driver = { new FirefoxDriver() }
break
case 'chrome':
driver = { chromeDriver([headless: false]) }
break
default:
driver = { chromeDriver([headless: true]) }
}
Also, if you want to e.g. run execute tests with firefox you may run this:
gw test -Pwebdriver=firefox
Although that works just fine, one can use rather the built-in concept of GebConfig.environments, so then in build.gradle
there would be:
tasks.withType(Test) {
systemProperty 'geb.env', project.findProperty('webdriver') ?: 'chrome'
// [...]
}
Aso, then in the GebConfig.groovy
:
environments {
firefox {
atCheckWaiting = 1
driver = { new FirefoxDriver() }
}
firefoxHeadless {
atCheckWaiting = 1
driver = { customizedFirefoxDriver([headless: true]) }
}
chrome {
driver = { customizedChromeDriver([headless: false]) }
}
chromeHeadless {
driver = { customizedChromeDriver([headless: true]) }
}
}
With that setup if the gradle project property 'webdriver' is not defined that 'chrome' environment will be used, while when it is defined - an appropriate environment will be picked up, e.g.
gw test -Pwebdriver=firefox
-
A method
$(…)
(or its aliasfind(…)
) searches in depth, looking for descendants -
Methods
filter(…)
andnot(…)
search in breadth, limiting the found content.
Also, a quote from The Book of Geb:
The
find()
and$()
methods support the exact same argument types as the $() function. Thefilter()
,not()
,has()
andhasNot()
methods have the same signatures - they accept: a selector string, a predicate map or both. These methods return a new navigator object that represents the new content.