【问题标题】:Why any Geb page method or module method can not be accessed in Where block为什么在 Where 块中无法访问任何 Geb 页面方法或模块方法
【发布时间】:2017-11-17 17:46:27
【问题描述】:

我有一个 Page 类并且有一些提取网页的方法。现在我想将这些方法调用到 Spock 的 Where 块中以作为数据提供者传递。但是当我调用该方法时,它会抛出一个错误,因为它没有找到它。但同样可以从 Where 块中访问。为什么会这样?

例子

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 块中访问,但是同样的方法在 when 或 then 块中是可以访问的。

我想了解一下场景背后的逻辑看起来,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 | groovy.lang.MissingPropertyException:无法将 getRowCount().size() 解析为 inca.sundashboard.pageobject.OverviewPage 的内容,或其导航器上下文中的属性。 getRowCount().size() 是您忘记导入的类吗? |

【问题讨论】:

  • 查看我对Leonard提到的问题的回复:stackoverflow.com/a/46971915/1856764
  • 我尝试了您提供的解决方案,但它并没有解决我面临的问题。当:“我在概览页面”在概览页面然后:“我应该所有文章的文章 id”getAllCountOf(articleInfo).size() == page."$actualCount" 其中:articleInfo |actualCount TopArticleListInfo.ARTICLE_THUMBNAIL |'getRowCount ()。尺寸()​​' 。这段代码不起作用。

标签: spock geb


【解决方案1】:

我在测试中使用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

}

【讨论】:

  • 这真的成功了。这就是我想要从数据表中传递动态方法的方法。非常感谢@Royg 的帮助。
猜你喜欢
  • 1970-01-01
  • 2013-11-23
  • 1970-01-01
  • 1970-01-01
  • 2014-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多