我正在尝试GEB,并想调试示例中的静态代码块。我试图设置断点,但是我似乎无法检查静态内容块中使用的数据。
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进行调试的任何线索?
由于内容块正在使用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
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句