forked from aaronlab/browsertrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaywright_example.py
More file actions
56 lines (41 loc) · 1.49 KB
/
Copy pathplaywright_example.py
File metadata and controls
56 lines (41 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Example: integrating BrowserTrace with Playwright.
Captures real screenshots and DOM URLs from a live browser run.
Install:
pip install playwright
playwright install chromium
Run:
python examples/playwright_example.py
browsertrace
"""
import asyncio
from browsertrace import Tracer
async def main():
from playwright.async_api import async_playwright
tracer = Tracer()
async with async_playwright() as p:
browser = await p.chromium.launch(headless=True)
page = await browser.new_page()
with tracer.run("playwright: open hn front page") as run:
await page.goto("https://news.ycombinator.com")
run.step(
action="navigate",
url=page.url,
screenshot=await page.screenshot(),
)
await page.wait_for_selector(".athing")
run.step(
action="wait for stories to load",
url=page.url,
screenshot=await page.screenshot(),
)
first_link = await page.locator(".athing .titleline > a").first.text_content()
run.step(
action=f"read first headline: {first_link!r}",
url=page.url,
screenshot=await page.screenshot(),
metadata={"headline": first_link},
)
await browser.close()
if __name__ == "__main__":
asyncio.run(main())
print("Done. Run `browsertrace` to view at http://127.0.0.1:3000")