Skip to main content

Prerequisites

Before you begin, ensure you have the following installed:

Python 3.11+

Required for running pytest and Playwright

pip

Python package manager (included with Python)

Git

For cloning the repository

Terminal/Command Line

To run commands and tests

Verify Python Installation

Check your Python version:
python --version
# or
python3 --version
You should see Python 3.11 or higher.

Installation Steps

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

Create a Virtual Environment (Recommended)

Using a virtual environment keeps your project dependencies isolated:
python3 -m venv venv
source venv/bin/activate
You’ll see (venv) in your terminal prompt when the virtual environment is active.
3

Install Python Dependencies

Install all required packages from requirements.txt:
pip install -r requirements.txt

Installed Packages

The requirements.txt includes:
requirements.txt
pytest
pytest-html
pytest-playwright
playwright
python-dotenv
  • pytest - Modern Python testing framework with powerful features
  • pytest-html - Generates beautiful HTML test reports
  • pytest-playwright - Pytest plugin for Playwright integration
  • playwright - Browser automation library supporting Chromium, Firefox, and WebKit
  • python-dotenv - Loads environment variables from .env files
4

Install Playwright Browsers

Playwright requires browser binaries to be installed separately:
python -m playwright install --with-deps
This downloads:
  • Chromium
  • Firefox
  • WebKit (Safari engine)
The --with-deps flag installs system dependencies required on Linux. On macOS and Windows, you can omit this flag: python -m playwright install

Install Specific Browsers Only

To save disk space, install only what you need:
# Chromium only
python -m playwright install chromium

# Firefox only
python -m playwright install firefox

# WebKit only
python -m playwright install webkit
5

Verify Installation

Run a test to confirm everything is working:
pytest tests/test_login.py::test_valid_login -v
Expected output:
tests/test_login.py::test_valid_login PASSED [100%]
If the test passes, your installation is complete!

Project Structure

After installation, your project structure looks like this:
qa-automation-learning/
├── .github/
│   └── workflows/
│       └── playwright.yml      # CI/CD configuration
├── pages/                      # Page Object Model classes
│   ├── __init__.py
│   ├── login.py               # Login page object
│   ├── cart_page.py           # Shopping cart page object
│   └── checkout.py            # Checkout page object
├── testData/                  # Test data files
│   └── users.json             # User credentials
├── tests/                     # Test files
│   ├── __init__.py
│   ├── conftest.py           # Pytest fixtures and configuration
│   ├── test_login.py         # Login tests
│   ├── test_assertions.py    # Assertion examples
│   ├── test_functionalities.py # E2E functionality tests
│   └── test_API.py           # API tests
├── requirements.txt          # Python dependencies
└── README.md

Configuration

Test Fixtures

The project uses pytest fixtures defined in tests/conftest.py:8 for test data management:
import json
from pathlib import Path
import pytest

@pytest.fixture(scope="session")
def users():
    """
    Loads testData/users.json and returns a dict.
    Accessible in any test as the 'users' fixture.
    """
    root = Path(__file__).parent.parent
    data_path = root / "testData" / "users.json"
    with data_path.open(encoding="utf-8") as f:
        return json.load(f)

Environment Variables Setup

Create a .env file in the project root for sensitive credentials:
.env
USERNAME=standard_user
PASSWORD=secret_sauce
Never commit .env files to version control. Add it to your .gitignore file.

Test Data Files

Store test data in JSON format at testData/users.json:
testData/users.json
{
  "validUser": { 
    "username": "standard_user", 
    "password": "secret_sauce" 
  },
  "invalidUser": { 
    "username": "locked_out_user", 
    "password": "secret_sauce" 
  }
}
Use in tests with the users fixture:
def test_with_testdata(page, users):
    login_page = LoginPage(page)
    login_page.navigate()
    login_page.login(
        users["validUser"]["username"], 
        users["validUser"]["password"]
    )
    assert page.get_by_test_id("title").is_visible

CI/CD Setup

The project includes a GitHub Actions workflow at .github/workflows/playwright.yml:1 that automatically runs tests on every push and pull request.
.github/workflows/playwright.yml
name: CI - Run login test

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]
  workflow_dispatch:

permissions:
  contents: read

jobs:
  tests:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install -r requirements.txt

      - name: Install Playwright browsers
        run: |
          python -m playwright install --with-deps

      - name: Run Tests
        run: |
          mkdir -p test-results
          python -m pytest tests/test_login.py \
            --junitxml=test-results/junit.xml \
            --html=test-results/report.html --self-contained-html \
            --maxfail=1 -q --disable-warnings

      - name: Upload test results
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: test-results
          path: test-results/
          retention-days: 7

Key CI Features:

  • Runs on Ubuntu latest
  • Python 3.11
  • Installs dependencies and browsers automatically
  • Generates HTML and JUnit XML reports
  • Uploads test results as artifacts (retained for 7 days)
  • Triggered on push, PR, or manual dispatch

Playwright Configuration

Control which browser to use:
# Chromium (default)
pytest tests/test_login.py --browser chromium

# Firefox
pytest tests/test_login.py --browser firefox

# WebKit
pytest tests/test_login.py --browser webkit

# All browsers
pytest tests/test_login.py --browser chromium --browser firefox --browser webkit

Troubleshooting

Solution: Ensure you’ve installed dependencies and activated your virtual environment:
pip install -r requirements.txt
Solution: Install Playwright browsers:
python -m playwright install
Solution: Check your internet connection and consider increasing timeouts:
page.goto("https://example.com", timeout=60000)  # 60 seconds
Solution: Create a .env file in the project root:
echo "USERNAME=standard_user" > .env
echo "PASSWORD=secret_sauce" >> .env

Next Steps

Quickstart

Run your first test in minutes

Writing Tests

Learn how to write effective test cases

Page Object Model

Organize tests with the POM pattern

Advanced Features

Explore fixtures, parametrization, and more
You’re all set! Start writing tests and building your automation skills.

Build docs developers (and LLMs) love