Run a single test in loop in Robot Framework

I have a csv file containing the test-data as follows:

# Case, StartTime, EndTime, ExpectedResult
Case_1, 2018-01-11T00:10:00, 2018-01-11T00:58:00, 2.5
Case_2, 2018-01-11T00:15:00, 2018-01-11T00:54:00, 3.2
Case_3, 2018-01-11T00:18:00, 2018-01-11T00:47:00, 4.5

Using robot framework I have added a keyword to read the file's content as follows:

Read Data File
    ${LIST}=  Process Data File  session_data.csv    
    : FOR    ${LINE}    IN    @{LIST}
        \    Log    ${LINE}
        \    @{COLUMNS}=    Split String    ${LINE}    separator=,
        \    ${TESTCASE}=    Get From List    ${COLUMNS}    0
        \    Log    ${TESTCASE}

I have created a test "Verify Result" to process data from CSV and verify the expected result, but all the process is considered as only one test-case.

For every single row in the CSV file I need to create a single test-case for example as follows:

Verify Result for Case_1
Verify Result for Case_3
Verify Result for Case_3
and so on...

Please provide suggestion on how to run a single test in a loop in Robot Framework.

3 answers

  • answered 2018-01-12 07:21 that_techgirl

    you can convert your testcase into a keyword and run it inside a loop in your test case. values can be changed by taking input from CSV with every run

  • answered 2018-01-12 07:21 pankaj mishra

    As suggested by Psytho , Test Template could be a solution for your question .

    Here is a basic example to give u a direction

    *** Settings ***
    *** Test Cases ***
    Look for All Possible Outputs from the System Under Test
        [Template]    Look for Specific Output
       csv1     #These rows are treated as arguments for test cases with [Template]
       csv2     # You can put your list variable as well, i have not checked with list
    *** Keywords ***
    Look For Specific Output
        [Arguments]    ${output}
        Comment    Pretending to look for a specific output...
        Log    ${output}   # 

    Test case would be run three times.

  • answered 2018-01-12 07:21 Bryan Oakley

    Unfortunately, what you want to do can't be done. Robot isn't designed to treat test data in an external file as separate test cases.

    What you can do instead is write a script that reads your .csv file and converts it to a series of robot test cases before you run the test. Then, you can run this generated test suite.