Data Driven Test using RobotFramework

2,913 views
Skip to first unread message

Nelson Ramos

unread,
Oct 24, 2013, 4:05:33 PM10/24/13
to robotframe...@googlegroups.com
Hi There  (I´m pretty new here)

I have read a few documents on how to effectively use and apply Data Driven test usin Robot  but I´m struggling to get thins to work.

Can someone provided me with a step by step procedure process to correctly overcome this?

I have created an xls file initially with data I intended to inject into my project, but I dunno know how to make robot import and read from that external file.

The intention is to read from the external file in a loop cycle.

Can someone help? 

Thank you in advance!

Florian Heine

unread,
Oct 25, 2013, 4:02:51 AM10/25/13
to robotframe...@googlegroups.com
Hello,

Robot framework support data driven testing directly. Using that functionality will make your test much easier to understand and maintain as everything will be in one place rather that having to rely on external files.

You can see it in the documentation:


Basically you create a Keyword which takes all you pieces of test data as arguments, you the create a Test Case in the following format

<Test Case Name>
       | [Template]       |   <your keyword>
       | <line 1, data item 1> | <line 1, data item 2> | <line 1, data item 3> | ...
       | <line 2, data item 1> | <line 2, data item 2> | <line 2, data item 3> | ...
       | <line 3, data item 1> | <line 3, data item 2> | <line 3, data item 3> | ...
       ....

Florian Heine

unread,
Oct 25, 2013, 9:05:44 AM10/25/13
to robotframe...@googlegroups.com
Hello,

You sent me a private message, but for the benefit of everybody else, below is a complete example. The important thing to note is that there is no FOR loop. Robot framework iterates over the test cases automatically and gives you a pass or fail for every test case in your set of test cases, depending on the passing or failing of the Test System keyword.

Hope that makes this a little clearer.

Florian

*** Test Cases ***
All test cases
    [Template]    Test System
    3    4    7    # Test Case 1
    45    55    100    # Test Case 2
    34    5    40    # Test Case 3
    5    5    10    # Test Case 4

*** Keywords ***
Test System
    [Arguments]    ${input_1}    ${input_2}    ${expected}
    ${result}=    Do something complicated    ${input_1}    ${input_2}
    Run Keyword If    '${result}'!='${expected}'    Fail    There is a problem

Do something complicated
    [Arguments]    ${input_1}    ${input_2}
    ${result}=    Evaluate    ${input_1}+${input_2}
    [Return]    ${result}

mr

unread,
Oct 27, 2013, 1:13:04 AM10/27/13
to robotframe...@googlegroups.com
Thanks for the illustrative example!

I have one more question which deals with data-driven testing:

I there a possibility to mix the data-driven style with behavior-driven style? What I mean is to write one behavior-driven style test case and populate it with data sets.

Laurent Bristiel

unread,
Oct 28, 2013, 6:06:26 AM10/28/13
to robotframe...@googlegroups.com
Hello,

you can not use both test case styles (BDD and Data Driven) in the same tests.

As for your initial question:

> I have created an xls file initially with data I intended to inject into my project, but I dunno know how to make robot import and read from that external file.
I used Excel document as data-source with Robot Framework in a previous company.
It worked well using the OpenPYXL libary.
There are some more informations about hat in a recent blog post I wrote:
http://laurent.bristiel.com/robot-framework-and-excel/
This is no step-by-step though... once you are able, to read XLS from Robot, up to you do decide how to use that data with other keywords:
${data} =  read input data from excel
do some tests on the data  ${data}


Hope this helps,
Laurent

bm.gur...@gmail.com

unread,
Oct 28, 2013, 12:17:26 PM10/28/13
to robotframe...@googlegroups.com
https://bitbucket.org/robotframework/robotdemo/downloads

Download this zip file and execute using RIDE..You can understand what is exactly difference between among them..more informative...and easier
Reply all
Reply to author
Forward
0 new messages