In this project I demonstrate some features of Robot Framework and Playwright framework,for automation E2E tests.
This project includes:
-
Frameworks:
- Robot Framework
- Playwright
-
Features:
- Authenticated test sessions with signed states
- Screenshot on fail and attach to reporter
- Generate trace file
- Using trace file for debug test
- Variable files and custom Keyword
For these tests I use a Sauce Labs demo app which can be found here: Sauce Demo
- Python >= 3.9 - How install Python
- Pip >= 21.3.x - How install pip
- Node >= 18.17 How install Node
Create a virtual environment:
$ python -m venv venv
$ source venv/bin/activate
Install dependencies:
$ pip3 install --no-cache-dir -r requirements.txt
$ rfbrowser init
To run tests in Chrome (for headless mode change HEADLESS to True, or change de variable value in tests/resources/system_variables.py )
$ robot -v BROWSER:chromium -v HEADLESS:False -d ./logs tests
$ robot -v BROWSER:firefox -d ./logs tests
In file tests/init.robot, there a code responsible for create state session files e generate browser sessions logged with users form tests/fixtures/users.json ho is used for all tests in folder tests
# __init__.robot
*** Settings ***
Library Browser
Library OperatingSystem
Library JSONLibrary
Variables ./resources/system_variables.py
Suite Setup Save Loged State File for user in ${file_path}
Suite Teardown Remove Directory ${OUTPUT_DIR}/browser/traces/ recursive=True
*** Variables ***
${file_path} tests/fixtures/users.json
${logo_text} css=.app_logo
${filed_username} css=[data-test=\"username\"]
${filed_password} css=[data-test=\"password\"]
${login_button} css=[data-test=\"login-button\"]
*** Keywords ***
Save Loged State File for user in ${file_path}
# Keyword ho interate over ${file_path}, get user and password, do login and save a state file for eatch user
# Load json file
${json_data}= Load Json From File ${file_path}
FOR ${user} IN @{json_data['users']}
${username}= Set Variable ${user['user']}
${password}= Set Variable ${user['password']}
New Browser ${BROWSER} headless=${HEADLESS}
New Context viewport={'width': ${SCREEN_WIDTH}, 'height': ${SCREEN_HEIGHT}}
New Page ${BASE_URL}
Type Text ${filed_username} ${username} clear=True
Type Text ${filed_password} ${password} clear=True
Click ${login_button}
Get Text ${logo_text} contains Swag Labs
${state_file}= Save Storage State
Move File ${state_file} ${OUTPUTDIR}/browser/state/${username}.json
Close Context
# Chame a keyword de login com os dados do usuário atual
END
Trace file is saved on logs/traces
To open a trace file:
rfbrowser show-trace -F logs/traces/Add\ a\ product\ to\ cart.zip