Browse Source

🐛 Fix Playwright scripts: server readiness check and duplicate browser launch

- Fix inverted retry logic in httpx readiness check: break on success instead of on ConnectError
- Increase retry count from 3 to 10 for more reliable server startup wait
- Remove duplicate browser launch and context overwrite in cookie_param_models and query_param_models scripts, preserving the intended 960x1080 viewport
pull/15399/head
yangxiangwen 2 months ago
parent
commit
840bfbfd92
Failed to extract signature
  1. 7
      scripts/playwright/cookie_param_models/image01.py
  2. 5
      scripts/playwright/header_param_models/image01.py
  3. 5
      scripts/playwright/json_base64_bytes/image01.py
  4. 7
      scripts/playwright/query_param_models/image01.py
  5. 5
      scripts/playwright/request_form_models/image01.py
  6. 5
      scripts/playwright/sql_databases/image01.py
  7. 5
      scripts/playwright/sql_databases/image02.py

7
scripts/playwright/cookie_param_models/image01.py

@ -10,8 +10,6 @@ def run(playwright: Playwright) -> None:
browser = playwright.chromium.launch(headless=False)
# Update the viewport manually
context = browser.new_context(viewport={"width": 960, "height": 1080})
browser = playwright.chromium.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.goto("http://localhost:8000/docs")
page.get_by_role("link", name="/items/").click()
@ -27,12 +25,13 @@ process = subprocess.Popen(
["fastapi", "run", "docs_src/cookie_param_models/tutorial001.py"]
)
try:
for _ in range(3):
for _ in range(10):
try:
response = httpx.get("http://localhost:8000/docs")
if response.status_code == 200:
break
except httpx.ConnectError:
time.sleep(1)
break
with sync_playwright() as playwright:
run(playwright)
finally:

5
scripts/playwright/header_param_models/image01.py

@ -26,12 +26,13 @@ process = subprocess.Popen(
["fastapi", "run", "docs_src/header_param_models/tutorial001.py"]
)
try:
for _ in range(3):
for _ in range(10):
try:
response = httpx.get("http://localhost:8000/docs")
if response.status_code == 200:
break
except httpx.ConnectError:
time.sleep(1)
break
with sync_playwright() as playwright:
run(playwright)
finally:

5
scripts/playwright/json_base64_bytes/image01.py

@ -25,12 +25,13 @@ process = subprocess.Popen(
["fastapi", "run", "docs_src/json_base64_bytes/tutorial001_py310.py"]
)
try:
for _ in range(3):
for _ in range(10):
try:
response = httpx.get("http://localhost:8000/docs")
if response.status_code == 200:
break
except httpx.ConnectError:
time.sleep(1)
break
with sync_playwright() as playwright:
run(playwright)
finally:

7
scripts/playwright/query_param_models/image01.py

@ -10,8 +10,6 @@ def run(playwright: Playwright) -> None:
browser = playwright.chromium.launch(headless=False)
# Update the viewport manually
context = browser.new_context(viewport={"width": 960, "height": 1080})
browser = playwright.chromium.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.goto("http://localhost:8000/docs")
page.get_by_role("button", name="GET /items/ Read Items").click()
@ -29,12 +27,13 @@ process = subprocess.Popen(
["fastapi", "run", "docs_src/query_param_models/tutorial001.py"]
)
try:
for _ in range(3):
for _ in range(10):
try:
response = httpx.get("http://localhost:8000/docs")
if response.status_code == 200:
break
except httpx.ConnectError:
time.sleep(1)
break
with sync_playwright() as playwright:
run(playwright)
finally:

5
scripts/playwright/request_form_models/image01.py

@ -26,12 +26,13 @@ process = subprocess.Popen(
["fastapi", "run", "docs_src/request_form_models/tutorial001.py"]
)
try:
for _ in range(3):
for _ in range(10):
try:
response = httpx.get("http://localhost:8000/docs")
if response.status_code == 200:
break
except httpx.ConnectError:
time.sleep(1)
break
with sync_playwright() as playwright:
run(playwright)
finally:

5
scripts/playwright/sql_databases/image01.py

@ -25,12 +25,13 @@ process = subprocess.Popen(
["fastapi", "run", "docs_src/sql_databases/tutorial001.py"],
)
try:
for _ in range(3):
for _ in range(10):
try:
response = httpx.get("http://localhost:8000/docs")
if response.status_code == 200:
break
except httpx.ConnectError:
time.sleep(1)
break
with sync_playwright() as playwright:
run(playwright)
finally:

5
scripts/playwright/sql_databases/image02.py

@ -25,12 +25,13 @@ process = subprocess.Popen(
["fastapi", "run", "docs_src/sql_databases/tutorial002.py"],
)
try:
for _ in range(3):
for _ in range(10):
try:
response = httpx.get("http://localhost:8000/docs")
if response.status_code == 200:
break
except httpx.ConnectError:
time.sleep(1)
break
with sync_playwright() as playwright:
run(playwright)
finally:

Loading…
Cancel
Save