66# pylint: disable=no-name-in-module
77
88from pathlib import Path
9+ from typing import Iterable
910
1011import pytest
12+ from playwright .sync_api import BrowserContext
1113
1214
1315@pytest .fixture (scope = "session" )
1416def 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
1936def 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