2017-09-02 120 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

相关问题