-
Notifications
You must be signed in to change notification settings - Fork 0
Add verification test script using Playwright #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| *.log | ||
| *.png | ||
| __pycache__/ |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| from playwright.sync_api import sync_playwright | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import time | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def run(playwright): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| browser = playwright.chromium.launch(headless=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| page = browser.new_page() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Capture console messages | ||||||||||||||||||||||||||||||||||||||||||||||||||
| page.on("console", lambda msg: print(f"CONSOLE: {msg.text}")) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| page.on("pageerror", lambda err: print(f"PAGE ERROR: {err}")) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Fail the test on console errors or page errors instead of just printing them Right now these handlers only log issues, so the test can pass despite serious runtime problems. Instead, collect console/page messages and assert that none are of type
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Navigating to http://localhost:8000/index.html") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| page.goto("http://localhost:8000/index.html") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Wait for potential initial animations or loading | ||||||||||||||||||||||||||||||||||||||||||||||||||
| time.sleep(2) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Taking initial screenshot...") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+13
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Avoid fixed Using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| page.screenshot(path="tests/initial.png") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Clarify how screenshots are used (assertions or baselines) and consider naming/output structure Right now the screenshots are only written to disk and never asserted. If they’re intended for visual regression, consider comparing them to a baseline or at least publishing them as CI artifacts. It may also help to write them under a dedicated directory (e.g. Suggested implementation: import os
import time # Wait for potential initial animations or loading
time.sleep(2)
# Take an initial screenshot for debugging / visual inspection (e.g. CI artifacts)
screenshot_dir = os.path.join("tests", "screenshots")
os.makedirs(screenshot_dir, exist_ok=True)
print("Taking initial screenshot...")
page.screenshot(path=os.path.join(screenshot_dir, "initial.png"))To fully implement the suggestion about CI artifacts and/or baselines, you will also want to:
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Check for key elements (the HUD) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if page.locator(".hud").is_visible(): | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Use assertions for HUD visibility instead of printing, and handle missing locator robustly This only logs HUD visibility and doesn’t affect the test result. Instead, assert that Suggested implementation: print("Taking initial screenshot...")
page.screenshot(path="tests/initial.png")
# Assert key elements (the HUD) are present and visible
hud = page.locator(".hud")
expect(hud).to_be_visible(timeout=5000)To fully support this change, ensure that from playwright.sync_api import expectIf the file already imports from |
||||||||||||||||||||||||||||||||||||||||||||||||||
| print("HUD is visible.") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| print("HUD is NOT visible.") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Simulate mouse movement | ||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Simulating mouse movement...") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| page.mouse.move(100, 100) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| time.sleep(0.5) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| page.mouse.move(500, 500) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| time.sleep(0.5) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # Simulate click (Warp) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Simulating click (Warp)...") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| page.mouse.down() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Add assertions around the mouse interactions to verify the "warp" effect, not just exercise it These interactions are only executed, not validated. To ensure the warp effect and HUD behavior are actually tested, add assertions on observable outcomes (e.g., DOM/CSS changes, element visibility, or a pixel/screenshot comparison) rather than just confirming no exceptions are thrown. Suggested implementation: print("Taking initial screenshot...")
page.screenshot(path="tests/initial.png")
hud = page.locator(".hud")
assert hud.count() > 0, "Expected HUD element '.hud' to exist on the page"
initial_hud_box = hud.bounding_box()
# Check for key elements (the HUD)
if hud.is_visible():
print("HUD is visible.")
else:
print("HUD is NOT visible.")
assert hud.is_visible(), "HUD should be visible before warp interaction"
# Simulate mouse movement intended to trigger the warp effect
print("Simulating mouse movement...")
page.mouse.move(100, 100)
page.wait_for_timeout(500)
page.mouse.move(500, 500)
page.wait_for_timeout(500)
# Simulate click (Warp)
print("Simulating click (Warp)...")
page.mouse.down()
page.wait_for_timeout(1000) # Hold for a bit to let the warp effect happen
print("Taking warping screenshot...")
page.screenshot(path="tests/warping.png")
page.mouse.up()
page.wait_for_timeout(1000)
# Re-query HUD to avoid stale references and validate warp effect
hud_after_warp = page.locator(".hud")
assert hud_after_warp.is_visible(), "HUD should remain visible after warp interaction"
warped_hud_box = hud_after_warp.bounding_box()
assert (
initial_hud_box is not None and warped_hud_box is not None
), "HUD bounding boxes must be measurable"
# Assert that the HUD has visually changed position or size as a proxy for the warp effect
hud_position_changed = (
initial_hud_box["x"] != warped_hud_box["x"]
or initial_hud_box["y"] != warped_hud_box["y"]
or initial_hud_box["width"] != warped_hud_box["width"]
or initial_hud_box["height"] != warped_hud_box["height"]
)
assert hud_position_changed, "Expected HUD position or size to change after warp interaction"If the warp effect is represented by a specific DOM/CSS change (e.g., a class like |
||||||||||||||||||||||||||||||||||||||||||||||||||
| time.sleep(1) # Hold for a bit to let the warp effect happen | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Taking warping screenshot...") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| page.screenshot(path="tests/warping.png") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| page.mouse.up() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| time.sleep(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"ERROR: {e}") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+46
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Avoid swallowing exceptions so the test fails when something goes wrong Catching
Comment on lines
+8
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "test_portfolio.py" -type fRepository: AshrafMorningstar/3d-portfolio Length of output: 99 🏁 Script executed: cat -n ./tests/test_portfolio.py | head -60Repository: AshrafMorningstar/3d-portfolio Length of output: 1932 The test never fails because errors are only printed and exceptions are caught without being re-raised. Console/page errors, HUD invisibility, and exceptions are currently logged but do not cause test failure. The exception handler (lines 46–47) catches all errors and prints them without re-raising, causing the test to pass silently even when failures occur. 🐛 Proposed fix to assert failures- # Capture console messages
- page.on("console", lambda msg: print(f"CONSOLE: {msg.text}"))
- page.on("pageerror", lambda err: print(f"PAGE ERROR: {err}"))
+ console_errors = []
+ page_errors = []
+ # Capture console messages
+ def on_console(msg):
+ if msg.type == "error":
+ console_errors.append(msg.text)
+ print(f"CONSOLE: {msg.text}")
+ def on_page_error(err):
+ page_errors.append(str(err))
+ print(f"PAGE ERROR: {err}")
+ page.on("console", on_console)
+ page.on("pageerror", on_page_error)
@@
- if page.locator(".hud").is_visible():
- print("HUD is visible.")
- else:
- print("HUD is NOT visible.")
+ if not page.locator(".hud").is_visible():
+ raise AssertionError("HUD is NOT visible.")
+ print("HUD is visible.")
@@
- except Exception as e:
- print(f"ERROR: {e}")
+ if console_errors or page_errors:
+ raise AssertionError(
+ f"Console/page errors detected: {console_errors + page_errors}"
+ )
+ except Exception as e:
+ print(f"ERROR: {e}")
+ raise🧰 Tools🪛 Ruff (0.14.14)46-46: Do not catch blind exception: (BLE001) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| finally: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| browser.close() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| with sync_playwright() as playwright: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| run(playwright) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+52
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: wc -l tests/test_portfolio.pyRepository: AshrafMorningstar/3d-portfolio Length of output: 100 🏁 Script executed: cat -n tests/test_portfolio.pyRepository: AshrafMorningstar/3d-portfolio Length of output: 1932 Wrap Playwright execution in a test function. ✅ Proposed fix+def test_portfolio():
+ with sync_playwright() as playwright:
+ run(playwright)
-
-with sync_playwright() as playwright:
- run(playwright)Alternatively, if this file is intended as a standalone script, use an 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Structure this as a real test function (e.g. pytest) rather than a standalone script
As written, this is a manual verification script: it runs on import and uses prints instead of assertions. Please convert it into one or more
test_...functions (e.g.def test_portfolio_hud_visible(page): ...) using Playwright’s pytest integration/fixtures so it’s executed by the test runner and produces proper pass/fail results in CI.