Home > database >  Robotframework datadriver library not able to find a variable from CSV file
Robotframework datadriver library not able to find a variable from CSV file

Time:02-22

I have a problem while trying to set up datadriver library with robot framework. I get to error that one of the variables is not found.

CSV File:

${username},${password}
[email protected],adm
[email protected],admin
[email protected],adm

DDT2_csv.robot:

*** Settings ***
Library     SeleniumLibrary
Library     DataDriver  ../testdata/TestData.csv    delimiter=,     encoding=utf-8
Resource    ../resources/login_resources.robot
Suite Setup     login_resources.open my browser
Suite Teardown  login_resources.close browsers
Test Template   Invalid Login


*** Test Cases ***
Doing Test Credentials for ${username} and ${password}  Default    UserData

*** Keywords ***
Invalid Login 
    [Arguments]     ${username}     ${password}
    input email  ${username}
    input password  ${password}
    click login button
    error message should be visible 

I am getting the below error:

==============================================================================
DDT2 csv                                                                      
==============================================================================
Doing Test Credentials for ${username} and ${password}                | FAIL |
Variable '${username}' not found.
------------------------------------------------------------------------------
[ WARN ] Multiple test cases with name 'Doing Test Credentials for ${username} and ${password}' executed in test suite 'DDT2 csv'.
Doing Test Credentials for ${username} and ${password}                | FAIL |
Variable '${username}' not found.
------------------------------------------------------------------------------
[ WARN ] Multiple test cases with name 'Doing Test Credentials for ${username} and ${password}' executed in test suite 'DDT2 csv'.
Doing Test Credentials for ${username} and ${password}                | FAIL |
Variable '${username}' not found.
------------------------------------------------------------------------------
DDT2 csv                                                              | FAIL |
3 tests, 0 passed, 3 failed
==============================================================================

Can anyone please help me out?

CodePudding user response:

I'm no expert on this library but it looks to me like the delimiter arg is overwritten by the default dialect settings and is remaining as ";" even when you try the override.

It could be worth trying arg dialect=excel as this defaults to ',' delimiter

https://github.com/Snooz82/robotframework-datadriver#file-encoding-and-csv-dialect

Example:

*** Settings ***
Library     SeleniumLibrary
Library     DataDriver  ../testdata/TestData.csv     dialect=excel    encoding=utf-8
Resource    ../resources/login_resources.robot
Suite Setup     login_resources.open my browser
Suite Teardown  login_resources.close browsers
Test Template   Invalid Login

*** Test Cases ***
Doing Test Credentials for ${username} and ${password}  Default    UserData

*** Keywords ***
Invalid Login 
    [Arguments]     ${username}     ${password}
    log to console  ${username}
    log to console  ${password}

You may also need *** Test Cases *** column in your csv as I believe it's a required column, something like below:

*** Test Cases ***,${username},${password}
Case1,[email protected],adm
Case2,[email protected],admin
Case3,[email protected],adm
  • Related