我有一个 Page 类,并且有一些提取网页的方法。现在我想将这些方法调用到 Spock 的Where block 中以作为数据提供者传递。但是当我调用该方法时,它会抛出错误,因为它没有找到它。但同样可以从Where block 之外访问。为什么会这样?
示例
def "Validate all article has its id"(){
when:"I am at Overview page"
at OverviewPage
then:"I should the article id of all article"
getAllCountOf(articleInfo).size() == actualCount
where:
articleInfo |actualCount
TopArticleListInfo.ARTICLE_THUMBNAIL |filter.getCount()
}
在上面的代码中,'filter.getCount()'无法从Where block 中访问,但在when或then block 中可以访问相同的方法。
我想了解场景背后的逻辑看起来,Where block 无法静态地找到这个方法,需要创建一个对象来调用它。
当我尝试erdi提供的解决方案时,但这也没有解决问题
when:"I am at Overview page"
at OverviewPage
then:"I should the article id of all article"
getAllCountOf(articleInfo).size() == page."$actualCount"
where:
articleInfo |actualCount
TopArticleListInfo.ARTICLE_THUMBNAIL |'getRowCount().size()'
这里 getRowCount().size() 替换为“$actualCount”。但它仍然抛出错误
错误消息
getAllCountOf(articleInfo).size() == page."$actualCount" | | | | | | | 10 | 10 groovy.lang.MissingPropertyException:无法将 getRowCount().size() 解析为 inca.sundashboard.pageobject.OverviewPage 的内容,或其导航器上下文上的属性。 getRowCount().size() 是您忘记导入的类吗? |
最佳答案
我正在使用Dynamic Method Names在我的测试中,这是一个小例子:
def "Validate all article has its id"(){
when: "I am at Overview page"
at OverviewPage
then: "I should the article id of all article"
getAllCountOf(articleInfo).size() == "$actualCountMethod"().getCount()
where:
articleInfo | actualCountMethod
TopArticleListInfo.ARTICLE_THUMBNAIL | filter
}
关于spock - 为什么在Where block 中无法访问任何Geb页面方法或模块方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47356484/