Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion tests/async/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,42 @@

from pathlib import Path

from playwright.async_api import Browser, BrowserContext
from tests.server import Server

async def test_browser_context_output_trace(browser, server, tmp_path):

async def test_browser_context_output_trace(
browser: Browser, server: Server, tmp_path: Path
):
context = await browser.new_context()
await context.tracing.start(screenshots=True, snapshots=True)
page = await context.new_page()
await page.goto(server.PREFIX + "/grid.html")
await context.tracing.stop(path=tmp_path / "trace.zip")
assert Path(tmp_path / "trace.zip").exists()


async def test_browser_context_should_not_throw_when_stopping_without_start_but_not_exporting(
context: BrowserContext, server: Server, tmp_path: Path
):
await context.tracing.stop()


async def test_browser_context_output_trace_chunk(
browser: Browser, server: Server, tmp_path: Path
):
context = await browser.new_context()
await context.tracing.start(screenshots=True, snapshots=True)
page = await context.new_page()
await page.goto(server.PREFIX + "/grid.html")
button = page.locator(".box").first

await context.tracing.start_chunk(title="foo")
await button.click()
await context.tracing.stop_chunk(path=tmp_path / "trace1.zip")
assert Path(tmp_path / "trace1.zip").exists()

await context.tracing.start_chunk(title="foo")
await button.click()
await context.tracing.stop_chunk(path=tmp_path / "trace2.zip")
assert Path(tmp_path / "trace2.zip").exists()
28 changes: 27 additions & 1 deletion tests/sync/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from pathlib import Path

from playwright.sync_api import Browser
from playwright.sync_api import Browser, BrowserContext
from tests.server import Server


Expand All @@ -27,3 +27,29 @@ def test_browser_context_output_trace(
page.goto(server.PREFIX + "/grid.html")
context.tracing.stop(path=tmp_path / "trace.zip")
assert Path(tmp_path / "trace.zip").exists()


def test_browser_context_should_not_throw_when_stopping_without_start_but_not_exporting(
context: BrowserContext,
) -> None:
context.tracing.stop()


def test_browser_context_output_trace_chunk(
browser: Browser, server: Server, tmp_path: Path
) -> None:
context = browser.new_context()
context.tracing.start(screenshots=True, snapshots=True)
page = context.new_page()
page.goto(server.PREFIX + "/grid.html")
button = page.locator(".box").first

context.tracing.start_chunk(title="foo")
button.click()
context.tracing.stop_chunk(path=tmp_path / "trace1.zip")
assert Path(tmp_path / "trace1.zip").exists()

context.tracing.start_chunk(title="foo")
button.click()
context.tracing.stop_chunk(path=tmp_path / "trace2.zip")
assert Path(tmp_path / "trace2.zip").exists()