From 840bfbfd92be659732cf0472123380ad9c4476ce Mon Sep 17 00:00:00 2001 From: yangxiangwen <50519347+liuyiyangwang@users.noreply.github.com> Date: Tue, 21 Apr 2026 20:45:09 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20Playwright=20scripts:=20se?= =?UTF-8?q?rver=20readiness=20check=20and=20duplicate=20browser=20launch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- scripts/playwright/cookie_param_models/image01.py | 7 +++---- scripts/playwright/header_param_models/image01.py | 5 +++-- scripts/playwright/json_base64_bytes/image01.py | 5 +++-- scripts/playwright/query_param_models/image01.py | 7 +++---- scripts/playwright/request_form_models/image01.py | 5 +++-- scripts/playwright/sql_databases/image01.py | 5 +++-- scripts/playwright/sql_databases/image02.py | 5 +++-- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/scripts/playwright/cookie_param_models/image01.py b/scripts/playwright/cookie_param_models/image01.py index 77c91bfe22..a8cf3d1bf1 100644 --- a/scripts/playwright/cookie_param_models/image01.py +++ b/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: diff --git a/scripts/playwright/header_param_models/image01.py b/scripts/playwright/header_param_models/image01.py index 53914251ed..8a41c3825b 100644 --- a/scripts/playwright/header_param_models/image01.py +++ b/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: diff --git a/scripts/playwright/json_base64_bytes/image01.py b/scripts/playwright/json_base64_bytes/image01.py index 56c57e1c32..1d3fada5b2 100644 --- a/scripts/playwright/json_base64_bytes/image01.py +++ b/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: diff --git a/scripts/playwright/query_param_models/image01.py b/scripts/playwright/query_param_models/image01.py index 0ea1d0df4e..157ac4ef52 100644 --- a/scripts/playwright/query_param_models/image01.py +++ b/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: diff --git a/scripts/playwright/request_form_models/image01.py b/scripts/playwright/request_form_models/image01.py index fe4da32fcb..ec4472ec3e 100644 --- a/scripts/playwright/request_form_models/image01.py +++ b/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: diff --git a/scripts/playwright/sql_databases/image01.py b/scripts/playwright/sql_databases/image01.py index 0dd6f25145..0490d621a0 100644 --- a/scripts/playwright/sql_databases/image01.py +++ b/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: diff --git a/scripts/playwright/sql_databases/image02.py b/scripts/playwright/sql_databases/image02.py index 6c4f685e86..ff134b2c4a 100644 --- a/scripts/playwright/sql_databases/image02.py +++ b/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: