我正在尝试 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/