-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add frontend-tests with pytest-playwright
- Loading branch information
1 parent
8013d21
commit 795ee1d
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from django.core.management import call_command | ||
|
||
from playwright.sync_api import Page, expect | ||
from pytest_django.live_server_helper import LiveServer | ||
|
||
from rdmo.accounts.utils import set_group_permissions | ||
|
||
# Ref: https://pytest-django.readthedocs.io/en/latest/helpers.html#live-server | ||
# https://playwright.dev/python/docs/auth | ||
|
||
# TODO: django_db_serialized_rollback | ||
|
||
# needed for playwright to run | ||
os.environ.setdefault("DJANGO_ALLOW_ASYNC_UNSAFE", "true") | ||
|
||
@pytest.fixture(scope="function") | ||
def e2e_tests_django_db_setup(django_db_setup, django_db_blocker, fixtures): | ||
"""Set up database and populate with fixtures, that get restored for every test case.""" | ||
with django_db_blocker.unblock(): | ||
call_command('loaddata', *fixtures) | ||
set_group_permissions() | ||
|
||
@pytest.fixture(scope="session") | ||
def base_url(live_server: LiveServer) -> str: | ||
"""Enable playwright to address URLs with base URL automatically prefixed.""" | ||
return live_server.url | ||
|
||
@pytest.fixture | ||
def logged_in_admin_user(e2e_tests_django_db_setup, page: Page) -> Page: | ||
page.goto("/account/login") | ||
# log in as admin user | ||
page.get_by_label("Username").fill("admin", timeout=5000) | ||
page.get_by_label("Password").fill("admin") | ||
page.get_by_role("button", name="Login").click() | ||
page.goto("/management") | ||
yield page | ||
|
||
@pytest.mark.e2e | ||
def test_management_navigation(logged_in_admin_user: Page) -> None: | ||
"""Test that each content type is available through the navigation.""" | ||
page = logged_in_admin_user | ||
expect(page.get_by_role("heading", name="Management")).to_be_visible() | ||
page.get_by_role("link", name="Catalogs").click() | ||
expect(page.locator("strong").filter(has_text="Catalogs")).to_be_visible() | ||
page.get_by_role("link", name="Sections").click() | ||
page.get_by_role("link", name="Pages").click() | ||
page.get_by_role("link", name="Question sets").click() | ||
page.get_by_role("link", name="Questions", exact=True).click() | ||
page.get_by_role("link", name="Attributes").click() | ||
page.get_by_role("link", name="Option sets").click() | ||
page.get_by_role("link", name="Options", exact=True).click() | ||
page.get_by_role("link", name="Conditions").click() | ||
page.get_by_role("link", name="Tasks").click() | ||
page.get_by_role("link", name="Views").click() | ||
|
||
|
||
@pytest.mark.e2e | ||
def test_management_has_catalogs(logged_in_admin_user: Page) -> None: | ||
page = logged_in_admin_user | ||
page.goto("/management/catalogs") |