2

I am trying to login to my application one by one using different credentials in robot framework-python-selenium but it is not working. Below is my code. Please suggest.

Open Browser  ${URL}   chrome
Input Text  id=username   ${user}
Input Text  id=password   ${password} 
${exp_row_count}    get element count   ${PATH_EXCEL}sheet1
${exp_row_count}    evaluate        ${exp_row_count}-1
For    ${i}    IN RANGE     1       ${exp_row_count}

*** Variables ***
${user}        ${i}
${password}    ${i}
${PATH_EXCEL}   C:\Users\TestLogin.xlsx
${i} 

enter image description here

1 Answer 1

3

I am not sure what the code you have there do as it is incomplete.

So assuming that you want to do data driven testing, use RobotFramework-datadriver: Structure of data file.

Installation:

pip install --upgrade robotframework-datadriver
pip install --upgrade robotframework-datadriver[XLS]

Create the excell sheet 1.xlsx and keep it in the same directory as .robot file

enter image description here

Now use below robot file:

*** Settings ***
Documentation   This is the script for Create Sales Visit Repository
Library     SeleniumLibrary
Library    DataDriver    file=1.xlsx    sheet_name=Sheet1
Test Template   Run Data Driven Steps

*** Test Case ***
Test Case 1 :Test behavior for Login    temp    temp
    

*** Keywords ***
Run Data Driven Steps
    [Arguments]    ${name}    ${age}
    Log     ${name}
    Log     ${age}
    

Explanation:

Robotframework uses Test Template for data driven testing , datadriver leverages this to drive the test using data from excel or csv than hard coding it in test step.

Library DataDriver file=1.xlsx sheet_name=Sheet1 initialise the data drver with the xlsx file in which we have the data.

Test Template Run Data Driven Steps tells robot that the testcase in suite uses the keyword 'Run Data Driven Steps' as the template. So we defines the test step inside this keyword and not the actual Test Case.

eg:

*** Keywords ***
Run Data Driven Steps
    [Arguments]    ${name}    ${age}
    Open ${url}
    Login using     ${1}
    Validate    a==b

Now in test case , we call a dummy test case just to trigger the test. The argument is also dummy. But as we say the template Run Data Driven Steps excepts two arguments we have to specify two dummy arguments to test case Any test name temp temp

Output:

Note: i used test name as

Test Case 1 :Test behavior for Login using ${name} and password ${age}

Thats why the data is being printed in the test name

enter image description here

9
  • Thanks! but where have you define the locator details like in my code (Input Text id=username ${user} Input Text id=password ${password} )
    – ADS KUL
    May 11, 2020 at 16:13
  • @ADSKUL everything inside the keyword run data ...
    – PDHide
    May 11, 2020 at 16:17
  • Change the key word to adapt your needs
    – PDHide
    May 11, 2020 at 16:28
  • Make sure first section after seeing is Test Case and then keyword and then variable
    – PDHide
    May 11, 2020 at 16:29
  • Everything I used same as your code and edit keywords section as below but getting error as 'geckodriver' executable needs to be in PATH. I am using chrome and that is already there in PATH. *** Keywords *** Run Data Driven Steps [Arguments] ${Username} ${Password} Open Browser ${url} chrome Input Text id=email ${Username} Input Text id=email ${Password *** Variables *** ${URL}
    – ADS KUL
    May 12, 2020 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.