Debian Codegraph @

scripts/playwright/json_base64_bytes/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="POST /data Post Data").click()
16 # Manually add the screenshot
17 page.screenshot(path="docs/en/docs/img/tutorial/json-base64-bytes/image01.png")
18
19 # ---------------------
20 context.close()
21 browser.close()
22
23
24 process = subprocess.Popen(
25 ["fastapi", "run", "docs_src/json_base64_bytes/tutorial001_py310.py"]
26 )
27 try:
28 for _ in range(3):
29 try:
30 response = httpx.get("http://localhost:8000/docs")
31 except httpx.ConnectError:
32 time.sleep(1)
33 break
34 with sync_playwright() as playwright:
35 run(playwright)
36 finally:
37 process.terminate()