Search code examples
robotframework

Variable '${username1}' not found Variable 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 '${username1}' not found." while I run the robot script and the test was FAIL.

My script:

*** Test Cases ***
Login with user ${username} and password ${password}        xyc     123456



*** Keywords ***
Validate Unsuccessful Login
    [Arguments]     ${username1}        ${password1}
    open the browser with the Mortgage payment url
    Fill the login Form     ${username1}        ${password1}
    wait until it checks and display error message
    verify error message is correct
Fill the login Form
    [Arguments]         ${username1}        ${password1}
    input text          id:username          ${username1}
    input password      id:password          ${password1}
    select checkbox     id:terms
    click button        signInBtn

Error:

testDemo5 :: To validate the login form                                       
==============================================================================
Invalidusername,nina,learning                                         | FAIL |
Variable '${username1}' not found.
------------------------------------------------------------------------------
Invalidpassword,rahulshetty,nina                                      | FAIL |
Variable '${username1}' not found.
------------------------------------------------------------------------------
Specialcharacter,@#$##,uqyuyw                                         | FAIL |

Any help would be greatly appreciated. Thanks.


Solution

  • The error Variable '${username1}' not found. could be caused by one or more of the following reasons:

    1. The CSV file uses commas in the header instead of semi colons
    2. There are spaces in the CSV headers
    3. The arguments within the template keyword don't match up with the embedded variables in the test case.

    It looks like issue 3 is definately the case in your code so you would need to change your Validate Unsuccessful Login to the following:

    Validate Unsuccessful Login
        [Arguments]     ${username}        ${password}
        open the browser with the Mortgage payment url
        Fill the login Form     ${username}        ${password}
        wait until it checks and display error message
        verify error message is correct
    

    Then inspect your csv file

    This style is valid:

    *** Test Cases ***;${username};${password};[Tags];[Documentation]
    

    This style causes the error:

    *** Test Cases ***,${username},${password},[Tags],[Documentation]
    

    And this also cause the error:

    *** Test Cases ***; ${username}; ${password}; [Tags]; [Documentation]