问题
I have a test case like below:
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]
}
The test consists of two defs. I want to repeat the whole process with different ID and Password. How I can do that?
For example:
- 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"
I want to loop for all sets of ID and password.
EDITED: My Original code here:
@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
}
}
回答1:
Every public method in Spock is considered as separate test. If you want to compose many methods in one test, they should be private. You need to redesign the thing, for example: I have a test case like below:
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]
}
来源:https://stackoverflow.com/questions/39327603/spock-how-to-run-a-set-of-methods-as-a-single-test-repeatedly