0

嗨,我试图做一个 NavigationModule 来访问我在 geb.page 中的内容,但是当我想从此导航“模块”实例时,intellij 无法解决

class NavigationModule extends Module{
    static content = {
        homeLink { $("a", title:"Home") }
        contactLink { $("a", title:"Contact Us") }
    }
}

class HomePage extends Page{

    static url = "http://www.websitetest.com"
    static at={
        assert $("h1").text() == "Test website speed and performance"
    }
    static content = {
        navBar {module NavigationModule}
        //loginLink { $("a", text: "login")[0]}
    }
}

而且我也无法从我的脚本中访问

void test() {

    Browser.drive() {
        to HomePage
        navBar.
    }
}

有人知道会发生什么吗?我花了很多时间在谷歌搜索,但我没有找到任何东西

提前致谢

4

1 回答 1

1

Geb 文档 ( http://www.gebish.org/manual/current/ide-and-typing.html#strong_typing ) 建议明确定义类型以获得更好的 IDE 支持。

使用此示例代码完成对我有用。

class HomePage extends Page {

    static url = "http://www.websitetest.com"
    static at={
        assert $("h1").text() == "Test website speed and performance"
    }

    static content = {
        navBar {module NavigationModule}
        //loginLink { $("a", text: "login")[0]}
    }

    // explicitly define getter to give IntelliJ more type information
    NavigationModule getNav() {
        navBar
    }
} 

测试脚本:

void test() {

    Browser.drive() {
        // assign to page in order to have code completion on page
        page = to HomePage
        // code completin for homeLink works
        navBar.homeLink
    }
}
于 2014-12-10T21:38:52.947 回答