DataDriver Robot Framework
Introduction
The DataDriver library is an extension for Robot Framework.
DataDriver creates new test cases based on a data file. You can use .csv, .xls or .xlsx files.
Documentation
Installation
python -m pip install robotframework-datadriver
Example
Let us go through the example from the official page.
We are offered the following code
*** 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}
And the content for the .csv file.
*** 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;
The authors forgot to mention that to run it in this form the .csv file must be named the same as the .robot
file.
Let us name the files datadriver_demo.robot
and datadriver_demo.csv
robot_data_driver_demo/ ├── datadriver_demo.csv └── datadriver_demo.robot
Nothing is said about the Default and UserData arguments either.
They can simply be removed
*** Settings *** Library DataDriver Test Template Login With User And Password *** Test Cases *** Login with user ${username} and password ${password} *** Keywords *** Login With User And Password [Arguments] ${username} ${password} Log Many ${username} ${password}
From the directory robot_data_driver_demo run
python -m robot .\datadriver_demo.robot
============================================================================== Datadriver Demo ============================================================================== Right user empty pass :: This is a test case documentation of the ... | PASS | ------------------------------------------------------------------------------ Right user wrong pass :: This test case has the Tags 2,3 and foo | PASS | ------------------------------------------------------------------------------ Login with user and password mode :: This test case has a generat... | PASS | ------------------------------------------------------------------------------ Login with user and password | PASS | ------------------------------------------------------------------------------ Login with user and password FooBar | PASS | ------------------------------------------------------------------------------ Login with user FooBar and password mode | PASS | ------------------------------------------------------------------------------ Login with user FooBar and password | PASS | ------------------------------------------------------------------------------ Login with user FooBar and password FooBar | PASS | ------------------------------------------------------------------------------ Datadriver Demo | PASS | 8 tests, 8 passed, 0 failed ==============================================================================
Test case name
The next interesting point is the test case name. If you replace it, for example, with Some Test, all the tests will still run.
The only difference will be a warning about identical test names.
*** Settings *** Library DataDriver Test Template Login With User And Password *** Test Cases *** Some Test *** Keywords *** Login With User And Password [Arguments] ${username} ${password} Log Many ${username} ${password}
python -m robot .\datadriver_demo.robot
============================================================================== Datadriver Demo ============================================================================== Right user empty pass :: This is a test case documentation of the ... | PASS | ------------------------------------------------------------------------------ Right user wrong pass :: This test case has the Tags 2,3 and foo | PASS | ------------------------------------------------------------------------------ Some Test :: This test case has a generated name based on template... | PASS | ------------------------------------------------------------------------------ [ WARN ] Multiple tests with name 'Some Test' executed in suite 'Datadriver Demo'. Some Test | PASS | ------------------------------------------------------------------------------ [ WARN ] Multiple tests with name 'Some Test' executed in suite 'Datadriver Demo'. Some Test | PASS | ------------------------------------------------------------------------------ [ WARN ] Multiple tests with name 'Some Test' executed in suite 'Datadriver Demo'. Some Test | PASS | ------------------------------------------------------------------------------ [ WARN ] Multiple tests with name 'Some Test' executed in suite 'Datadriver Demo'. Some Test | PASS | ------------------------------------------------------------------------------ [ WARN ] Multiple tests with name 'Some Test' executed in suite 'Datadriver Demo'. Some Test | PASS | ------------------------------------------------------------------------------ Datadriver Demo | PASS | 8 tests, 8 passed, 0 failed ==============================================================================
The logs show that the test case name from the .csv file takes precedence over the base name in the .robot file.
Article author: Andrei Olegovich