Debian Codegraph @

scripts/playwright/separate_openapi_schemas/image04.py

raw
1 import subprocess
2
3 from playwright.sync_api import Playwright, sync_playwright
4
5
6 # Run playwright codegen to generate the code below, copy paste the sections in run()
7 def run(playwright: Playwright) -> None:
8 browser = playwright.chromium.launch(headless=False)
9 # Update the viewport manually
10 context = browser.new_context(viewport={"width": 960, "height": 1080})
11 page = context.new_page()
12 page.goto("http://localhost:8000/docs")
13 page.get_by_role("button", name="Item-Input").click()
14 page.get_by_role("button", name="Item-Output").click()
15 page.set_viewport_size({"width": 960, "height": 820})
16 # Manually add the screenshot
17 page.screenshot(
18 path="docs/en/docs/img/tutorial/separate-openapi-schemas/image04.png"
19 )
20 # ---------------------
21 context.close()
22 browser.close()
23
24
25 process = subprocess.Popen(
26 ["uvicorn", "docs_src.separate_openapi_schemas.tutorial001:app"]
27 )
28 try:
29 with sync_playwright() as playwright:
30 run(playwright)
31 finally:
32 process.terminate()