I have a test request for executing some test cases multiple times in robotframework and have the test cases pass/fail status individually in report. Now I use for loop to execute but I get only one Pass/Fail status for all executions.
-
May be below link can hep you to some extent stackoverflow.com/questions/31311941/…pankaj mishra– pankaj mishra2018-03-22 05:35:17 +00:00Commented Mar 22, 2018 at 5:35
-
It's not test case status in the report, but the details of the test, if I want to count the pass number of the tests, I need to click each case for the details, it's inconvenient to do so.Qi Huaping– Qi Huaping2018-03-22 06:15:33 +00:00Commented Mar 22, 2018 at 6:15
-
You can use a small pre-run modifier to dynamically replicate the test cases the requested number of times. See my answer here.Adrian W– Adrian W2023-03-20 13:35:03 +00:00Commented Mar 20, 2023 at 13:35
3 Answers
Robot-framework will look for matching tests in all of the provided paths, if you pass the same path more than once, robot will run the same test again.
For example, if you are running tests on the current folder, you can pass "." as many times as you want the test to run. Ex:
robot -t "*My test*" . . .
This command will run all tests that match the expression 3 times, and the report will contain all 3 executions and results.
Comments
To my knowledge there is now way to loop Test Cases therefore I assume you are using repeated execution of a Keyword within test case like:
Test case with loop assertion
:FOR ${var} IN RANGE 3
\ Click Element ${MY_BUTTON}
You will never see specific outcome of keywords in Report, only in the Log. You will need to produce Test Cases to see the outcome in Report.
For convenient generation of multiple same test cases (running same keyword) with different (or same) sets of data, you can use the data-driven approach
*** Settings ***
Test Template Click Element
*** Test Cases *** OBJECT LOCATOR
Click my button first time ${MY_BUTTON}
Click my button second time ${MY_BUTTON}
Click my button third time ${MY_BUTTON}
Of course the Tempate keyword can be custom one containing several libraries keywords.
Comments
You can repeat test cases as many times as you want--you just need to put the looping portion in the *** Test Cases *** section and move the tests into the *** Keywords *** section:
*** Keywords ***
Valid Login
Open Browser To Login Page
Input Username demo
Input Password mode
Submit Credentials
Welcome Page Should Be Open
*** Test Cases ***
Repeat many times test
FOR ${index} IN RANGE 20
Valid Login
END
It only produces one report at the end but you can get robot framework to stop execution on the first failing test using --exitonfailure
https://copyprogramming.com/howto/iterating-test-case-in-robot-framework
Also How to stop Robot Framework test execution if first testcase FAIL?