Debian Codegraph @

scripts/playwright/cookie_param_models/image01.py

raw
1 import subprocess
2 import time
3
4 import httpx
5 from playwright.sync_api import Playwright, sync_playwright
6
7
8 # Run playwright codegen to generate the code below, copy paste the sections in run()
9 def run(playwright: Playwright) -> None:
10 browser = playwright.chromium.launch(headless=False)
11 # Update the viewport manually
12 context = browser.new_context(viewport={"width": 960, "height": 1080})
13 browser = playwright.chromium.launch(headless=False)
14 context = browser.new_context()
15 page = context.new_page()
16 page.goto("http://localhost:8000/docs")
17 page.get_by_role("link", name="/items/").click()
18 # Manually add the screenshot
19 page.screenshot(path="docs/en/docs/img/tutorial/cookie-param-models/image01.png")
20
21 # ---------------------
22 context.close()
23 browser.close()
24
25
26 process = subprocess.Popen(
27 ["fastapi", "run", "docs_src/cookie_param_models/tutorial001.py"]
28 )
29 try:
30 for _ in range(3):
31 try:
32 response = httpx.get("http://localhost:8000/docs")
33 except httpx.ConnectError:
34 time.sleep(1)
35 break
36 with sync_playwright() as playwright:
37 run(playwright)
38 finally:
39 process.terminate()