3

Problem Statement: I want to have 1 robot file with 3 Test cases

  1. 1st test case would not use any Test Template
  2. 2nd test case would use a Test Template using Variables in 'Variables' section so as to iterate same template with multiple data sets
  3. 3rd test case would use csv file to read the data and iterate a test case

From above having 1 & 2 is working fine. But when it comes to combining 3 with 1 & 2. Only 3rd test case runs and others gets skipped. Also, I was getting this error in trying to achieve same. DataDriver error while running the script

This seems to be probably due to this https://github.com/Snooz82/robotframework-datadriver#structure-of-test-suite

So the problem is if I have 100 test cases which I want to use with a csv file. I need to use 100 robot files.. Is there some workaround for it ?

*** Settings ***
Library         RequestsLibrary
Library         Collections
Library         SeleniumLibrary
Resource        ../configapi/api_config.robot
Library         DataDriver      ../data/testdata/login.csv

# Header Labels just in front of *** Test Cases ***  is just a represenation, test would run perfectly fine even without it
# Eg:     *** Test Cases ***            USERNAME        PASSWORD        STATUSCODE
# Refer more here https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-templates

*** Test Cases ***
Read valid username and password from csv  
    [Template] Login Cases CSV
 
Both Username and Password are empty       ${EMPTY}     ${EMPTY}        400
    [Template]  Login Cases

Valid Username and Invalid Password        ${username}      dummypassword      400
    [Template]  Login Cases

Valid Username and Empty Password          ${username}   ${EMPTY}       400
    [Template]  Login Cases

Empty Username and Valid Password          ${EMPTY}     dummypassword        400
    [Template]  Login Cases

# Below Test case is just for represenational purpose to showcase even if Test Template is being used multiple tests can written in the same file.
# This will be removed in the future.
Successful Login
   Create Session    loginsession  url=${base_url}     verify=true
   ${data}     Create dictionary   grant_type=password     username=${username}  password=${password}
   ${headers}  Create Dictionary     Content-Type=application/x-www-form-urlencoded     authorization=${authorization}
   ${resp}     POST On Session    loginsession     /oauth/token  params=${data}  headers=${headers}
   log to console       ${resp.json}
   log to console       ${resp.content}
   Status Should Be     200  ${resp}


*** Keywords ***
Login Cases
    [Arguments]    ${username}      ${password}     ${status}
    Create Session    loginsession  url=${base_url}     verify=true
    ${data}     Create dictionary   grant_type=password     username=${username}  password=${password}
    ${headers}  Create Dictionary    Content-Type=application/x-www-form-urlencoded     authorization=${authorization}
    ${resp}     POST On Session    loginsession     /oauth/token  params=${data}  headers=${headers}        expected_status=${status}

Login Cases CSV
[Arguments]    ${username_csv}      ${password_csv}     ${statuscode_csv}
Create Session    loginsession  url=${base_url}     verify=true
${data}     Create dictionary   grant_type=password     username=${username_csv}  password=${password_csv}
${headers}  Create Dictionary    Content-Type=application/x-www-form-urlencoded     authorization=${authorization}
${resp}     POST On Session    loginsession     /oauth/token  params=${data}  headers=${headers}        expected_status=${statuscode_csv}
Manish Arya
  • 113
  • 1
  • 7

0 Answers0