-
Notifications
You must be signed in to change notification settings - Fork 6
feat(advanced): PER-8195 — advanced example for percy-selenium (Python) #22
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7ec73cf
feat(advanced): PER-8195 Phase 1 stub — matrix.yml + README
Shivanshu-07 dbb68ea
feat(advanced): PER-8195 Phase 1 — add advanced example for percy-sel…
Shivanshu-07 c123988
fix(ci): run advanced job like the basic job; drop unpublished shared…
Shivanshu-07 1e84d2f
ci: limit GITHUB_TOKEN to read-only permissions (PER-8195)
Shivanshu-07 9911e53
fix: vendor todomvc CSS locally so advanced snapshots render styled (…
Shivanshu-07 b091e77
ci: replace removed percy/exec-action with direct percy exec run (PER…
Shivanshu-07 257f921
Merge remote-tracking branch 'origin/master' into per-8195-phase-1-se…
Shivanshu-07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .venv/ | ||
| __pycache__/ | ||
| *.pyc | ||
| advanced-requests.json | ||
| .pytest_cache/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # PER-8195 — advanced example global config for percy-selenium (python). | ||
| # Per-snapshot options in tests/test_todomvc_advanced.py override these. | ||
|
|
||
| version: 2 | ||
|
|
||
| snapshot: | ||
| widths: [375, 1280] | ||
| min-height: 1024 | ||
| percy-css: | | ||
| .new-todo::placeholder { color: #999 !important; } | ||
|
|
||
| discovery: | ||
| allowed-hostnames: | ||
| - localhost | ||
| network-idle-timeout: 500 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| VENV=.venv/bin | ||
| REQUIREMENTS=requirements.txt | ||
|
|
||
| $(VENV): | ||
| python3 -m venv .venv | ||
| $(VENV)/python3 -m pip install --upgrade pip | ||
|
|
||
| $(VENV)/.deps: $(REQUIREMENTS) | $(VENV) | ||
| $(VENV)/pip install -r $(REQUIREMENTS) | ||
| touch $(VENV)/.deps | ||
|
|
||
| .PHONY: venv install clean test test-advanced test-advanced-ci | ||
|
|
||
| venv install: $(VENV)/.deps | ||
|
|
||
| clean: | ||
| rm -rf .venv .pytest_cache __pycache__ tests/__pycache__ advanced-requests.json | ||
|
|
||
| # Local run against a real PERCY_TOKEN. | ||
| test test-advanced: install | ||
| npx --no-install percy exec -- $(VENV)/python3 -m pytest tests/ -v | ||
|
|
||
| # CI run in --testing mode + capture requests file. | ||
| test-advanced-ci: install | ||
| PERCY_TOKEN=fake_token npx --no-install percy exec --testing -- bash -c '\ | ||
| $(VENV)/python3 -m pytest tests/ -v; \ | ||
| ec=$$?; \ | ||
| curl -fsS http://localhost:5338/test/requests > advanced-requests.json || true; \ | ||
| exit $$ec' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Advanced Percy + Selenium-Python example | ||
|
|
||
| This directory exercises the full applicable Percy SDK feature surface for `percy-selenium` (Python). See the basic example at the repo root for the minimum integration. | ||
|
|
||
| ## What this example covers | ||
|
|
||
| A pytest suite (`tests/test_todomvc_advanced.py`) where each test exercises one row of the [Percy SDK Advanced Feature Matrix](../../../docs/advanced-example-feature-matrix.md). Global SDK config — readiness preset, default widths, percyCSS, discovery — lives in `.percy.yml`. | ||
|
|
||
| Note: `scope`, `domTransformation`, `regions`, `discovery` are marked `N/A` — not exposed in `percy-selenium` 2.1.2 kwargs surface. | ||
|
|
||
| ## Run locally | ||
|
|
||
| ```bash | ||
| cd advanced | ||
| make install # creates .venv, installs requirements.txt | ||
| export PERCY_TOKEN="<your token>" # do NOT commit this | ||
| make test | ||
| ``` | ||
|
|
||
| To run without a real token (CI assertion mode): | ||
|
|
||
| ```bash | ||
| make test-advanced-ci # uses --testing + PERCY_TOKEN=fake_token + captures /test/requests | ||
| ``` | ||
|
|
||
| The CI variant asserts every matrix row appears in the captured POST bodies at the local `/test/requests` endpoint. No real Percy build is created. | ||
|
|
||
| ## Coverage matrix | ||
|
|
||
| States: `Covered` / `N/A — <reason>` / `Planned` / `Deprecated`. Source of truth is [`matrix.yml`](./matrix.yml). | ||
|
|
||
| | Feature | State | Test | | ||
| |---|---|---| | ||
| | widths | Covered | `test_exercises_widths` | | ||
| | minHeight (`min_height`) | Covered | `test_exercises_min_height` | | ||
| | enableJavaScript (`enable_javascript`) | Covered | `test_exercises_enable_javascript` | | ||
| | responsiveSnapshotCapture (`responsive_snapshot_capture`) | Covered | `test_exercises_responsive_snapshot_capture` | | ||
| | readiness preset | Covered | `test_exercises_readiness_preset` | | ||
| | sync | Covered | `test_exercises_sync` | | ||
| | labels | Covered | `test_exercises_labels` | | ||
| | testCase (`test_case`) | Covered | `test_exercises_test_case` | | ||
| | devicePixelRatio (`device_pixel_ratio`) | Covered | `test_exercises_device_pixel_ratio` | | ||
| | browsers override | Covered | `test_exercises_browsers` | | ||
| | snake_case + camelCase dual naming | Covered | `test_exercises_snake_case_camelcase_dual_naming` | | ||
| | percyCSS | Covered | global via `.percy.yml` | | ||
| | cross-origin iframe handling | Covered | automatic via `percy-selenium >= 2.1.2` | | ||
| | `.percy.yml` global config | Covered | `.percy.yml` consumed at build start | | ||
| | environment info reporting | Covered | automatic via `percy-selenium` client info | | ||
| | PERCY_SERVER_ADDRESS via env | Covered | CI advanced job picks up `PERCY_SERVER_ADDRESS` | | ||
| | `disable_shadow_dom` | Planned | — | | ||
| | `enable_layout` | Planned | — | | ||
| | `scope` | N/A | Not exposed in SDK 2.1.2 | | ||
| | `domTransformation` | N/A | Not exposed in SDK 2.1.2 | | ||
| | `regions` per-snapshot | N/A | `create_region` is Automate-only | | ||
| | `discovery` per-snapshot | N/A | discovery is per-build only | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """PER-8195 — pytest fixtures: HTTP server for the TodoMVC app, headless | ||
| firefox driver. Server roots two directories up so the basic TodoMVC files | ||
| served at /index.html land at http://localhost:8006/.""" | ||
|
|
||
| from http.server import HTTPServer, SimpleHTTPRequestHandler | ||
| from threading import Thread | ||
| import functools | ||
| import os | ||
| import pytest | ||
| from selenium.webdriver import Firefox, FirefoxOptions | ||
|
|
||
| PORT = int(os.environ.get("PORT_NUMBER", "8006")) | ||
| TEST_URL = f"http://localhost:{PORT}" | ||
| APP_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def http_server(): | ||
| handler = functools.partial(SimpleHTTPRequestHandler, directory=APP_ROOT) | ||
| httpd = HTTPServer(("localhost", PORT), handler) | ||
| thread = Thread(target=httpd.serve_forever, daemon=True) | ||
| thread.start() | ||
| yield httpd | ||
| httpd.shutdown() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def driver(http_server): | ||
| options = FirefoxOptions() | ||
| options.add_argument("-headless") | ||
| if os.environ.get("FIREFOX_BINARY"): | ||
| options.binary_location = os.environ["FIREFOX_BINARY"] | ||
| browser = Firefox(options=options) | ||
| browser.implicitly_wait(10) | ||
| yield browser | ||
| browser.quit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # PER-8195 Phase 1 — Selenium-Python matrix-row mapping. | ||
| # Test code: tests/test_todomvc_advanced.py (pytest). | ||
|
|
||
| sdk: selenium-python | ||
| package: percy-selenium | ||
| language: python | ||
| sdk_min_version: '2.1.2' | ||
| cli_min_version: '1.31.13' | ||
|
|
||
| rows: | ||
| - id: widths | ||
| state: covered | ||
| test: 'test_exercises_widths' | ||
| - id: min_height | ||
| state: covered | ||
| test: 'test_exercises_min_height' | ||
| - id: enable_javascript | ||
| state: covered | ||
| test: 'test_exercises_enable_javascript' | ||
| - id: responsive_snapshot_capture | ||
| state: covered | ||
| test: 'test_exercises_responsive_snapshot_capture' | ||
| - id: readiness_preset | ||
| state: covered | ||
| test: 'test_exercises_readiness_preset' | ||
| - id: sync | ||
| state: covered | ||
| test: 'test_exercises_sync' | ||
| - id: percy_css | ||
| state: covered | ||
| test: 'global via .percy.yml snapshot.percy-css' | ||
| - id: labels | ||
| state: covered | ||
| test: 'test_exercises_labels' | ||
| - id: test_case | ||
| state: covered | ||
| test: 'test_exercises_test_case' | ||
| - id: device_pixel_ratio | ||
| state: covered | ||
| test: 'test_exercises_device_pixel_ratio' | ||
| - id: browsers | ||
| state: covered | ||
| test: 'test_exercises_browsers' | ||
|
|
||
| # Python-specific. | ||
| - id: snake_case_camelcase_dual_naming | ||
| state: covered | ||
| test: 'test_exercises_snake_case_camelcase_dual_naming' | ||
| - id: cross_origin_iframe_handling | ||
| state: covered | ||
| test: 'automatic via percy-selenium >= 2.1.2' | ||
|
|
||
| - id: disable_shadow_dom | ||
| state: planned | ||
| - id: enable_layout | ||
| state: planned | ||
|
|
||
| # Options not exposed as kwargs in percy-selenium (per SDK source). | ||
| - id: scope | ||
| state: n_a | ||
| reason: 'Not exposed in percy-selenium 2.1.2 kwargs surface.' | ||
| - id: dom_transformation | ||
| state: n_a | ||
| reason: 'Not exposed in percy-selenium 2.1.2 kwargs surface.' | ||
| - id: regions | ||
| state: n_a | ||
| reason: 'create_region helper exists for Automate; not used in DOM snapshot path in 2.1.2.' | ||
| - id: discovery | ||
| state: n_a | ||
| reason: 'discovery is per-build, not per-snapshot in this SDK.' | ||
|
|
||
| - id: env_percy_server_address | ||
| state: covered | ||
| test: 'CI: advanced job sets PERCY_SERVER_ADDRESS via env' | ||
| - id: percy_yml_global_config | ||
| state: covered | ||
| test: 'global config consumed via .percy.yml' | ||
| - id: environment_info_reporting | ||
| state: covered | ||
| test: 'automatic via percy-selenium client info' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| selenium>=4.9.0 | ||
| percy-selenium>=2.1.2 | ||
| pytest>=7.4.0 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.