__init__.robot files of Robot Framework
Introduction
Example
In the article about Templates a similar test was considered
*** Settings *** Documentation Flasky App Login Data-driven Test with ... Arguments Embedded to Keyword Name and ... Named Columns Resource users/users.resource Suite Setup Setup Suite Test Tags ui login Test Template Providing ${username} and ${password} Title Should Be ${expected} *** Variables *** *** Keywords *** Create Unique User &{unique_user}= Generate Unique User Set Suite Variable ${unique_user} Setup Suite Create Unique User Register User user=${unique_user} # To reduce variable names two new # variables are created here ${VALID USER}= Set Variable ${unique_user.username} Set Suite Variable ${VALID USER} ${VALID PASSWD}= Set Variable ${unique_user.password} Set Suite Variable ${VALID PASSWD} Test Setup Tasks Start Chromium Browser Test Teardown Tasks Close Browser Providing ${username} and ${password} Title Should Be ${expected} Open Browser To Login Page Log ${username} Log ${password} Input Username ${username} Input Password ${password} Submit Credentials ${title}= Get Title Log ${title} Should Be Equal ${title} ${expected} *** Test Cases *** USERNAME PASSWORD EXPECTED TITLE Valid Credentials ${VALID USER} ${VALID PASSWD} User Information - Demo App Invalid User Name invalid ${VALID PASSWD} Login Failure - Demo App Invalid Password ${VALID USER} invalid Login Failure - Demo App Invalid User Name and Password invalid invalid Login Failure - Demo App Empty User Name ${EMPTY} ${VALID PASSWD} Log In - Demo App Empty Password ${VALID USER} ${EMPTY} Log In - Demo App Empty User Name and Password ${EMPTY} ${EMPTY} Log In - Demo App Empty User Name Invalid Password ${EMPTY} invalid Log In - Demo App Invalid User Name Empty Password invalid ${EMPTY} Log In - Demo App
If there are a lot of similar tests, it makes sense to separate common tags and Test Setup into a separate
__init__.robot
file.
If Sute Variables were used, then for their
availability
from files nested in the directory, you need to use
children=True
robot/ |-- tests | |-- __init__.robot | |-- invalid_login.robot | `-- valid_login.robot `-- resources |-- ui | `-- ui.resource `-- users `-- users.resource
*** Settings *** Documentation Flasky App Login and ... Registration Tests Resource ui/ui.resource Resource users/users.resource Suite Setup Setup Suite Test Tags ui *** Keywords *** Setup Suite Create Unique User Register User user=${unique_user} # To reduce variable names two new # variables are created here ${VALID USER}= Set Variable ${unique_user.username} Set Suite Variable ${VALID USER} children=True ${VALID PASSWD}= Set Variable ${unique_user.password} Set Suite Variable ${VALID PASSWD} children=True Create Unique User &{unique_user}= Generate Unique User Set Suite Variable ${unique_user} children=True Test Setup Tasks Start Chromium Browser Test Teardown Tasks Close Browser
Now you can write a suite test without some settings, and also with only one keyword - a template
*** Settings *** Resource users/users.resource Test Tags login Test Template Providing ${username} and ${password} Title Should Be ${expected} *** Variables *** *** Keywords *** Providing ${username} and ${password} Title Should Be ${expected} Open Browser To Login Page Log ${username} Log ${password} Input Username ${username} Input Password ${password} Submit Credentials ${title}= Get Title Log ${title} Should Be Equal ${title} ${expected} *** Test Cases *** USERNAME PASSWORD EXPECTED TITLE Valid Credentials ${VALID USER} ${VALID PASSWD} User Information - Demo App Invalid User Name invalid ${VALID PASSWD} Login Failure - Demo App Empty User Name and Password ${EMPTY} ${EMPTY} Log In - Demo App Empty User Name Invalid Password ${EMPTY} invalid Log In - Demo App
| Robot Framework | |
| Architecture | |
| Logs | |
| __init__.robot | |
| Create custom .py libs | |
| Path to libs and resources | |
| Keyword as decorator | |
| Template | |
| Parametrize | |
| Demo with pywinauto |