Can robot framework be used as data driven as given way?

5,375 views
Skip to first unread message

Pratik Gajjar

unread,
Dec 29, 2011, 5:01:40 AM12/29/11
to robotframework-users
Currently I am working with one project which requires a lot of data
driven stuff. I used robot framework's data driven capability and I
found its interesting. but now I find its weird that my execution
tester(manual tester) is changing the test-script every time he
changes the data.

Now I have created custom library that contains functions that read
data from csv . The problem I am facing here is
I have to call these functions in my testcases. So the log file
consist of for loop constructs. And when the script get fails for one
of the data set, I have to navigate to the for loop iteration at which
it got failed and what data set was used.


My suggestion(and its requirement also :) ) is using the robot
framework as data driven which automatically takes one by one value
from csv and run the test case. It run as many times as there are rows
available in csv. In the report also there should be separate entry
for the same test case with each row-data as separate testcase. Can
there be some internal coding that hides data fetching process from
reports and log just like TestNG dataprovider capability.

one suggestion is can someone make use of [] construct aftere testcase
name to make the test case as data driven just like test template as
follows

*** Settings ***
Test Setup KW_Go_To_Login_Page
Library SeleniumLibrary

*** Test Cases ***

TC_Login_To_Application [DataDrivenTest] path=<path_to_csv>/
<path_to_xls_file> sheet=<sheet_name>

Input Text ${username_loc} ${user_name}
Input Text ${passwd_loc} ${password}
Click Button ${login_button_loc}

*** Keywords ***

KW_Go_To_Login_Page

###script to go to login page.....

so the above script will login to the application as many times as
there are entries into data file(csv) and make separate entry in
report file so that on failure we can figure out for which dataset it
got failed.

Please reply to this....

Pratik Gajjar

unread,
Dec 29, 2011, 5:03:53 AM12/29/11
to robotframework-users
One more thing.....variables used here as ${user_name} and ${password}
are the column name of the csv/xls file as "user_name" and "password".

king

unread,
Jul 7, 2012, 9:53:10 AM7/7/12
to robotframe...@googlegroups.com
Please reply to this.

Even I am also looking for a solution where in I can read from a csv file or xls sheet and run my test?

Regards

Pekka Klärck

unread,
Jul 7, 2012, 5:00:07 PM7/7/12
to hara.a...@gmail.com, robotframe...@googlegroups.com
2012/7/7 king <hara.a...@gmail.com>:
>
> Even I am also looking for a solution where in I can read from a csv file or
> xls sheet and run my test?

Did I get it right that you want to get data from external sources and
use it as variables? Probably the easiest solution would be using
variable files:
http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html#variable-files

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Pekka Nikander

unread,
Jul 9, 2012, 1:30:50 AM7/9/12
to hara.a...@gmail.com, robotframe...@googlegroups.com
I think it would make sense to create a tablib fixture for RF, allowing one to use tablib for reading and writing data.

http://docs.python-tablib.org/en/latest/index.html
https://github.com/kennethreitz/tablib

In addition to cvs files, that could also be used for reading the RF test cases "again", to provide access to other tables but the RF tables.

Here is the earlier discussion: https://groups.google.com/d/topic/robotframework-users/p51B4AeXOSo/discussion

I did some prototyping towards that direction (without tablib), designing some keywords etc. The code works (for reading ReST/HTML) but is somewhat ugly; however, if someone is interested please let me know and I'll share the code over e-mail.

--Pekka Nikander
> --
> You received this message because you are subscribed to the Google Groups "robotframework-users" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/robotframework-users/-/kPpZzarvZ0IJ.
> To post to this group, send email to robotframe...@googlegroups.com.
> To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.

Densil D'silva

unread,
Nov 20, 2013, 2:59:51 PM11/20/13
to robotframe...@googlegroups.com, hara.a...@gmail.com
Can you please provide the details.
would like to implement this in one of my project?

Thanks in Advance.
> To unsubscribe from this group, send email to robotframework-users+unsub...@googlegroups.com.

Denzie

unread,
Mar 25, 2014, 4:17:36 AM3/25/14
to robotframe...@googlegroups.com, hara.a...@gmail.com
I was able to solve the problem I was facing using a mix of Templates with for loops and custom keyword to read data from the spreadsheet/csv .

Thought of sharing the same as it could benefit others also.

First thing I did is to write a custom keyword in python to read data from file and return it as a 2 dimensional array (List of Lists).

import xlrd
import csv

def get_Data_From_Spreadsheet(fileName, sheetIndex): 
    workbook = xlrd.open_workbook(fileName)
    sheets= workbook.sheet_names()
    worksheet = workbook.sheet_by_index(0)
    rows = worksheet.nrows-1 
    cols = worksheet.ncols -1
    return _extractDataFromExcel(1, rows, 0, cols)    
def _extractDataFromExcel(rowStartIndex, rowEndIndex, colStartIndex, colEndIndex):
    curr_row = rowStartIndex
    while curr_row <= rowEndIndex:
         cur_col = colStartIndex
         dataRow =[]
         while cur_col <= colEndIndex:
             value = worksheet.cell_value(curr_row, cur_col)
             dataRow.append(value)
             cur_col+=1
         curr_row += 1
         testData.append(dataRow)
    return testData  

and the test case file looks like this

*** Settings ***
Library    Collections
Library    DataReader.py

*** Test Cases ***
Test data provider   
    [Template]   sample template
    [Setup]   prepare data
    :FOR  ${test}   in   @{testData}
    \    ${test}
    
*** Keywords ***
prepare data
    ${data}=   get Data From Spreadsheet    testData.xlsx
    Set Test Variable   ${testData}     ${data}          
    
sample template  [Arguments]    ${data}
    log   UserName :${data}

As you can see the template will be executed as many times as you have the data in the sample spreadsheet. you dont want to touch the testcase file if you want to include more test data. just put all your test data to the spreadsheet. and enjoy.

mind

unread,
Feb 18, 2015, 5:29:44 AM2/18/15
to robotframe...@googlegroups.com, hara.a...@gmail.com
Thanks a lot, U help me very much. I find this solution for my webs.
I can do now. I want input from excel (many fields) and put in web (many fields) by robotframework
 
Login.txt
 
*** Settings ***
Library    Selenium2Library
# Test Teardown    Close Browser
Resource    login_resource.txt
Library    DataReader.py
*** Variables ***
 ${file}  C:/testcase/test/run/testData.xlsx 
 ${sheet}  Login
*** Testcases ***
Test data provider  
    [Template]   Validate login
    [Setup]   prepare data
    :FOR  ${Username}  ${Password}  in   @{testData}
    \    ${Username}

*** Keywords ***
prepare data
    ${data}=   getDataFromSpreadsheet    ${file}   ${sheet}

    Set Test Variable   ${testData}     ${data}
Validate login
 [Arguments]    ${test}
 Visit to Login Page
 Input Correct Username and Password    ${username}    ${password}
 
login_resource.txt
*** Settings ***
Library     OperatingSystem
Library  Selenium2Library

*** Variable ***
${LOGIN_URL}    http://.....
*** Keywords ***
Visit to Login Page
 Set Environment Variable webdriver.chrome.driver /usr/local/bin/chromdriver
 Open browser ${LOGIN_URL} Chrome 
 Set Window Size  ${1280}  ${800}
Input Correct Username and Password
 [Arguments]    ${username}    ${password}
 Input Text    id=ctl00_ContentPlaceHolderBody_txtUsername    ${username}
 Input Password    id=ctl00_ContentPlaceHolderBody_txtPassword    ${password}
 Click Button    id=ContentPlaceHolderBody_btnLogin
 
DataReader.py
import xlrd

def getDataFromSpreadsheet(fileName, sheetname) :
    workbook = xlrd.open_workbook(fileName)
    worksheet = workbook.sheet_by_name(sheetname)
    print worksheet
    rowEndIndex = worksheet.nrows - 1
    colEndIndex = worksheet.ncols - 1
    rowStartIndex = 1
    colStartIndex = 0
    testData = []
    dataRow = []

    curr_row = rowStartIndex
    while curr_row <= rowEndIndex:
         cur_col = colStartIndex
         while cur_col <= colEndIndex:
             cell_type = worksheet.cell_type(curr_row, cur_col)

             value = worksheet.cell_value(curr_row, cur_col)
             dataRow.append(value)
             cur_col+=1
         curr_row += 1
         # testData.append(dataRow)
    # return testData 
    return dataRow

Ed Manlove

unread,
Feb 18, 2015, 10:22:35 AM2/18/15
to robotframe...@googlegroups.com
Note there is an ExcelLibrary, [most active version appears to be] https://github.com/NaviNet/robotframework-excellibrary, that has keywords for reading in from excel files. No need to reinvent the wheel as far as I can see.

Ed

To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.

To post to this group, send email to robotframe...@googlegroups.com.

Kyle Nolan

unread,
Nov 7, 2017, 2:14:30 PM11/7/17
to robotframework-users
This solution seems to report each iteration as a sub-item of the same testcase. 
Is there a way to report each of these iterations as a separate Testcase, as mentioned in the original post?

-Kyle

Pekka Klärck

unread,
Nov 8, 2017, 4:10:39 AM11/8/17
to ky...@wackygames.net, robotframework-users
Hello,

The solution below cannot be directly used if you want individual
tests. Test data files must have individual tests in them for Robot to
see multiple tests. I think the easiest solution is generating tests
data files based on your data before running tests.

Cheers,
.peke
> --
> You received this message because you are subscribed to the Google Groups
> "robotframework-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to robotframework-u...@googlegroups.com.
> To post to this group, send email to robotframe...@googlegroups.com.
> Visit this group at https://groups.google.com/group/robotframework-users.
>
> For more options, visit https://groups.google.com/d/optout.



vijay jadon

unread,
Nov 8, 2017, 4:19:15 AM11/8/17
to robotframework-users
Hi, I used the same code but getting error like "NameError: global name 'worksheet' is not defined" and trying to get data from XLS file


On Tuesday, March 25, 2014 at 4:17:36 AM UTC-4, Denzie wrote:

rajk...@mahathiinfotech.com

unread,
Oct 11, 2018, 12:28:05 PM10/11/18
to robotframework-users
Hi,

I am using jspringbot framework, Windows Authentication login username field only value is entered but password field value is not properly entered, it only entered one or two digit randomly.  Please give your valuable suggestion.

*** Settings ***
Resource ../selenium-resources.robot
Resource ../util-resources.robot
Resource ../form-resources.robot


Suite Setup Set Config And Test Data web


Test Teardown Test Tear Down

*** Variables ***


*** Test Cases ***
Test Case - Loginscreen
[Tags] Loginscreen
[Documentation] test new claim happypath
Sleep ${GENERIC_SLEEP_10S}
Enter Authentication rafig Sharp123

*** Settings ***
Library JSpringBotGlobal
Library String
Library Collections



*** Variables ***
${POLL_MILLIS} 500
${TIMEOUT_MILLIS} 10000
${MAX_RESULT_DISPLAY} 250
${REGEX_NUM} [0-9]+
${HTML_CODE_SYNTAX} &#


*** Keywords ***
Go To Login Page
[Documentation] go to login page
# open webpage
Navigate To $[config:test.claim.center.url]
Maximize Window


Regards,
Rajkumar .K



Bahubali Patil

unread,
Oct 12, 2018, 4:02:13 AM10/12/18
to robotframework-users
We've used the generic test data framework.

It is used on top of Robot Framework.
Here the test cases are generated automatically using the template.

The template have the test steps.
The test data is maintained in separate excel sheet.

Every time you update the excel sheet with new data/changes, the test cases can be generated in a fly and then executed.


More details refer to :: https://github.com/ThomasJaspers/Generic-Testdata-Framework

ishman

unread,
Oct 31, 2018, 3:34:30 AM10/31/18
to robotframework-users
Hi Peke,

Sorry to start on a older thread, but I recently started on Robot framework and I need something like this. More details here - https://groups.google.com/forum/#!topic/robotframework-users/k5yt57O4ibI

I like what you proposed - I think the easiest solution is generating tests data files based on your data before running tests. 

Is it possible to do this - 
1) If in the test suite file for a test case, lets say I find a custom Tag - Data Driven and it also has in another tag, Name of Variable to parametrise and in yet another tag, in multiple rows the values for the parametrised variables
 -  when I start the run with robot, I can intercept from test suites file only these test cases and generate a test case for each of parametrised row, remove the original data driven test (as its replaced) and then the execution starts.

This will be of much of help if its possible. Any pointer around this will be much appreciated!

Thanks,
Reply all
Reply to author
Forward
0 new messages