No project description provided
Project description
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}")
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file adacs_django_playwright-1.2.0.tar.gz.
File metadata
- Download URL: adacs_django_playwright-1.2.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.12.22+bpo-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f562f5b3541faacf86beee2821ef624b1e2c1aca6d56e31c4e95eabba74ecae0
|
|
| MD5 |
220b4a2482be7cddda160e861e5243e3
|
|
| BLAKE2b-256 |
b9c9143f50cf3b102f0806399d1cd52d1067728056b56c5adc7e92462de8de9a
|
File details
Details for the file adacs_django_playwright-1.2.0-py3-none-any.whl.
File metadata
- Download URL: adacs_django_playwright-1.2.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.12.22+bpo-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10bb079a9cab53ef0d3fadb8f55d9b2699179080602ab8745a3a02c77bf76213
|
|
| MD5 |
7eb88829e417fd380d1cf89e9fc8e7bf
|
|
| BLAKE2b-256 |
9d196dd20faa2e178b4a019a31c31708a24216929ee5d287a963bf65e8ab15d6
|