Skip to main content

DataDriven Tests

Using DataDriven Syntax in Robot Framework

DataDriven Syntax

Test Cases can be written in a data-driven style where test cases use only one higher-level keyword, that hides the actual test workflow. These tests are very useful when there is a need to test the same scenario with different input and/or output data.
The Test Template setting defines the Keyword which is executed for every test case.
The Test Cases section just contains

  • the Test Case Name
  • the arguments for the Keyword defined in the Test Template setting
*** Settings ***
Test Template Login with invalid credentials should fail

*** Test Cases *** USERNAME PASSWORD
Invalid User Name invalid ${VALID PASSWORD}
Invalid Password ${VALID USER} invalid
Invalid User Name and Password invalid invalid
Empty User Name ${EMPTY} ${VALID PASSWORD}
Empty Password ${VALID USER} ${EMPTY}
Empty User Name and Password ${EMPTY} ${EMPTY}

*** Keywords ***
Login with invalid credentials should fail
[Arguments] ${username} ${password}
Log Many ${username} ${password}
Let me run it

Using DataDriver Library

The DataDriver library is an extension for Robot Framework®.
DataDriver creates new test cases based on a Data-File that contains the data for Data-Driven Testing. These data file may be .csv , .xls or .xlsx files.
The DataDriver library is not included in the Robot Framework distribution, but it can be installed using pip.

pip install robotframework-datadriver

A simple Test Suite which logs the username and password from the CSV file.

*** Settings ***
Library DataDriver
Test Template Login With User And Password

*** Test Cases ***
Login with user ${username} and password ${password} Default UserData

*** Keywords ***
Login With User And Password
[Arguments] ${username} ${password}
Log Many ${username} ${password}

The CSV file contains the test data.

*** Test Cases ***;${username};${password};[Tags];[Documentation]
Right user empty pass;demo;${EMPTY};1;This is a test case documentation of the first one.
Right user wrong pass;demo;FooBar;2,3,foo;This test case has the Tags 2,3 and foo
;${EMPTY};mode;1,2,3,4;This test case has a generated name based on template name.
;${EMPTY};${EMPTY};;
;${EMPTY};FooBar;;
;FooBar;mode;foo,1;
;FooBar;${EMPTY};foo;
;FooBar;FooBar;foo,2;

Check the DataDriver Library repository for more information.

Let me run it