You are pretty close! You can do the following to retrieve the count where h3 contains the word "ebay" and assert the correct number appear:
def "checking for word"() {
given: " Search for word 'ebay' in google"
go "https://www.google.pl/"
$("body").find("input", name: "q").value("ebay")
$("center").$("input", 0, name: "btnK").click()
waitFor { title.endsWith(" Szukaj w Google")}
then: "Correct results are show"
$("h3").count { it.text().toLowerCase().contains("ebay") } == 10
}
Note the toLowerCase() as most results return as "eBay" and won't match "ebay".
I'd recommending looking into page objects, and creating a GoogleHomePage and GoogleResultsPage something similar to:
import geb.Page
class GoogleHomePage extends Page {
static url = "http://www.google.com"
static at = {
logo.displayed
}
static content = {
logo { $("#hplogo") }
searchField { $("body").find("input", name: "q") }
searchButton { $("center").$("input", 0, name: "btnK") }
}
ResultsPage searchFor(String search) {
searchField.value(search)
searchButton.click()
browser.at(ResultsPage)
}
}
Results page:
import geb.Page
class ResultsPage extends Page {
static at = { title.endsWith(" Szukaj w Google") }
static content = {
results { $("h3") }
}
def countResultsContaining(String expectedResultPhrase) {
results.count { it.text().toLowerCase().contains(expectedResultPhrase) }
}
}
Then your test ends up looking a lot cleaner without all the selectors etc, and you have some reusable code for other tests:
class GoogleSpec extends GebReportingSpec {
def "checking for word"() {
given: " Search for word 'ebay' in google"
def searchPhrase = "ebay"
def googlePage = to GoogleHomePage
when: "I search for ebay"
def resultsPage = googlePage.searchFor(searchPhrase)
then: "Correct results are shown"
resultsPage.countResultsContaining(searchPhrase) == 10
}
}
As for resources, the Geb Manual is good, but Geb is written in Groovy - so searching for how to do it using Groovy rather than Geb will aid you.