Skip to main content

ADACS Playwright Class

A Django python package that extends the Django StaticLiveServerTestCase to use Playwright for testing.

Why?

When using Playwright for testing with the Django test runner there are common issues that need to be solved:

  • Accessing the playwright object, browser object, and the browser context.
  • Automatically closing the browser context after each test.
  • Forcing login of a user for admin testing.
  • Correctly setting cookies during login.
  • Handling async requests and responses.

On top of the above this package also provides support for htmx by providing methods to wait for htmx requests to finish.

Usage

Instead of inheriting from Django's StaticLiveServerTestCase you should inherit from either PlaywrightTestCase for synchronous tests or AsyncPlaywrightTestCase for asynchronous tests. Both classes behave like StaticLiveServerTestCase but with the added functionality of Playwright.

They adds 2 useful class properties:

self.browser   # A browser object from playwright used for accessing the page.
self.playwright  # The return from sync_playwright().start()

They also add the following methods on both the sync and async classes:

  • login
    Logs in a Django user by setting session cookies in the browser context.
    Example:

    test_case.login(user)
    
  • htmx_wait
    Waits for HTMX to load and complete any ongoing operations on the page.
    Example:

    test_case.htmx_wait(page)
    
  • htmx_settle
    Ensures all HTMX operations (requests, DOM updates) are finished before proceeding.
    Example:

    test_case.htmx_settle(page)
    

Example Test

from adacs_django_playwright.adacs_django_playwright import PlaywrightTestCase

class MyTestCase(PlaywrightTestCase):

  def awesome_test(self):
    page = self.browser.new_page()
    page.goto(f"{self.live_server_url}")

Release files for adacs-django-playwright 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adacs-django-playwright 1.2.0
File Size Uploaded
adacs_django_playwright-1.2.0.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for adacs-django-playwright 1.2.0
File Interpreter ABI Platform
adacs_django_playwright-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.0 kB

Release files / adacs_django_playwright-1.2.0.tar.gz

Download URL adacs_django_playwright-1.2.0.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f562f5b3541faacf86beee2821ef624b1e2c1aca6d56e31c4e95eabba74ecae0
BLAKE2b-256 checksum
How to use checksums
b9c9143f50cf3b102f0806399d1cd52d1067728056b56c5adc7e92462de8de9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.12.22+bpo-amd64

Release files / adacs_django_playwright-1.2.0-py3-none-any.whl

Download URL adacs_django_playwright-1.2.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10bb079a9cab53ef0d3fadb8f55d9b2699179080602ab8745a3a02c77bf76213
BLAKE2b-256 checksum
How to use checksums
9d196dd20faa2e178b4a019a31c31708a24216929ee5d287a963bf65e8ab15d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.12.22+bpo-amd64

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page