I have read most of the (excellent) Geb documentation and have been familiarizing myself with the Geb API with examples that just run as main production code, completely outside the scope of any unit tests. I am now trying to familiarize myself with the Geb-Spock API so that I can write functional/UAT tests. Here is all my code:
// Basic project structure (built w/ Gradle):
geb-sandbox/
src/
main/
groovy/
sandbox.geb/
GoogleHomepage.groovy
GoogleSearchResultsPage.groovy
test/
groovy/
sandbox.geb/
MyFirstGebSpec.groovy
resources/
GebConfig.groovy
build.gradle
// Snippet from build.gradle:
task firefoxTest(type: Test) {
reports {
html.destination = reporting.file('build/reports/tests')
}
outputs.upToDateWhen { false }
systemProperty "geb.build.reportsDir", reporting.file('build/reports/geb')
systemProperty "geb.build.reportsDir", 'firefox'
}
// GebConfig.groovy
import org.openqa.selenium.firefox.FirefoxDriver
waiting {
timeout = 5
}
environments {
firefox {
driver = {
new FirefoxDriver()
}
}
}
// GoogleHomepage.groovy:
class GoogleHomepage extends Page {
static at = {
title == 'Google'
}
static content = {
search {
$('input', name: 'q')
}
searchButton {
$('button', name: 'btnG')
}
}
}
// GoogleSearchResultsPage.groovy:
class GoogleSearchResultsPage extends Page {
static at = {
title == 'gmail - Google Search'
}
static content = {
firstLink {
$('h3.r > a')[0]
}
}
}
// MyFirstGebSpec.groovy:
class MyFirstGebSpec extends GebSpec {
void 'we can get to the gmail signin page'() {
when:
to GoogleHomepage
search().value('gmail')
searchButton.click()
waitFor {
at(GoogleSearchResultsPage)
}
firstLink.click()
waitFor {
at(GmailLandingPage)
}
signinLink.click()
then:
at GmailLandingPage
}
}
When I run ./gradlew firefoxTest, I get the following build error:
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy
:processTestResources
:testClasses
:firefoxTest
sandbox.geb.MyFirstGebSpec > we can get to the gmail signin page FAILED
org.openqa.selenium.ElementNotVisibleException at MyFirstGebSpec.groovy:38
1 test completed, 1 failed
:firefoxTest FAILED
FAILURE: Build failed with an exception.
When I look at the test report, I see an actual stacktrace:
org.openqa.selenium.ElementNotVisibleException: You may only interact with visible elements
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'BLAH', ip: 'BLAH', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_45' Driver info: driver.version: unknown
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.verifyCanInteractWithElement(HtmlUnitWebElement.java:282)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.click(HtmlUnitWebElement.java:142)
at geb.navigator.NonEmptyNavigator.click(NonEmptyNavigator.groovy:463)
at geb.content.TemplateDerivedPageContent.click(TemplateDerivedPageContent.groovy:73)
at sandbox.geb.MyFirstGebSpec.we can get to the gmail signin page(MyFirstGebSpec.groovy:38)
Obviously BLAH is not the actual value for my host/IP :-)
MyFirstGebSpec line 38 is this line:
searchButton.click()
It's interesting to me that I'm specifying Firefox as the driver but the HTMLUnit driver is somehow being selected. Perhaps I'm configuring something wrong and the default is HTMLUnit? Anybody know why this search button isn't visible? Thanks!