- Mount /opt/playwright-tools/browsers into web container (docker-compose.yml and CI docker run) — never download browsers, use the ones on this host - Set PLAYWRIGHT_BROWSERS_PATH in all container envs (compose + CI) - Drop 'playwright install chromium' steps from pr-e2e and nightly-e2e jobs - Bump playwright requirement to ~1.57.0 to match the installed browser builds - Fix seed_e2e_content: de-duplicate default Site entries left by unit test fixtures so Wagtail always routes to the seeded home page - Fix test_comments_section_absent_when_disabled: use exact=True on heading locator to avoid matching 'No Comments Article' h1 as 'Comments' heading - Fix test_copy_link_button_updates_text: use [data-copy-link] data-attr locator (stable across text change) and force-override clipboard.writeText via page.evaluate() rather than relying on init_script polyfill E2E suite verified locally: 34 passed via docker compose exec Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
60 lines
2.6 KiB
Python
60 lines
2.6 KiB
Python
"""E2E tests for the comment submission flow."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from playwright.sync_api import Page, expect
|
|
|
|
ARTICLE_SLUG = "nightly-playwright-journey"
|
|
|
|
|
|
def _go_to_article(page: Page, base_url: str) -> None:
|
|
page.goto(f"{base_url}/articles/{ARTICLE_SLUG}/", wait_until="networkidle")
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_valid_comment_submission_redirects(page: Page, base_url: str) -> None:
|
|
_go_to_article(page, base_url)
|
|
|
|
# Fill the main comment form (not a reply form)
|
|
form = page.locator("form[action]").filter(has=page.get_by_role("button", name="Post comment"))
|
|
form.locator('input[name="author_name"]').fill("E2E Tester")
|
|
form.locator('input[name="author_email"]').fill("e2e@example.com")
|
|
form.locator('textarea[name="body"]').fill("This is a test comment from Playwright.")
|
|
form.get_by_role("button", name="Post comment").click()
|
|
|
|
# Successful submission redirects back to the article with ?commented=1
|
|
page.wait_for_url(lambda url: "commented=1" in url, timeout=10_000)
|
|
assert "commented=1" in page.url
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_empty_body_shows_form_errors(page: Page, base_url: str) -> None:
|
|
_go_to_article(page, base_url)
|
|
|
|
form = page.locator("form[action]").filter(has=page.get_by_role("button", name="Post comment"))
|
|
form.locator('input[name="author_name"]').fill("E2E Tester")
|
|
form.locator('input[name="author_email"]').fill("e2e@example.com")
|
|
form.locator('textarea[name="body"]').fill(" ") # whitespace-only body
|
|
form.get_by_role("button", name="Post comment").click()
|
|
page.wait_for_load_state("networkidle")
|
|
|
|
# The page re-renders with the error summary visible
|
|
expect(page.locator('[aria-label="Comment form errors"]')).to_be_visible()
|
|
# URL must NOT have ?commented=1 — form was not accepted
|
|
assert "commented=1" not in page.url
|
|
|
|
|
|
@pytest.mark.e2e
|
|
def test_comments_section_absent_when_disabled(page: Page, base_url: str) -> None:
|
|
"""Article with comments_enabled=False must not show the comments section."""
|
|
response = page.goto(f"{base_url}/articles/e2e-no-comments/", wait_until="networkidle")
|
|
assert response is not None and response.status == 200, (
|
|
f"Expected 200 for e2e-no-comments article, got {response and response.status}"
|
|
)
|
|
# Confirm we're on the right page
|
|
expect(page.get_by_role("heading", level=1)).to_have_text("No Comments Article")
|
|
# Comments section must be absent — exact=True prevents matching "No Comments Article" h1
|
|
expect(page.get_by_role("heading", name="Comments", exact=True)).to_have_count(0)
|
|
expect(page.get_by_role("button", name="Post comment")).to_have_count(0)
|