Just learning

Those a just properly written notes for an hypothetical futur amnesic me willing to re-use Robot Framework for acceptance tests.

Here's the official site, and the Quickstart guide from which I got started initialy. And here's the Robot Framework Selenium library documentation, especially useful to find the keywords


Since I'm using a Windows 10 workstation with admin's rights, this is roughtly what I did

Open a CMD as Administrator, and install Chocolatey

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Maybe re-open your CMD as Administrator. Install Firefox, Selenium drivers, Python & pip.

choco install -y python3 pip firefox selenium-all-drivers

Then upgrade pip and install pipenv

pip install -U pip pipenv

Now close CMD as Administrator and open a regular CMD in a workdir. Then install python deps

pipenv install robotframework robotframework-selenium2library

Now you're all set, just need to write down some tests and run them

Write a not so basic test

Write down a resource.robot. Note web page title are in french here !

*** Settings ***
Documentation     A resource file with reusable keywords and variables.
...               The system specific keywords created here form our own
...               domain specific language. They utilize keywords provided
...               by the imported Selenium2Library.
Library           Selenium2Library

*** Variables ***
${SERVER}         webmail.gandi.net
${BROWSER}        Firefox
${DELAY}          0
${VALID USER}     remy.@garrigue.re
${VALID PASSWORD}    InvalidPasswordButIDontCare
${LOGIN URL}      https://${SERVER}/?_task=login

*** Keywords ***
Open Browser To Login Page
    Open Browser    ${LOGIN URL}    ${BROWSER}
    Maximize Browser Window
    Set Selenium Speed    ${DELAY}
    Login Page Should Be Open

Login Page Should Be Open
    Title Should Be    Roundcube Webmail :: Bienvenue sur Roundcube Webmail

Go To Login Page
    Go To    ${LOGIN URL}
    Login Page Should Be Open

Input Username
    [Arguments]    ${username}
    Input Text    rcmloginuser    ${username}

Input Password
    [Arguments]    ${password}
    Input Text    rcmloginpwd    ${password}

Submit Credentials
    Click Button    rcmloginsubmit

Inbox Page Should Be Open
    Title Should Be    Roundcube Webmail :: INBOX

Login Failed Page Should Be Open
    Location Should Be      ${LOGIN_URL}
    Title Should Be         Roundcube Webmail :: Bienvenue sur Roundcube Webmail
    Wait Until Element Is Enabled    rcmloginsubmit
    # Wait Until Page Does Not Contain    Chargement... # Nope, wait's too long, I guess u can change that
    Page Should Contain     La connexion a échoué

And write down another file test_invalid_login.robot

*** Settings ***
Documentation     A test suite about testing (gandi.net's) Roundcube Webmail with invalid credentials
...               This is taken from the official doc and adapted to a diffrent use case than their demo
Suite Setup       Open Browser To Login Page
Suite Teardown    Close Browser
Test Setup        Go To Login Page
Test Template     Login With Invalid Credentials Should Fail
Resource          resource.robot

*** Test Cases ***               USER NAME        PASSWORD
Invalid Username                 invalid          ${VALID PASSWORD}
Invalid Password                 ${VALID USER}    invalid
Invalid Username And Password    invalid          whatever
Empty Username                   ${EMPTY}         ${VALID PASSWORD}
Empty Password                   ${VALID USER}    ${EMPTY}
Empty Username And Password      ${EMPTY}         ${EMPTY}

*** Keywords ***
Login With Invalid Credentials Should Fail
    [Arguments]    ${username}    ${password}
    Input Username    ${username}
    Input Password    ${password}
    Submit Credentials
    Login Should Have Failed

Login Should Have Failed
    Login Failed Page Should Be Open

Run tests

Open a CMD in the workdir, and activate pipenv related commands. Otherwise robot command doesn't exist system-wide

pipenv shell
robot test_invalid_login.robot

This test will fail with 3 OK & 3 KO : Roundcube's login display a small tooltip when you forget login or password. Open the report, firefox report.html and have a look.

A good thing is you have a screenshot from the failed step. The downside is that the popup's missing from the screenshot, you've to test this yourself to realize the issue. But that's OK, since the test should be aimed at being 100% OK even for "I did it wrong" scenarios, and KO for broken scenarios only.