我有一个如下测试用例:
def "Go to home page and click login button and go to login page"
{
}
def "Input user ID and password and click login"
{
when:
code....
then:
code....
where:
param1 << [ID1,ID2,ID3]
param2 << [password1,password2,password3]
}
测试由两个defs组成。 我想用不同的ID和密码重复整个过程。 我怎么能这样做?
例如:
- First execute def "Go to home page and click login button and go to login page"
- Than execute def "Input user ID and password and click login"
我想循环访问所有ID和密码集。
EDITED: 我的原始代码在这里:
@Stepwise
class AOSearchPageTest extends GebReportingSpec
{
@Shared def orig_list = ['東京(成田・羽田)', '日本','アジア' ]
@Shared def dest_list = ['ソウル', '韓国','アジア' ]
def "Select origin"()
{
when: "Clicking international radio button"
"Open Homepage"()
"Click oneWayRadioButton"()
then: "Select departure point"
code ...
and: "Select destination point"
code...
and:
"Select departure date"()
"Click searchButton"()
"Select product details"()
"Member login"()
"Input detail page"()
where:
area | country | port | dest_area | dest_country | dest_port
'アジア' | '日本' | '東京(成田・羽田)' | 'アジア' | '韓国' | 'ソウル'
'ヨーロッパ' | 'イギリス' | 'ロンドン' | 'ヨーロッパ' | 'イタリア' | 'フィレンツェ'
}
private "Open Homepage"()
{
same like above functions
}
private "Click oneWayRadioButton"()
{
same like above functions
}
private "Select departure date"()
{
when: "Clicking search button"
...
then: "Click Login Button"
...
}
private "Click searchButton"()
{
when: "Clicking search button"
...
then: "Click Login Button"
...
}
private "Select product details"()
{
same like above functions
}
private "Member login"()
{
same like above functions
}
private "Input detail page"()
{
same like above functions
}
}
答案 0 :(得分:0)
Spock中的每个公共方法都被视为单独的测试。如果你想在一次测试中组合很多方法,它们应该是私有的。你需要重新设计这个东西,例如: 我有一个如下测试用例:
private "Go to home page and click login button and go to login page"
{
}
private "Input user ID and password and click login"
{
}
def "Name of the entire test"
{
when:
"Go to home page and click login button and go to login page"()
"Input user ID and password and click login"()
then:
code....
where:
param1 << [ID1,ID2,ID3]
param2 << [password1,password2,password3]
}