使用Spock数据表来测试Geb页面对象 [英] Using Spock Data Tables to Test Geb Page Objects

查看:212
本文介绍了使用Spock数据表来测试Geb页面对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完全披露:我对Geb和Spock都很新。



作为我正在开发的测试套件的一部分,我们必须测试运行几个页面元素上的相同测试。我希望能够使用Spock数据表来抽象出这种行为。但是,当我这样做时,Geb抱怨说它不承认页面属性。



这是我正在谈论的一个简单的例子: / b>

  when:
textBox = value
submit()

then:值更新
在SuccessPage
textBox ==值

其中:
textBox |价值
box1 | val1
box2 | val2
box3 | val3

在这个例子中,框1-3被定义在内容这些测试在我独立执行时有效,但当我使用数据表时,这些测试不起作用。 。为什么Geb元素没有被正确地替换?

解决方案

数据表是在测试环境之外执行的,被指定。必须以这种方式执行它们才能知道如何基于它们实际构建测试的多个迭代。在这种情况下, box1 并不指向页面属性,因为您的浏览器尚未指向 SuccessPage



为了解决它,您需要使用内容名称(这将是 String 的实例)并将它们解析为当您处于正确的上下文中时,页面的属性:

  when:
page。$ textBox= value
submit()

then:value is updated
at SuccessPage
page。$ textBox== value

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


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?

解决方案

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

这篇关于使用Spock数据表来测试Geb页面对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆