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

Tom*_*nos 3 groovy automated-tests geb

使用Page Object模式,我想基于/ html/head/title元素的文本实现一些"at"验证.

我如何获得标题文本?

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

ina*_*lus 5

@Tim_Yates是对的,但您特别询问了Page Object模型.

您为成功加载页面设置了规则,如下所示:

class GoogleHomePage extends Page {
  static url = "http://google.com/"
  static at = { title == "Google" }  // the bit you asked about
}
Run Code Online (Sandbox Code Playgroud)

然后,你的实际测试:

Browser.drive {
  to GoogleHomePage // goes to GoogleHomePage and verifies by calling at(). 
}
Run Code Online (Sandbox Code Playgroud)

(如果您不想at()检查,请使用via()而不是to().)