Geb to()不适用于Page List

时间:2014-04-21 19:13:18

标签: java testing groovy automated-tests geb

我正在尝试在页面对象上实现to()检查器,以便在出现错误时单击按钮可能会停留在页面上,或者如果没有错误则转到新页面。

当我使用List提供所有可能的页面类时,只检查第一页是否为(),然后验证失败。它永远不会检查列表中的其他页面。我的实现几乎与Geb手册完全一样。

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()
    }
}

在上面的示例中,浏览器转到目标网页,当您单击没有填写任何字段的按钮时,它应显示错误并保留在LandingPage上。但是对于LandingPage的当前实现,它尝试对AccountPage进行at()检查然后失败。如果我在loginBtn的to()语句中切换[AccountPage,LandingPage]的位置,那么负测试用例将通过,但好的路径将失败。

有什么想法吗?

http://www.gebish.org/manual/current/pages.html#to

编辑:包括堆栈跟踪

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

1 个答案:

答案 0 :(得分:0)

我不确定你是否可以在其中递归使用相同的类名(你在LandingPage类中做到了)。使用以下三个类,我相信它应该有效!

class LandingPage extends Page {
    static at = { title == "Welcome" }
    static content = {
        loginBtn(to: AccountPage) { $("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()
    }
}