问题
I have below code:
*** Settings ***
Library OperatingSystem
Library Process
Library String
Test Template My Run Test
*** Variables ***
@{MyList}= item items
*** Test Cases ***
#name type profile file test
[XXXXX_1] General test.out Profile mode.out
[Tags] TEST-XXXXX
*** Keywords ***
My Run Test
[Documentation] Run the suite
[Arguments] ${type} ${profile} ${file} ${test}
: FOR ${data} IN @{MyList}
\ When data is ready
\ And tool is ran
\ And get was success
\ And test suite config is updated
\ And testing tool is again run
\ Then publish test status
data is ready
Log to Console "Data is ready"
tool is ran
Log to Console "tool is ran"
Run Keyword And Return Stop Test "This is fun"
get was success
Log to Console "get was success"
test suite config is updated
Log to Console "test suite config is updated"
testing tool is again run
Log to Console "testing tool is again run"
publish test status
Log to Console "publish test status"
Stop Test
[Arguments] ${msg}
Log To Console ${msg}
Fail ${msg}
As per it I am running a set of keywords for all items in a list using for loop. Now I have a situation that for an item in list a evaluation failed and I have to mark that test as failure but want the test suite to continue with next items in list.
Hence assume there are 3 items in list and test case fails for 2 second item in list then code should return back to main for loop [not continue with other keyword for 2nd item] and start test case for 3rd item.
What I observer that using keyword Fail and others stops the whole test suite. Is there a way to achieve this?
回答1:
If you extract the for loop from the test template into the test case and use Templates with for loops, you could make the iterations independent from each other.
For example with the following modifications:
*** Test Cases ***
[XXXXX_1]
FOR ${data} IN @{MyList}
# list item type profile file test
${data} General test.out Profile mode.out
END
*** Keywords ***
My Run Test
[Documentation] Run the suite
[Arguments] ${data} ${type} ${profile} ${file} ${test}
When data is ready
And tool is ran
And get was success
And test suite config is updated
And testing tool is again run
Then publish test status
This would be the output:
来源:https://stackoverflow.com/questions/63543667/robotframework-for-loop-continue-with-next-test