在空導航器上使用導航器方法的Geb

[英]Geb using Navigator Methods on empty Navigators


I am a little confused by the verbiage used for the navigator API found here http://www.gebish.org/manual/current/api/geb/navigator/Navigator.html

我對這里的導航器API使用的措辭感到有些困惑http://www.gebish.org/manual/current/api/geb/navigator/Navigator.html

In particualr, I am confused by the .isDisplayed Method.

特別是,我對.isDisplayed方法感到困惑。

The method documentation states: "Returns true if the sole context element is displayed or false for empty Navigators. Cannot be called on multi element Navigators."

方法文檔說明:“如果顯示唯一的上下文元素,則返回true;對於空的Navigators,返回false。無法在多元素導航器上調用。”

The problem is if I call .isDisplayed() on an empty navigator it does not return false. Instead it throws this error:

問題是如果我在空導航器上調用.isDisplayed()它不會返回false。相反,它會拋出此錯誤:

table: geb.navigator.EmptyNavigator' is not present

The line it fails at looks something like this:

它失敗的線看起來像這樣:

at SomePage //This page has a module element called "module"
if(module.table.isDiplayed()){ // module has a navigtor element called table
    //do stuff
}

The table element in question is indeed non-existant, so the table element is indeed an empty navigator, but according to the documentation that means that when I call .isDisplayed() it should return false but instead it throws the above mentioned error

有問題的表元素確實是不存在的,所以table元素確實是一個空的導航器,但根據文檔,這意味着當我調用.isDisplayed()時它應該返回false但是它會拋出上面提到的錯誤

this is the same case when calling simular navigator methods such as .isEmpty() again, if the the element is not found on the page I would expect .isEmpty() to return true when being called from the empty element, but instead it throws the EmptyNavigator exception.

再次調用諸如.isEmpty()之類的simular導航器方法時也是如此,如果在頁面上找不到該元素,我希望.isEmpty()在從空元素調用時返回true,而是拋出它EmptyNavigator異常。

What gives?

是什么賦予了?

1 个解决方案

#1


4  

This is because the table element on module on your page is a required element (which is default). When you try to use a required page element, but the selector returns an empty navigator, geb will throw that exception. To fix this, you want to tell geb that the module is not required:

這是因為頁面上模塊上的表元素是必需元素(默認情況下)。當您嘗試使用所需的頁面元素,但選擇器返回一個空導航器時,geb將拋出該異常。要解決此問題,您需要告訴geb該模塊不是必需的:

class Module{

  static content {
    table(required: false) { /* selector here*/ }
  }
}

Now when you use table, you will get the empty navigator back instead of the exception.

現在,當您使用表時,您將返回空導航器而不是異常。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/06/03/7209455703bbe38535954e46ddee44c8.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com