Naming

Test suite names

Test case names

invalid_login_should_fail.txt

invalid_login_should_fail.txt

*** Test Cases ***
Login With Empty Password Should Fail
Login With Empty Username Should Fail
Login With Empty Username And Password Should Fail
Login With Invalid Username Should Fail
Login With Invalid Password Should Fail
Login With Invalid Username And Invalid Password Should Fail
*** Test Cases ***
Empty Password
Empty Username
Empty Username And Password
Invalid Username
Invalid Password
Invalid Username And Invalid Password

Keyword names

*** Keywords ***
Input Valid Username And Valid Password And Click Login Button
*** Keywords ***
Login With Valid Credentials

Naming setup and teardown

*** Settings ***
Test Setup   Login To System, Add User, Activate Alarms And Check Balance
*** Settings ***
Test Setup   Initialize System

Documentation

Test suite documentation

account_withdrawal.txt

account_withdrawal.txt

*** Settings ***
Documentation    Tests Account Withdrawal.
*** Settings ***
Documentation    Tests to verify that account withdrawals succeed and
...              fail correctly depending from users account balance
...              and account type dependent rules.
...              See http://internal.example.com/docs/abs.pdf
Metadata         Version    0.1

Test case documentation

valid_login.txt

valid_login.txt

*** Test Cases ***
Valid Login
  [Documentation]    Opens a browser to login url, inputs username
  ...                and password and checks the welcome page is open.
  ...                This is a smoke test. Created in iteration 3.
  Open Browser   ${URL}  ${BROWSER}
  Input Text     field1  ${UN11}
  Input Text     field2  ${PW11}
  Click Button   button_12
  Title Should Be  Welcome Page
  [Teardown]     Close Browser
*** Test Cases ***
Valid Login
  [Tags]  Iteration-3  Smoke
  Open Login Page
  Input Username    ${VALID USERNAME}
  Input Password    ${VALID PASSWORD}
  Submit Credentials
  Welcome Page Should Be Open
  [Teardown]   Close Browser

User keyword documentation

Test suite structure

Test case structure

Workflow tests

Data-driven tests

*** Settings ***
Test Template       Invalid Login
*** Test Cases ***  USERNAME            PASSWORD
Invalid Username    invalid             ${VALID PASSWORD}
Invalid Password    ${VALID USERNAME}   invalid
Invalid Both        invalid             invalid
Empty Username      ${EMPTY}            ${VALID PASSWORD}
Empty Password      ${VALID USERNAME}   ${EMPTY}
Empty Both          ${EMPTY}            ${EMPTY}
*** Keywords ***
Invalid Login
  [Arguments]   ${username}   ${password}
  Input Username    ${username}
  Input Password    ${password}
  Submit Credentials
  Error Page Should Be Open

User keywords

Variables

Variable naming

*** Variables ***
# URL for CI server. Override with your local server if run elsewhere.
${SERVER URL}        http://sre-12.example.com/
${BROWSER}           Actual value set dynamically at suite setup
*** Keywords ***
Title Should Begin With
  [Arguments]          ${beginning}
  ${title} =           Get Title
  Should Start With    ${title}   ${beginning}
Suite Setup
  ${BROWSER} =        Get Current Browser
  Set Suite Variable  ${BROWSER}

Passing and returning values

valid_login.txt

valid_login.txt

*** Test Cases ***
Withdraw From Account
  ${status} =   Withdraw From Account    $50
  Withdraw Should Have Succeeded     ${status}
*** Keywords ***
Withdraw From Account
  [arguments]   ${amount}
  ${status} =   Withdraw From User Account  ${USER}  ${amount}
  [return]      ${status}
Withdraw Should Have Succeeded
  [arguments]   ${status}
  Should Be Equal   ${status}   SUCCESS
*** Test Cases ***
Withdraw From Account
  Withdraw From Account    $50
  Withdraw Should Have Succeeded
*** Keywords ***
Withdraw From Account
  [arguments]   ${amount}
  ${status} =   Withdraw From User Account  ${USER}  ${amount}
  Set Test Variable   ${STATUS}    ${status}
Withdraw Should Have Succeeded
  Should Be Equal   ${STATUS}   SUCCESS

Avoid sleeping