Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Run Certain Tests With Tags in Robot Framework Python

An application may have a lot of modules to test. When your robot framework has many tests/suites, you may need to run certain tests as smoke tests or integration tests to save time or to test specific modules. In robot framework, tagging tests will enable you to pick certain tests to run. See the example below.

 

Step 1: create a test project "Test Case Order", add test suites "TestCaseOrder" and "TestCaseWithTags". In each test suite, add these test cases as shown in the picture below.

TestCaseOrder Suite includes these test cases

*** 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

TestCaseWithTags suite includes these test cases

 
*** Test Cases ***
User-Registration-Test
    [Tags]    Smoke Test
    Log    This is user registration test
    Log    User registration test is over

Login-Test
    [Tags]    Smoke Test
    Log    This is login test
    Log    Login test is over

Change-User-Setting-Test
    [Tags]    Integration
    Log    This is change user setting test
    Log    Change user setting test is over

Logout-Test
    [Tags]    Integration
    Log    This is logout test
    Log    Logout test is over

Step 2: Tag each test with a tag name. For example, we tag tests in TestCaseOrder suite with OrderTest

 01__User-Registration-Test

02__Login-Test

03__Change-User-Setting-Test

04__Logout-Test

Step 3: Tag each test with a tag name. For example, we tag tests in TestCaseWithTags

User-Registration-Test

Login-Test 

Change-User-Setting-Test

Logout-Test

 Step 4: run tests that have only the tag "OrderTest". See the result below. The four tests that have the tag "OrderTest" run and passed.

Run tests that have only the tag "Smoke Test". See the result. Only the tests with the tag "Smoke Test" run and passed.

Run tests that do not have the tags "OrderTest" and "Smoke Test". See the result. Only the tests with "Integration" tag run and passed. 

In summary, by using tag, we can group tests and define which tests to run.