Data Driven Testing in Robot Framework
Technical Feed
Nisha T S May 22, 2018


A Short Introduction to Robot Framework

Robot Framework is a generic open-source test automation framework, that is suitable for both end-to-end acceptance testing and acceptance test-driven development (ATDD).
The test syntax for Robot Framework follows a tabular style and plain text format which makes writing test cases more user-friendly and easy to read. Therefore, Robot Framework was found to meet all the required requirements in testing. One of the other benefits of Robot Framework is that it is created in Python which can be implemented on all major platforms.
Among the other open-source tools, Robot Framework appears to be an example of the very few tools that support a multi-platform environment. The test data in Robot Framework is simple, easy-to-edit, so it’s convenient to store in any version of the control system.

Data Driven Testing in Robot Framework

What is Data-Driven Testing?

Data-Driven Testing is a test design and execution method where the test scripts read data from sources such as XLS, XML and CSV files rather than utilizing hard-coded values. This strategy allows the automation engineers to implement a single test script that can execute tests for all the test data in the table.
The tasks in testing services such as quality assurance sometimes require developers to examine how different “classes” of data will perform in the same test procedure.
A perfect example of this is when a user has to login with their email credentials to access a website. The general way to test this case scenario is to give a valid email and password and then click on the submit button. The expected result is that the user logins to the system under test but there are several negative testing scenarios that needs to be covered as well. Such as:

A) Valid email, invalid password = Error message 1

B) Valid email, blank password=Error message 2

C) Blank email, blank password= Error message 3

D) Unregistered email, valid password= Error message 4

The above scenarios would require a tester to create four different test cases and test each one of those cases individually. Since all the users are effectively following the same procedure, that is, submitting after providing the right email and password; the tester could loop through a series of data values in the same test case and keep track of which one passes the test and which one fails.

The Relevance Of Data-Driven Tests In Data Setup

Now that we’ve explored some of the ways data-driven tests can benefit in testing, there are other instances as well where data-driven tests are implemented in data setup.

For implementing data-driven tests in data setup, we could use the same concept of iterating through different data rows to do the setup. E.g. When the development team deploys a new instance of an application under test, Jenkins could be used to trigger a particular scenario. This scenario could be a data-driven process executed to register 100 new users into the system under test from an external file like CSV, JSON, or Excel. Therefore, whether you are doing a testing scenario or verifying the different types of users or whether you are doing a data set up, understanding how the robot framework can load up multiple rows of data from the file and process them through 1 test case is a great skill to have.

Here is a typical example of a test automation project that has three separate test cases for testing the negative condition

three separate test cases testing the negative condition

As you can see:

  1. In the first test case, unregistered users should be able to view the correct error message at login. 
  2. In the next test case, registered user logins with an invalid password should view the correct error message
  3. Finally, if a user is attempting to log in with a blank email and password, it should show the correct error message. 

Here you could see that the test cases do exactly the same test steps, but with different data in each one.

The repeated test steps here are:

  1. Navigate to Sign-in page
  2. Attempt a login with some credentials
  3. Verify that the error message displayed in the login page matches the message we would expect when we provide input data.

Also Read: How to successfully set up CI/CD in Robot Framework

Though we could test these scenarios in three different cases, a better approach would be to create a single test case that would say, a negative login scenario should produce correct error messages. This would further iterate through the different sets of the data for the same test step in the first test case. If one of them failed, we wouldn’t exit the test case and simply keep track of the test case and then move on to the next row of data.

Here is a sample program on how you could achieve this

Test case

test case 2

Execute the *.robot program and the HTML results can be viewed as below.

HTML for *.robot progra

Data-driven tests in robot allow you to view each test data as a separate test case in the log files.

Typically, the built-in method for getting data-driven results in robot framework are as follows

  1.      Create a keyword with the common step, either in the Tests file or the  keyword file
  2.      It has [Arguments] to catch test data
  3.      Add [Test Template] to the test case
  4.      Associates the keyword having common steps
  5.      Add data rows to the test case
  6.      These will be passed into keyword[Arguments]

Also Read: The Automation Challenges and Solutions in Robot Framework

Data-driven testing is a great alternative approach if your enterprise has huge volumes of data to be tested for the same scripts. At ThinkPalm, our test automation services ensure that the quality, reliability, and performance of your product or software is thoroughly verified before it is deployed.

Get In Touch With Us!

For a free consultation on Testing as a Service (TaaS), Software Testing Services or Test Automation Services.

Reduce testing time by 70% and ensure you deliver high-quality products!

Reduce testing time by 70% and ensure you deliver high-quality products!