我想将所有用户数据保存到集合中,并让GEB对每组数据运行相同的测试。我在想这样的事情。
import geb.spock.GebReportingSpec
import spock.lang.*
class MyFirstTestSpec extends GebReportingSpec {
def setupSpec() {
def userData = //an array of hashes but if it work I really do not care what type of collection is used
}
def 'run app'() {
given:
to LoginPage
userName = 'MasterUser'
password = 'APassword'
login.click()
at HomePage
when:
userData.each{
to ProfilePage
first = it['first']
mi = it['mi']
last = it['last']
...... More data
}
then: 'did it work'
at ReviewPage
amount1 == it['amount1']
amount2 == it['amount12']
...... More checks
}
}
答案 0 :(得分:2)
您是否考虑过将userData移至其中:阻止?
import geb.spock.GebReportingSpec
import spock.lang.*
class MyFirstTestSpec extends GebReportingSpec {
def setupSpec() {
}
def 'run app'() {
given:
to LoginPage
userName = 'MasterUser'
password = 'APassword'
login.click()
at HomePage
when:
to ProfilePage
first = firstName
mi = midName
last = lastName
...... More data
then: 'did it work'
at ReviewPage
reviewFirstName == firstName
amount1 == amount1
amount2 == amount12
...... More checks
where:
firstName | midName | lastName | amount1 | amount12
Robert | John | Brown | 100 | 20
...more data
这种结构的唯一之处是登录过程需要为每次迭代触发。如果这不符合您的喜好,那么您可以使用 where:块并将给定的块移出 setupSpec()夹具方法。