(
context: BrowserContext,
page: Page,
server: Server,
tmp_path: Path,
show_trace_viewer: Callable[[Path], ContextManager[TraceViewerPage]],
)
| 80 | |
| 81 | |
| 82 | def 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 | |
| 131 | def test_should_collect_trace_with_resources_but_no_js( |
nothing calls this directly
no test coverage detected