Debian Codegraph @

scripts/playwright/header_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 page = context.new_page()
14 page.goto("http://localhost:8000/docs")
15 page.get_by_role("button", name="GET /items/ Read Items").click()
16 page.get_by_role("button", name="Try it out").click()
17 # Manually add the screenshot
18 page.screenshot(path="docs/en/docs/img/tutorial/header-param-models/image01.png")
19
20 # ---------------------
21 context.close()
22 browser.close()
23
24
25 process = subprocess.Popen(
26 ["fastapi", "run", "docs_src/header_param_models/tutorial001.py"]
27 )
28 try:
29 for _ in range(3):
30 try:
31 response = httpx.get("http://localhost:8000/docs")
32 except httpx.ConnectError:
33 time.sleep(1)
34 break
35 with sync_playwright() as playwright:
36 run(playwright)
37 finally:
38 process.terminate()