我对此处的导航器 API 使用的措辞感到有点困惑 http://www.gebish.org/manual/current/api/geb/navigator/Navigator.html
特别是,我对 .isDisplayed 方法感到困惑。
方法文档指出: “如果显示唯一的上下文元素,则返回 true;如果显示空导航器,则返回 false。无法在多元素导航器上调用。”
问题是如果我在空导航器上调用 .isDisplayed() 它不会返回 false。相反,它会抛出此错误:
table: geb.navigator.EmptyNavigator' is not present
它失败的行看起来像这样:
at SomePage //This page has a module element called "module"
if(module.table.isDiplayed()){ // module has a navigtor element called table
//do stuff
}
有问题的表元素确实不存在,因此表元素确实是一个空导航器,但根据文档,这意味着当我调用 .isDisplayed() 时,它应该返回 false,但它会抛出上述内容错误
这与调用 .isEmpty() 等模拟导航器方法时的情况相同 同样,如果在页面上找不到该元素,我希望 .isEmpty() 在从空元素调用时返回 true,但它会抛出 EmptyNavigator 异常。
什么给出了?
最佳答案
这是因为页面模块上的表格元素是必需元素(默认)。当您尝试使用所需的页面元素,但选择器返回空导航器时,geb 将抛出该异常。要解决此问题,您需要告诉 geb 该模块不是必需的:
class Module{
static content {
table(required: false) { /* selector here*/ }
}
}
现在,当您使用表格时,您将得到空导航器而不是异常。
关于jquery - Geb 在空导航器上使用导航器方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37617713/