MCPcopy Create free account
hub / github.com/microsoft/playwright-python / test_should_collect_sources

Function test_should_collect_sources

tests/sync/test_tracing.py:82–128  ·  view source on GitHub ↗
(
    context: BrowserContext,
    page: Page,
    server: Server,
    tmp_path: Path,
    show_trace_viewer: Callable[[Path], ContextManager[TraceViewerPage]],
)

Source from the content-addressed store, hash-verified

80
81
82def test_should_collect_sources(
83 context: BrowserContext,
84 page: Page,
85 server: Server,
86 tmp_path: Path,
87 show_trace_viewer: Callable[[Path], ContextManager[TraceViewerPage]],
88) -> None:
89 context.tracing.start(sources=True)
90 page.goto(server.EMPTY_PAGE)
91 page.set_content("<button>Click</button>")
92
93 def my_method_outer() -> None:
94 def my_method_inner() -> None:
95 page.get_by_text("Click").click()
96
97 my_method_inner()
98
99 my_method_outer()
100 path = tmp_path / "trace.zip"
101 context.tracing.stop(path=path)
102
103 with show_trace_viewer(path) as trace_viewer:
104 expect(trace_viewer.action_titles).to_have_text(
105 [
106 re.compile(r'Navigate to "/empty\.html"'),
107 re.compile(r"Set content"),
108 re.compile(r"Click"),
109 ]
110 )
111 trace_viewer.show_source_tab()
112 # Check that stack frames are shown (they might be anonymous in Python)
113 expect(trace_viewer.stack_frames).to_contain_text(
114 [
115 re.compile(r"my_method_inner"),
116 re.compile(r"my_method_outer"),
117 re.compile(r"test_should_collect_sources"),
118 ]
119 )
120
121 trace_viewer.select_action("Set content")
122 # Check that the source file is shown
123 expect(trace_viewer.page.locator(".source-tab-file-name")).to_have_attribute(
124 "title", re.compile(r".*test_.*\.py")
125 )
126 expect(trace_viewer.page.locator(".source-line-running")).to_contain_text(
127 'page.set_content("<button>Click</button>")'
128 )
129
130
131def test_should_collect_trace_with_resources_but_no_js(

Callers

nothing calls this directly

Calls 12

my_method_outerFunction · 0.70
show_trace_viewerFunction · 0.70
startMethod · 0.45
gotoMethod · 0.45
set_contentMethod · 0.45
stopMethod · 0.45
to_have_textMethod · 0.45
show_source_tabMethod · 0.45
to_contain_textMethod · 0.45
select_actionMethod · 0.45
to_have_attributeMethod · 0.45
locatorMethod · 0.45

Tested by

no test coverage detected