2017-09-02 126 views
0

我正在使用geb-spock。我試圖驗證頁面類的內容,在頁面本身,以便我只調用變量或函數。使用功能。我做了這樣的事情不能與頁面類內容中的框架一起使用

class BasePage extends Page { 
    static content = { 

     verifyheader { withFrame ("myFrame") { assert $("h1").text() == "Header1" } 

    } 
    } 
} 



    ... 

then: 
    to BasePage 
and: 
    verifyheader 

我得到一個錯誤,測試失敗和withFrame爲空。 這並不occuer當我把withFrame測試用例

then: 
    to BasePage 
    and: 
    withFrame('myFrame') {...} 

這完美地工作,但我期待在頁面類使用它。可能嗎?我怎麼去解決它?或換句話說,我的代碼有什麼問題

+0

你可以張貼堆棧跟蹤 –

回答

4

是的,內容定義中的withFrame調用返回null,因爲傳遞給它的塊中的最後一個語句是總是返回null的斷言。你不應該將內容定義的內部,而是在您的測試,而不是斷言:

class BasePage extends Page { 
    static content = { 
     headerText { withFrame("myFrame") { $("h1").text() } } 
    } 
} 

和:

when: 
    to BasePage 

then: 
    headerText == "Header1" 
+0

感謝您的回答 – eskoba

相關問題