I am trying to implement the to() checker on the Page Object for the case when clicking a button may stay on the page if there is an error or go to a new page if there are no errors.
When I use a List to provide all the possible Page Classes only the first Page is at() checked and then the validation fails. It never checks the other Pages in the List. My implementation is almost exactly like the Geb Manual.
class LandingPage extends Page {
static at = { title == "Welcome" }
static content = {
loginBtn(to: [AccountPage, LandingPage]) { $("button", id: "login") }
}
class AccountPage extends Page {
static at = { title == "My Account" }
static content = {
// Page Contents
}
class LoginTest() extends GebReportingTest {
@Test
public void checkErrorDisplayed() {
to LandingPage
loginBtn.click()
}
}
In the example above the browser goes to the Landing Page and when you click the button without any fields filled in it should display an error and remain on the LandingPage. But with the current implementation of LandingPage it attempts to do an at() check on AccountPage and then fails. If I switch the placement of [AccountPage, LandingPage] in the to() statement for loginBtn, then the negative test case will pass, but the good path will fail.
Any ideas?
http://www.gebish.org/manual/current/pages.html#to
EDIT: Including stack trace
title.contains("My Account")
| |
| false
Welcome
at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:398)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:646)
at com.website.pages.AccountPage$__clinit__closure1.doCall(AccountPage.groovy:10)
at com.website.pages.AccountPage$__clinit__closure1.doCall(AccountPage.groovy)
at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at geb.waiting.Wait.waitFor(Wait.groovy:117)
... 90 more