Skip to main content

A framework for automated functional testing of web applications

Project description

webtest-kit

A framework for automated functional testing of web applications built on Python, pytest and Playwright.

Python pytest Playwright License: MIT


What is webtest-kit?

webtest-kit solves a common problem: setting up automated functional tests for a web application takes time — configuring pytest, Playwright, authentication, fixtures for different user roles, report generation.

webtest-kit gives you all of this out of the box. You describe your application in a single config.yaml file, and the framework automatically provides:

  • authenticated browser pages for each role (admin_page, manager_page, ...)
  • authenticated API clients for each role (admin_client, user_client, ...)
  • two-layer test architecture: fast API tests + full E2E browser tests
  • screenshot on failure
  • HTML and Allure report generation

Installation

pip install webtest-kit
playwright install chromium

Requirements: Python 3.11 or 3.12


Quickstart

# 1. Create a new test project
webtest-kit init my_app_tests
cd my_app_tests

# 2. Fill in your site URL and credentials
nano config.yaml

# 3. Run tests
webtest-kit run

# 4. View report
webtest-kit run --html-report
webtest-kit report --type html

How it works

1. Describe your application in config.yaml

base_url: http://localhost:8000

credentials:
  admin:
    username: admin
    password: secret
  user:
    username: regular
    password: pass123

auth:
  type: cookie_jwt
  login_url: /auth/login
  username_field: username
  password_field: password

browser:
  name: chromium
  headless: true
  timeout: 8000

2. Describe your pages using Page Object Model

# pages/login_page.py
from webtest_kit.core.base_page import BasePage

class LoginPage(BasePage):
    URL = "/auth/login"

    def __init__(self, page, base_url=None):
        super().__init__(page, base_url)
        self.username_input = self.by_testid("input-username")
        self.password_input = self.by_testid("input-password")
        self.submit_btn     = self.by_testid("btn-submit")
        self.error_alert    = self.by_testid("alert-error")

    def login(self, username, password):
        self.navigate()
        self.fill(self.username_input, username)
        self.fill(self.password_input, password)
        self.click(self.submit_btn)

    def expect_error(self, text=None):
        self.expect_visible(self.error_alert)
        if text:
            self.expect_text(self.error_alert, text)

3. Write tests — fixtures are already there

# tests/test_login.py
import pytest
from pages.login_page import LoginPage

pytestmark = pytest.mark.e2e

class TestLogin:

    def test_admin_is_authenticated(self, admin_page, base_url):
        # admin_page is already logged in — no manual login needed
        admin_page.goto(f"{base_url}/dashboard")
        assert "dashboard" in admin_page.url

    def test_wrong_password_shows_error(self, anon_page, base_url):
        page = LoginPage(anon_page, base_url)
        page.login("admin", "wrong")
        page.expect_error("Invalid username or password")

    def test_user_cannot_access_admin(self, user_page, base_url):
        user_page.goto(f"{base_url}/admin")
        assert "403" in user_page.locator("body").inner_text()
# tests/test_api.py
import pytest

pytestmark = pytest.mark.api

class TestApi:

    def test_admin_can_create_resource(self, admin_client):
        response = admin_client.post("/api/items", json={"name": "Test"})
        admin_client.assert_status(response, 201)

    def test_user_cannot_create_resource(self, user_client):
        response = user_client.post("/api/items", json={"name": "Test"})
        user_client.assert_status(response, 403)

    def test_list_returns_array(self, admin_client):
        data = admin_client.get_json("/api/items")
        assert isinstance(data, list)

CLI Commands

Command Description
webtest-kit init <name> Create new test project with scaffold
webtest-kit run Run all tests
webtest-kit run --headed Run with visible browser window
webtest-kit run --slowmo=500 Slow down browser actions (ms)
webtest-kit run --api-only Run only API tests (fast, no browser)
webtest-kit run --e2e-only Run only UI browser tests
webtest-kit run --html-report Generate HTML report
webtest-kit run --allure Generate Allure report data
webtest-kit run -k "test_login" Run tests matching keyword
webtest-kit report Open Allure report in browser
webtest-kit report --type html Open HTML report in browser

Project structure after webtest-kit init

my_app_tests/
├── config.yaml          ← your app URL, credentials, browser settings
├── conftest.py          ← ready to use, connects webtest-kit fixtures
├── pytest.ini           ← pytest configuration
├── pages/
│   └── example_page.py  ← copy and adapt for your pages
├── tests/
│   ├── test_api_example.py   ← API test examples
│   └── test_ui_example.py    ← UI test examples
└── reports/             ← test reports appear here

Available fixtures

After adding pytest_plugins = ["webtest_kit.core.fixtures"] to your conftest.py, these fixtures are available automatically:

Fixture Scope Description
{role}_page function Authenticated Playwright page for role
{role}_client function Authenticated httpx API client for role
anon_page function Unauthenticated browser page
anon_client function Unauthenticated API client
base_url session Base URL from config.yaml

Roles are defined in config.yaml under credentials. If you define admin, manager, user — you get admin_page, manager_page, user_page, admin_client, manager_client, user_client.


Supported authentication types

Type Description
cookie_jwt POST form login, JWT stored in cookie
session POST form login, session cookie
basic HTTP Basic Auth
bearer Bearer token in Authorization header

Demo project

The demo/ folder contains a complete working example: a TaskFlow task manager application with full API and E2E test suites.

# Run the demo application
cd demo/backend
python seed.py
uvicorn app.main:app --reload

# Run demo tests (in another terminal)
cd demo
webtest-kit run --api-only
webtest-kit run --e2e-only --headed

Documentation


License

MIT — see LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webtest_kit-0.1.1.tar.gz (54.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

webtest_kit-0.1.1-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file webtest_kit-0.1.1.tar.gz.

File metadata

  • Download URL: webtest_kit-0.1.1.tar.gz
  • Upload date:
  • Size: 54.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for webtest_kit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b3837e958634efb64b308505001597ff03c8206b617f33cbf417ef8959250df8
MD5 69ea6cfe8555e2de11a8185b6dabc46c
BLAKE2b-256 57795814465b0278a8cc8a18577e0accfb93b7f5a07d664fa30eb908146b7c05

See more details on using hashes here.

File details

Details for the file webtest_kit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: webtest_kit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for webtest_kit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 017340b2908fa28f083754f2c6a61d56800dd1e9deaa278cc0d86d730b63f1ac
MD5 ceda2a55a7a9ef1af03a1030103776b9
BLAKE2b-256 30b9e9c4837331a153c43bf0e30fad2fab79e458d8aaef790280d2e23ebbe79f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page