Data driven tests with Robot Framework

2+
Share

Data driven tests with Robot Framework


Driving the Automation Tests with Data is one of the main component of any Test Automation Framework. Data driven Tests in robot framework can be created in many ways and this blog will touch upon one of traditional way to do accomplish this task i.e. storing the data in external Microsoft Excel file.

User can store the test data in Microsoft Excel file and then can read the data form this file in the Robot Test. Here are the steps you need to perform to achieve this.


Pre-Requisite

  1. Python should be installed on the system.
  2. Pip Should be installed on the System.
  3. Robot Framework Should be installed on the system.

Install Robot Framework excellibrary

Open Command Prompt with Administrator rights and run following command to install Robot Framework Excel Library.

pip install robotframework-excellibrary


If Pip Install is blocked by your network then you have to manually download and install the package.

Please visit this blog to learn the installation of packages without PIP.

Note: If you are installing the package manually then you may have to install all the package dependencies manually.


Sample Code to Access Data from Excel Using Robot

Create one sample File Say Data.xls and store it in your system’s C Drive. So, file path should look like C:\Data.xls.

Add the data in the excel as mentioned in the following screenshot.

Make sure you are entering the data in the Col A and B.

Now Copy Paste following code in a Notepad and save it as excelTest.robot in “C:/RF” drive.

Note:Do not change the formatting while pasting code in the text file.

*** Settings ***

Library    ExcelLibrary

*** Test Cases ***

Get Excel Data

    Open Excel    c://Data.xls

    Log To Console    ${\n}   

    ${userName}=    Read Cell Data By Coordinates    Sheet1    0    1   

    Log To Console    ${\n}

    ${userPass}=    Read Cell Data By Coordinates    Sheet1    1    1

    Log To Console    User Name Is:${userName}

    Log To Console    User Pass is:${userPass}

 

In order to execute this test, open cmd prompt and run following commands

cd “c:/RF”

Robot excelTest.robot

Your Robot Test will execute and show you the values fetched from the excel in results as follows:

You can get all the Keyword documentation for the Excel Library at following location:

http://navinet.github.io/robotframework-excellibrary/ExcelLibrary-KeywordDocumentation.html

 

Related Posts

Post A Comment

Your email address will not be published. Required fields are marked *