Search code examples
robotframework

Variable '${username}' not found while using Robot Framework with DataDriver library


I'm new in Robot Framework, and now get stuck while using DataDriver library in my robot script.

My problem: There is a message : "Variable '${username}' not found." while I run the robot script and the test was FAIL.

This is my robot script:

*** Settings ***
Library  DataDriver  file=resources/user_password.csv  encoding=utf_8  dialect=unix
Test Template  Test Credential

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

*** Keywords ***
Test Credential
    [Arguments]     ${username}     ${password}
    Log  ${username}
    Log  ${password}

and this is my CSV file:

*** Test Cases ***, ${username}, ${password}, [Tags], [Documentation]
Valid user, user@mail.com, pass123, Positive, This is valid user credential
Invalid user, invalid@mail.com, pass123, Negative, This user is invalid
Invalid password, user@mail.com, pass, Negative, This password is invalid
Blank user, ${EMPTY}, pass123, Negative, Blank user
Blank password, user@mail.com, ${EMPTY}, Negative, Blank password
Blank user and password, ${EMPTY}, ${EMPTY}, Negative, Blank both user and password

Any help would be greatly appreciated. Thanks.

Welly


Solution

  • I think the problem is in:

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

    You're not passing any variables to the keyword as it's shown in the documentation for the DataDriver library: https://github.com/Snooz82/robotframework-datadriver#example-test-suite

    A solution would be to pass some values to the keyword:

    *** Test Cases ***
    Doing Test Credentials for ${username} and ${password}    secret-user    secret-pwd
    

    EDIT:

    Another is the format of your csv file. You include spaces after each comma, if I delete them:

    *** Test Cases ***,${username},${password},[Tags],[Documentation]
    Valid user,user@mail.com,pass123,Positive,This is valid user credential
    

    I can run it without any problems:

    enter image description here

    and the report:

    enter image description here