Skip to main content

Welcome to QA Automation Learning

This quickstart guide will help you run your first automated test in minutes. We’ll use Playwright with Python to test a demo e-commerce application.
This guide assumes you have Python 3.11+ installed on your system. If not, download it from python.org.

Quick Setup

1

Clone the repository

Get the source code from GitHub:
git clone https://github.com/yourusername/qa-automation-learning.git
cd qa-automation-learning
2

Install dependencies

Install all required packages using pip:
pip install -r requirements.txt
This installs:
  • pytest - Testing framework
  • pytest-html - HTML report generation
  • pytest-playwright - Playwright integration
  • playwright - Browser automation
  • python-dotenv - Environment variable management
3

Install browser drivers

Playwright needs browser binaries to run tests:
python -m playwright install --with-deps
The --with-deps flag installs system dependencies needed for browsers on Linux.
4

Run your first test

Execute the login test suite:
pytest tests/test_login.py -v
You should see output like:
tests/test_login.py::test_valid_login PASSED
tests/test_login.py::test_invalid_login PASSED
tests/test_login.py::test_logout_session PASSED

Your First Test

Let’s examine the test_valid_login test from tests/test_login.py:7:
tests/test_login.py
from playwright.sync_api import Page

URL = "https://www.saucedemo.com/"
login_dashboard = "https://www.saucedemo.com/inventory.html"

def test_valid_login(page: Page):
    page.goto(URL)
    
    username_input = page.get_by_placeholder("Username")
    username_input.fill("standard_user")

    password_input = page.get_by_placeholder("Password")
    password_input.fill("secret_sauce")

    login_button = page.locator("input#login-button")
    login_button.click()
    
    assert page.get_by_test_id("title").is_visible
    assert page.url == login_dashboard

What’s Happening?

  1. Page fixture - Playwright automatically provides a fresh browser page for each test
  2. Navigation - page.goto() loads the test application
  3. Element interaction - Uses locators to find and fill input fields
  4. Assertions - Verifies the login was successful by checking the URL and dashboard visibility

Using Page Object Model

The project uses the Page Object Model pattern for better code organization. Here’s the same test using the LoginPage class from pages/login.py:4:
from pages.login import LoginPage
from playwright.sync_api import Page

def test_successful_login(page):
    login_page = LoginPage(page)
    login_page.navigate()
    login_page.login("standard_user", "secret_sauce")

    assert page.get_by_test_id("title").is_visible

Running Tests with Options

pytest tests/test_login.py -v

Parametrized Tests

Test multiple scenarios with the same test logic using @pytest.mark.parametrize from tests/test_login.py:58:
@pytest.mark.parametrize("username, password",[
    ("error_user","secret_sauce"),
    ("performance_glitch_user","secret_sauce"),
    ("visual_user","secret_sauce")])

def test_multiple_users(page: Page, username, password):
    page.goto(URL)
    
    username_input = page.get_by_placeholder("Username")
    username_input.fill(username)

    password_input = page.get_by_placeholder("Password")
    password_input.fill(password)

    login_button = page.locator("input#login-button")
    login_button.click()

    assert page.get_by_test_id("title").is_visible
    assert page.url == login_dashboard
This runs the test 3 times with different user credentials.

Next Steps

Installation Guide

Deep dive into setup and configuration options

Test Data Management

Learn how to use fixtures and external data files

Page Objects

Master the Page Object Model pattern

CI/CD Integration

Run tests in GitHub Actions
The default credentials (standard_user / secret_sauce) work only with the Sauce Demo application. You’ll need to configure your own credentials for other applications.

Build docs developers (and LLMs) love