I've just started reading and trying some Geb
0.12.2 examples and it's documentation (http://www.gebish.org/manual/current) and need help to understand why these asserts are failing.
My first try was with a webapp that redirect to our IDP to log in and if it's succesful login, then redirects you to the private webapp content.
I've been failing with this example and decided to try the simplest example (I was also using Spok, login module for reuse and Spec definitions) I could do to better understand what's happening (I'm also an Eclipse user and I've switched to IntelliJ for this scenario).
Assert 2 and 3 are failing because empty value is compared against my expected title:
package pages
import geb.Browser
import geb.Page
class GooglePage extends Page {
static url = "http://www.google.com/"
static content = {
heading { $("title").text() }
}
static at = {
title == "Google" //1
$('title').text() == "Google" //2
heading == "Google" //3
}
}
Browser.drive{
to GooglePage
}
Output of //2 assert failing:
Caught: Assertion failed:
$('title').text() == "Google"
| | |
| "" false
[[[FirefoxDriver: firefox on WINDOWS (2c4f1f19-b4fc-4f1f-bb39-9e0e2459da58)] -> css selector: title]]
Output //3 assert failing:
Caught: Assertion failed:
heading == "Google" //3
| |
"" false
Only the first assert is true, that's the built-in title attribute. According to documentation http://www.gebish.org/manual/current/#at-checker there are several methods to retrieve the title's value, but seems I'm using it incorrectly.
Same fails with chromeTest, firefoxTest or phantomJS or running from IntelliJ or gradlew via command line). I've re-readed some documentation parts, but the more I read the less I understand.
What's what I'm missunderstanding or missing?
Thanks.
You can only get the value of the title via the title
property of the Page
class, which you do in //1
. You cannot select the <title>
element using $()
selectors and this is a limitation of WebDriver - that's why WebDriver.getTitle()
is there and Page.getTitle()
delegates to it (as per it's javadoc).
Can you please point me at exactly which part of http://www.gebish.org/manual/current/#at-checker made you believe that there are several ways of getting the title? I personally don't think that section makes such statement but if it does then we should fix it.