Search code examples
seleniumframeworksresourcesrobotframework

Robot Framework : Keyword 'login_resources.Open Browser' expected 0 arguments, got 2


I am new to Robot framework and would like to practice it. I have encountered this error while trying Data driven testing. I think the problem is the resources but I don't know what's wrong. I have searched for some answers but none of it solved it.

Please help me. Below is my code.

login_resources.robot

    *** Settings ***
    Library     SeleniumLibrary

    *** Variables ***
    ${Login URL}        https://admin-demo.nopcommerce.com/login?returnurl=%2Fadmin%2F
    ${browser}      chrome

    *** Keywords ***
    Open Browser
        open browser    ${Login URL}      ${browser}
        maximize browser window

    Close Browsers
        close all browsers

    Open login page
        go to       ${Login URL}

    Input username
        [Arguments]     ${username}
        input text      id:Email      ${username}

    Input password
        [Arguments]     ${password}
        input text      id:Password     ${password}

    Click login button
        click element    xpath:/html/body/div[6]/div/div/div/div/div[2]/div[1]/div/form/div[3]/button

    Click logout button
        click link      Logout


    Error Message should be visible
        page should contain      Login was unsuccessful

    Dashboard page should be visible
        page should contain     Dashboard

DDT.robot

    *** Settings ***
    Library     SeleniumLibrary
    Resource    ../Resources/login_resources.robot
    Suite Setup     Open Browser
    Suite Teardown      Close Browsers
    Test Template       Invalid login


    *** Test Cases ***

    Right username empty password      [email protected]      ${EMPTY}
    Right username wrong password      [email protected]     xyx
    Wrong username right password      [email protected]       admin
    Wrong username empty password      [email protected]       ${EMPTY}
    Wrong username wrong password      [email protected]       xyx


    *** Keywords ***

    Invalid login
       [Arguments]     ${username}     ${password}
       Input username      ${username}
       Input password      ${password}
       Click login button
       Error Message should be visible

Solution

  • Robot framework is case insensitive. Now you have 2 keywords that are named open browser. One uses 0 arguments and the other 2. now you have to specifi the library when using the keyword.

    SeleniumLibrary.open browser
    

    Or use another name for your keyword Open Browser.