Add responsive snapshot capture and CORS iframe support#124
Add responsive snapshot capture and CORS iframe support#124bhokaremoin wants to merge 11 commits intomainfrom
Conversation
…g cookies using context object
…lidating changes and test
There was a problem hiding this comment.
Pull request overview
This PR enhances the Percy Playwright Python SDK’s snapshot fidelity and capabilities by adding multi-viewport (“responsive”) DOM snapshot capture, serializing cross-origin iframes, and including cookie context in snapshots. It also tightens CI quality gates by enforcing 100% coverage and updates Playwright/Percy CLI dependencies to support the new behavior.
Changes:
- Add responsive snapshot capture (
capture_responsive_dom, widths config lookup, resize/reload/sleep helpers). - Extend DOM snapshot payload to include cookies and cross-origin iframe snapshots (
get_serialized_dom,process_frame). - Add/expand tests and enforce 100% coverage in CI; bump Playwright and Percy CLI versions.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
percy/screenshot.py |
Implements responsive capture, cookie capture, and CORS iframe serialization; introduces CLI logging helper. |
percy/__init__.py |
Adds pragma: no cover handling for defensive import fallback. |
tests/test_screenshot.py |
Updates/expands unit and integration tests for new snapshot payload and helpers. |
tests/test_init.py |
Adds tests for backwards-compatible wrapper functions and version export. |
requirements.txt |
Updates Playwright pin to 1.40.*. |
package.json |
Updates @percy/cli dev dependency to ^1.31.9-beta.5. |
development.txt |
Adds coverage dependency for local/CI reporting. |
Makefile |
Adds coverage targets and enforces 100% coverage. |
.github/workflows/test.yml |
Runs make test-coverage in CI. |
.coveragerc |
Adds coverage configuration and fail-under threshold. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@bhokaremoin I've opened a new pull request, #126, to work on those changes. Once the pull request is ready, I'll request review from you. |
… element is not found (#126) * Initial plan * Fix process_frame() to return None when iframe_data is missing or lacks percyElementId Co-authored-by: bhokaremoin <75439850+bhokaremoin@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bhokaremoin <75439850+bhokaremoin@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
percy/init.py:13
- With 100% coverage enforced, only marking the
except ImportErrorline as# pragma: no coverwon’t exclude the fallbackpercy_snapshot()function body from coverage. In normal installs thetryimport succeeds, so lines 9-13 will remain uncovered and will failcoverage report --fail-under=100. Add# pragma: no coverto the fallbackdef/raiselines (or restructure so the whole fallback is excluded) to keep coverage deterministic.
except ImportError: # pragma: no cover
# This is defensive code in case percy_snapshot is not available
def percy_snapshot(page, *a, **kw):
raise ModuleNotFoundError(
"[percy] `percy-playwright-python` package is not installed, "
"please install it to use percy_snapshot command"
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…f github.com:percy/percy-playwright-python into PPLT-4951-responsive-capture-and-cors-iframe-capture
Overview
Adds support for responsive snapshot capture, CORS iframe serialization, and cookie context capture to improve Percy snapshot fidelity and enable multi-width testing.
Key Features
1. Responsive Snapshot Capture
Enables capturing DOM snapshots at multiple viewport widths in a single call.
capture_responsive_dom()to iterate through configured widthsget_responsive_widths()PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT,PERCY_RESPONSIVE_CAPTURE_RELOAD_PAGE,RESPONSIVE_CAPTURE_SLEEP_TIMEUsage:
2. Cookie Context Capture
Snapshots now include page cookies to preserve authentication and session state.
get_serialized_dom()to capturepage.context.cookies(){"html": "...", "cookies": [...]}3. CORS Iframe Capture
Captures cross-origin iframe content previously inaccessible due to browser security.
process_frame()to serialize cross-origin framesCode Changes
percy/screenshot.py:
is_percy_enabled()→_is_percy_enabled()returns dict instead of stringget_serialized_dom()with CORS iframe supportlog()helperTests:
tests/test_init.pyfor wrapper testsInfrastructure:
1.28.*→1.40.*^1.31.9-beta.5Breaking Changes
^1.31.9-beta.5or higher