spock - 如何调试GEB Page模型中的静态代码块

标签 spock geb

我正在尝试 GEB,并想调试示例中的静态代码块。我尝试设置断点,但似乎无法检查静态内容 block 中使用的数据。

class GoogleResultsPage extends Page {
    static at = { results }
    static content = {
        results(wait: true) { $("li.g") }
        result { i -> results[i] }
        resultLink { i -> result(i).find("a.l")[0] }
        firstResultLink { resultLink(0) }
    }
}

关于如何使用 IntelliJ 等正常情况进行调试的任何线索?

最佳答案

由于内容 block 使用 DSL 并在编译时进行转换,我认为如果没有 IDE 的特殊支持,就不可能进行调试,但我希望有人能证明我错了。

我一直使用的方法是为核心内容之外的任何内容定义方法。这提供了一些好处,包括调试支持、编写测试时的 IDE 自动完成以及良好的重构支持。当然,缺点是代码稍微冗长,尽管对于我的目的来说,这种权衡是值得的。

以下是我可以如何执行 GoogleResultsPage:

class GoogleResultsPage extends Page {
    static at = { results }
    static content = {
        results(wait: true) { $("li.g") }
    }

    Navigator result(int i) { results[i] }

    Navigator resultLink(int i) { result(i).find("a.l")[0] }

    Navigator firstResultLink { resultLink(0) }
}

然后,在编写测试时,我使用了一种稍微更类型化的方法:

class MySpec extends GebReportingSpec {
    def "google search with keyword should have a first result"() {
        given:
        GoogleHomePage homePage = to(GoogleHomePage)

        when:
        homePage.search("keyword")

        then:
        GoogleResultsPage resultsPage = at(GoogleResultsPage)
        resultsPage.result(0).displayed
    }
}

关于spock - 如何调试GEB Page模型中的静态代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24283149/

相关文章:

spring - @SpringBootTest : Context not loading and Spock unable to @Autowire 的问题

Grails - 使用命名编码器的单元测试 Controller

grails - 使用Spock测试在Grails中触发了beforeUpdate或beforeInsert

java - 无法在IntelliJ中调试Spock测试

grails - 使用Geb维护测试之间的 session

Grails IntegrationSpec IllegalStateException

macos - 无法在 Mac 上创建谷歌浏览器驱动程序进行 Geb 测试

Grails 功能测试 Geb 页面对象模块不起作用 没有方法签名

testing - Spock:如何在数据管道中输入字符串值

grails - 对地址栏中直接插入的链接进行Geb测试