Print

Run Tests in Certain Order in Robot Framework Python

In robot framework, we may need to run tests in a certain order when tests are dependent on other tests in previous orders. Generally speaking, in a test suite, tests will run in the order by which they are created. However, for easily seeing the order of tests, users can prefix tests with numbers. See the example below.

 

Step 1: create a test project "Test Case Order" in robot framework IDE (RIDE) and create a new test suite "TestCaseOrder", and add test cases as listed in the picture below.

Text View of the test looks like this below

 

*** Test Cases ***
01__User-Registration-Test
    [Tags]    OrderTest
    Log    User Registration Test
    Log    User Registration Test is Over

02__Login-Test
    [Tags]    OrderTest
    Log    Login Test
    Log    Login Test is over

03__Change-User-Setting-Test
    [Tags]    OrderTest
    Log    Change User Setting Test
    Log    Change User Setting Test is over

04__Logout-Test
    [Tags]    OrderTest
    Log    Logout Test
    Log    Logout Test is over

Run the test and see the log

======================================================================================================================================
Test Case Order                                                                                                                       
======================================================================================================================================
Test Case Order.TestCaseOrder                                                                                                         
======================================================================================================================================
01__User-Registration-Test                                                                                                    | PASS |
--------------------------------------------------------------------------------------------------------------------------------------
02__Login-Test                                                                                                                | PASS |
--------------------------------------------------------------------------------------------------------------------------------------
03__Change-User-Setting-Test                                                                                                  | PASS |
--------------------------------------------------------------------------------------------------------------------------------------
04__Logout-Test                                                                                                               | PASS |
--------------------------------------------------------------------------------------------------------------------------------------
Test Case Order.TestCaseOrder                                                                                                 | PASS |
4 critical tests, 4 passed, 0 failed
4 tests total, 4 passed, 0 failed