Robot Framework

How to run a Skip Test in Robot Framework

Skip Test in Robot Framework

The Robot Framework Selenium library provides us with various keywords as well as various ways in which we can skip test. Sometimes skipping tests can play a crucial role in saving time. 

When there are certain types of errors in the given test case, which during execution may lead to many discrepancies, during this time we tend to skip the given test case to avoid further issues. 

In this Blog, we will discuss- 

  • Project setup to run Skip Tests 
  • Perform the Required actions on the Skip test 
  • Verify for the same 

NOTE: There are three ways of skipping any test, we will look at all ways in the coming sections. 

Project setup for Skip Test:

Firstly, we must install all prerequisite libraries in our project (for more info about prerequisites you can visit- https://www.neovasolutions.com/2022/07/21/robot-framework-automation-using-selenium-and-python/

To ensure that the required libraries are installed, use pip list command or manually navigate to: 

File > settings > project: robot-automation > python interpreter 

Project setup in skip test

After verifying the prerequisite part create a file SkipTest.robot in the TestCases directory.

— go to the new file > give a name of with .robot >Enter 

New File

Keywords: 

Commands available in Robot Framework in which we can Skip Test are as follows: 

  • Skip: Using this keyword we can skip the rest of the test. But if the test has Teardown met method it will run. 
  • Skip if: Skips the test only if the conditions are true. If Conditions are false, it runs the test. But if the test has Teardown met method it will run. 
  • Using Tags: Tags are generally used to associate a test with scenarios like a smoke test or regression test etc. Using this we can further perform actions like skip test. 

We will be looking into details of all these techniques in the coming sections. 

TestCase: 

Step1: We will create different test cases, each performing a different task. 

Step2: On a given TestCase perform skip action using the skip keyword. 

Step3: In the next step, we will perform conditional skip using ‘skip if’ keyword. 

Step4: Perform skip action in Terminal using exclude function of Tags. 

Step5: We will perform these actions using “robot -e tagname SkipTest.robot”. 

*** Settings ***
Library    SeleniumLibrary
*** Test Cases ***
TC1 open amazon
    [Tags]    ecommerce
     log to console    flipkart.com
TC2 open facebook
    [Tags]    social
     log to console    open facebook.com
TC3 open youtube
    [Tags]    social
    log to console    open instagram.com
TC4 open flipkart
     [Tags]    eCommerce
     log to console    amazon.in
TC5 skip method
    log to console    hello
    skip
TC5 skip if method
    skip if    "cat" == "cat"
    log to console    I'm skipped
*** Keywords ***

***Settings*** – To work with robot framework keywords we need to import the selenium library in the settings section because all these keywords are built in the selenium library-Library SeleniumLibrary

Similarly, we can import other libraries, resource files, and variable files as per our project requirement in this section. 

***Variables***– This section contains the defined variables that are used commonly, here we declared variables of browser and URL so we can reuse these variables.  

${url} ${browser} 

in the same way, we can create more variables like this according to the requirement of the project. 

***Test Cases*** 

Skip test code

Code Explanation: 

For Testing using skip method we just use skip keyword in the given test case and while execution it skips the test case and continues executing other test Cases. 

For skipping a test using conditional statements we use skip if keyword. We check this in our example by passing to the same keywords and verifying whether the test suite skips the test or not. 

For skipping a test case using Tags we will be having four different test cases with two different tags. One would be a social tag as the test case would contain social networking site addresses and the other would-be an e-commerce tag as the test cases would be containing the eCommerce site’s address. 

Note: Both skip and skip if are built-in functions used for skipping a test. 

In our current example, we would be using- 

                                      [Tags] social

                                      [Tags] eCommerce

Code Execution: 

In Order to execute the above code using Tags, we will be using the below command. 

                   robot -e social skiptest.robot 

To execute the Test case we need to use the below command. 

Code execution skip test

But now since we are excluding a test case, so we are using the –e keyword. 

–e followed by tag name, in our case the Tag Name is eCommerce since we only want this test case to exclude, so we use –e e-commerce. 

After execution, we should get the result as a pass 

Execution skip test

By running the Above Test Cases with the given Keywords, we will be able to skip eCommerce sites that is flipkart.com and amazon.com, and run other test cases. 

Report: 

Skiptest log
Skiptest report