Groovy can';不要在页面类内容中使用withFrame
我用的是geb spock。我试图验证页面类的内容,在页面本身中,这样我就可以调用变量或函数。使用函数。我做了这样的事Groovy can';不要在页面类内容中使用withFrame,groovy,automated-tests,spock,geb,Groovy,Automated Tests,Spock,Geb,我用的是geb spock。我试图验证页面类的内容,在页面本身中,这样我就可以调用变量或函数。使用函数。我做了这样的事 class BasePage extends Page { static content = { verifyheader { withFrame ("myFrame") { assert $("h1").text() == "Header1" } } } } ... then: to BasePage and:
class BasePage extends Page {
static content = {
verifyheader { withFrame ("myFrame") { assert $("h1").text() == "Header1" }
}
}
}
...
then:
to BasePage
and:
verifyheader
我收到一个错误,测试失败,withFrame为空。
当我将withFrame放入测试用例中时,不会发生这种情况
这非常有效,但我希望在page类中使用它。可能吗?我该怎么做呢?或者换句话说,我的代码有什么问题?是的,内容定义中的
withFrame
调用返回null,因为传递给它的块中的最后一条语句是一个始终返回null的断言。您不应在内容定义内断言,而应在测试中断言:
class BasePage extends Page {
static content = {
headerText { withFrame("myFrame") { $("h1").text() } }
}
}
以及:
是的,内容定义中的
withFrame
调用返回null,因为传递给它的块中的最后一条语句是一个始终返回null的断言。您不应在内容定义内断言,而应在测试中断言:
class BasePage extends Page {
static content = {
headerText { withFrame("myFrame") { $("h1").text() } }
}
}
以及:
你能把StackTrace贴出来吗?谢谢你的回答
when:
to BasePage
then:
headerText == "Header1"