Skip to content

Commit 68068fb

Browse files
improve playwright e2e test
1 parent 7839e46 commit 68068fb

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/e2e-playwright/tests/platform_CI_tests/test_platform.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,40 @@
66
# pylint: disable=no-name-in-module
77

88
from pathlib import Path
9+
from typing import Iterable
910

1011
import pytest
12+
from playwright.sync_api import BrowserContext
1113

1214

1315
@pytest.fixture(scope="session")
1416
def store_browser_context() -> bool:
1517
return True
1618

1719

20+
@pytest.fixture
21+
def results_path(request):
22+
"""
23+
Fixture to retrieve the path to the test's results directory.
24+
"""
25+
# Check if `results_dir` is available in the current test's user properties
26+
results_dir = dict(request.node.user_properties).get("results_dir")
27+
if not results_dir:
28+
results_dir = "test-results" # Default results directory
29+
test_name = request.node.name
30+
test_dir = Path(results_dir) / test_name
31+
test_dir.mkdir(parents=True, exist_ok=True) # Ensure the test directory exists
32+
return test_dir
33+
34+
1835
@pytest.fixture
1936
def logged_in_context(
2037
playwright,
2138
store_browser_context: bool,
2239
request: pytest.FixtureRequest,
2340
pytestconfig,
24-
):
41+
results_path: Path,
42+
) -> Iterable[BrowserContext]:
2543
is_headed = "--headed" in pytestconfig.invocation_params.args
2644

2745
file_path = Path("state.json")
@@ -30,7 +48,14 @@ def logged_in_context(
3048

3149
browser = playwright.chromium.launch(headless=not is_headed)
3250
context = browser.new_context(storage_state="state.json")
51+
test_name = request.node.name
52+
context.tracing.start(
53+
title=f"Trace for Browser 2 in test {test_name}",
54+
snapshots=True,
55+
screenshots=True,
56+
)
3357
yield context
58+
context.tracing.stop(path=f"{results_path}/second_browser_trace.zip")
3459
context.close()
3560
browser.close()
3661

@@ -80,7 +105,10 @@ def test_simple_workspace_workflow(
80105
and response.request.method == "POST"
81106
) as response_info:
82107
page.get_by_test_id("newWorkspaceButton").click()
108+
page.wait_for_timeout(500)
83109
page.get_by_test_id("workspaceEditorSave").click()
110+
page.wait_for_timeout(500)
111+
84112
_workspace_id = response_info.value.json()["data"]["workspaceId"]
85113
page.get_by_test_id(f"workspaceItem_{_workspace_id}").click()
86114
page.get_by_test_id("workspacesAndFoldersTreeItem_null_null").click()

0 commit comments

Comments
 (0)