This is the demo for the swaglabs test site. The exercise focuses on the checkout flow, but the framework is build to easily add additional tests for other scenarios.
- Python 3.12
- git
You have a couple of options for executing these tests.
- Local Machine installtion
- GitHub CodeSpace
Follow the steps below to install and run the tests locally. Easier if you have Python 3 installed already and you want to actually view the tests running in the browser.
It is mostly the same between Windows and Mac / Linux, but there are setup scripts that will help install the virtual environment and packages needed to run everything.
- Clone the repo using git. If you do not have git installed you can download the zip file and extract it to a location on your computer. The CLI to clone it is:
git clone https://github.com/sabadam32/demo.git
cd demo- Run the script to bootstrap the environment and execute the tests.
./run.shor for Windows
run.batTo run tests manually without opening the browser run:
pytest -vTo open the browser window while the tests are running use:
pytest -v --headedFollow these steps to run it on GitHub codespace. Nothing needed on your local machine for you to run it, but cannot view tests running in the browser.
- From the
Codebutton in the repository select theCodespacestab. - Click the
Create codespace on mainbutton and wait for it to setup. - In the terminal window run
pip install -r requirements.txt - Setup playwright broser by running
python -m playwright install --with-deps chromium - Run the tests
pytest -v
I used the Page object model along with a fluent design flow. All element locators and actions for a page are kept together. The fluent design allows the test to be more readable and self documenting.
Page objects are all found in the pages folder. This is the top level of the framework. There are also utility classes for componenets common all pages. Those are separated into the utility subfolder
All tests will be found in the tests folder. I am using Pytest for this demo which will find all tests automatically in this folder and run them. The test files can be setup in different ways. I chose to group the tests by user flow. Since we are concerned with the checkout flow for this demo, all tests will be in the test_checkout.py file
- test_happy_path_checkout - Validates that a user can add an item to the cart and checkout. This test has multiple assertions to ensure that each step succeeds. I used a parameterized test here to try the flow with all the possible users.
- test_must_login_to_shop - One of the negative scenarios is that we canot shop without logging in first.
- test_must_enter_user_information - We must enter user information before we checkout
-
test_cannot_bypass_user_information_step - Since all fields are required this screen should not be able to be bypassed.
${\textsf{\color{red}Fails}}$ -
test_valid_postal_code - These are numeric and should be validated on server side and client side.
${\textsf{\color{red}Fails}}$ -
test_input_length - There should be a reasonable limit on form input fields.
${\textsf{\color{red}Fails}}$ - test_username_and_password_required - Test that the username and password are both required
- test_password_case_sensitive - passwords should be case sensative.
- test_username_case_sensative - although not required, it is a good idea to implement this.
- test_no_clue_given_for_invalid_credentials - To help prevent brute forcing an account it is important for the error message to not indicate if the username or password specifically was incorrect. This is implicit in the 2 tests above but it is better to be explicit.