| 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", exact=True).click() |
| 14 |
page.set_viewport_size({"width": 960, "height": 700}) |
| 15 |
# Manually add the screenshot |
| 16 |
page.screenshot( |
| 17 |
path="docs/en/docs/img/tutorial/separate-openapi-schemas/image05.png" |
| 18 |
) |
| 19 |
|
| 20 |
# --------------------- |
| 21 |
context.close() |
| 22 |
browser.close() |
| 23 |
|
| 24 |
|
| 25 |
process = subprocess.Popen( |
| 26 |
["uvicorn", "docs_src.separate_openapi_schemas.tutorial002:app"] |
| 27 |
) |
| 28 |
try: |
| 29 |
with sync_playwright() as playwright: |
| 30 |
run(playwright) |
| 31 |
finally: |
| 32 |
process.terminate() |