Skip to content

Commit

Permalink
🚧 Make trace
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Apr 4, 2024
1 parent d617eb8 commit 73cd2b9
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/openforms/tests/e2e/test_file_upload.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import os
from pathlib import Path
from typing import Literal
from unittest.mock import patch

from django.urls import reverse

from asgiref.sync import sync_to_async
from furl import furl
from playwright.async_api import expect
from playwright.async_api import BrowserType, async_playwright, expect
from rest_framework.test import APIRequestFactory

from openforms.forms.tests.factories import FormFactory
from openforms.tests.e2e.base import E2ETestCase, browser_page
from openforms.tests.e2e.base import E2ETestCase

factory = APIRequestFactory()

TEST_FILES = Path(__file__).parent / "data"

HEADLESS = "NO_E2E_HEADLESS" not in os.environ
BROWSER: Literal["chromium", "firefox", "webkit"] = os.getenv(
"E2E_DRIVER", default="chromium"
) # type:ignore
SLOW_MO = int(os.environ.get("SLOW_MO", "100"))
PLAYWRIGHT_BROWSERS_PATH = os.getenv("PLAYWRIGHT_BROWSERS_PATH", default=None)

LAUNCH_KWARGS = {
"headless": HEADLESS,
"slow_mo": SLOW_MO,
"executable_path": PLAYWRIGHT_BROWSERS_PATH,
}


class FillInFormTests(E2ETestCase):
async def test_form_with_file_upload(self):
Expand Down Expand Up @@ -53,7 +68,20 @@ def setUpTestData():
)

with patch("openforms.utils.validators.allow_redirect_url", return_value=True):
async with browser_page() as page:
async with async_playwright() as p:
# Start browser here with tracing
_browser: BrowserType = getattr(p, BROWSER)
browser = await _browser.launch(**LAUNCH_KWARGS)
context = await browser.new_context(
locale="en-UK",
timezone_id="Europe/Amsterdam",
)
await context.tracing.start(
screenshots=True, snapshots=True, sources=True
)

page = await context.new_page()

await page.goto(form_url)

await page.get_by_role("button", name="Formulier starten").click()
Expand Down Expand Up @@ -81,3 +109,6 @@ def setUpTestData():
await expect(
page.get_by_text("Een moment geduld", exact=False)
).to_be_visible()

await context.tracing.stop(path="trace_file_upload_test.zip")
await browser.close()

0 comments on commit 73cd2b9

Please sign in to comment.