如何使用Geb框架获取/ html / head / title元素的文本?

时间:2014-01-23 11:10:18

标签: groovy automated-tests geb

使用Page Object模式,我想根据/ html / head / title元素的文本实现一些“at”验证。

如何获取标题文字?

我知道Geb不支持XPath表达式。

2 个答案:

答案 0 :(得分:5)

@Tim_Yates是对的,但您明确询问了Page Object模型。

您可以设置成功加载页面的规则,如下所示:

class GoogleHomePage extends Page {
  static url = "http://google.com/"
  static at = { title == "Google" }  // the bit you asked about
}

然后,你的实际测试:

Browser.drive {
  to GoogleHomePage // goes to GoogleHomePage and verifies by calling at(). 
}

(如果您不希望at()检查,请使用via()代替to()。)

答案 1 :(得分:1)

documentation显示:

Browser.drive {
    go "http://google.com/ncr"

    // make sure we actually got to the page
    assert title == "Google"

    ....
相关问题