Using Spock Data Tables to Test Geb Page Objects

 ̄綄美尐妖づ 提交于 2019-12-12 04:19:42

问题


Full Disclosure: I'm very new to both Geb and Spock.

As part of a test suite I'm working on, we have to test run the same test on several page elements. I would love to be able to abstract this behavior using a Spock data-table. However, when I do this, Geb complains that it doesn't recognize the page property.

Here is a bare-bones example of what I'm talking about:

when:
textBox = value
submit()

then:"value is updated"
at SuccessPage
textBox == value

where:
textBox | value
box1    | val1
box2    | val2
box3    | val3

In this example, boxes 1-3 are defined in the content object of a Page.

These tests work when I do them independently, but not when I use a data table. Why isn't the Geb element getting substituted correctly?


回答1:


Data tables are executed outside of the context of the test for which they are specified. They have to be executed that way to know how to actually construct multiple iterations of your test based on them. In that context box1 does not point to a page property as you're browser is not yet pointing at SuccessPage.

To get around it you will need to use content names (which will be instances of String) and resolve them as properties of the page when you are in the right context:

when:
page."$textBox" = value
submit()

then:"value is updated"
at SuccessPage
page."$textBox" == value

where:
textBox | value
'box1'  | val1
'box2'  | val2
'box3'  | val3


来源:https://stackoverflow.com/questions/46960922/using-spock-data-tables-to-test-geb-page-objects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!