Skip to content

Commit c64e003

Browse files
pashidlosclaude
andauthored
chore: refresh examples for sdk-python 5.0.0 (#5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3d0f2c9 commit c64e003

12 files changed

Lines changed: 175 additions & 28 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: pip
4+
directories:
5+
- "/playwright"
6+
- "/selenium"
7+
schedule:
8+
interval: weekly
9+
groups:
10+
pip-minor-patch:
11+
patterns:
12+
- "*"
13+
update-types:
14+
- minor
15+
- patch
16+
pip-major:
17+
patterns:
18+
- "*"
19+
update-types:
20+
- major
21+
pip-security:
22+
applies-to: security-updates
23+
patterns:
24+
- "*"
25+
26+
- package-ecosystem: docker-compose
27+
directory: "/.github/vrt"
28+
schedule:
29+
interval: weekly
30+
groups:
31+
docker:
32+
patterns:
33+
- "*"
34+
35+
- package-ecosystem: github-actions
36+
directory: "/"
37+
schedule:
38+
interval: weekly
39+
groups:
40+
github-actions:
41+
patterns:
42+
- "*"

‎.github/vrt/docker-compose.yml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
api:
3+
image: visualregressiontracker/api:6.0.0-rc1
4+
environment:
5+
DATABASE_URL: postgresql://vrt:vrt@postgres:5432/vrt
6+
JWT_SECRET: ci
7+
APP_FRONTEND_URL: http://localhost:8080
8+
BODY_PARSER_JSON_LIMIT: 5mb
9+
ports:
10+
- "4200:3000"
11+
depends_on:
12+
migration:
13+
condition: service_completed_successfully
14+
migration:
15+
image: visualregressiontracker/migration:6.0.0-rc1
16+
environment:
17+
DATABASE_URL: postgresql://vrt:vrt@postgres:5432/vrt
18+
DEFAULT_USER_EMAIL: visual-regression-tracker@example.com
19+
DEFAULT_USER_PASSWORD: "123456"
20+
DEFAULT_USER_API_KEY: DEFAULTUSERAPIKEYTOBECHANGED
21+
depends_on:
22+
postgres:
23+
condition: service_healthy
24+
postgres:
25+
image: postgres:17
26+
environment:
27+
POSTGRES_USER: vrt
28+
POSTGRES_PASSWORD: vrt
29+
POSTGRES_DB: vrt
30+
healthcheck:
31+
test: ["CMD-SHELL", "pg_isready -d vrt -U vrt"]
32+
interval: 2s
33+
retries: 30

‎.github/workflows/ci.yml‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
example:
17+
name: ${{ matrix.example }}
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
example: [playwright, selenium]
23+
defaults:
24+
run:
25+
working-directory: ${{ matrix.example }}
26+
env:
27+
VRT_APIURL: http://localhost:4200
28+
VRT_APIKEY: DEFAULTUSERAPIKEYTOBECHANGED
29+
VRT_PROJECT: Default project
30+
VRT_BRANCHNAME: master
31+
VRT_ENABLESOFTASSERT: "true"
32+
steps:
33+
- uses: actions/checkout@v7
34+
- name: Start Visual Regression Tracker
35+
working-directory: .github/vrt
36+
run: docker compose up -d --quiet-pull
37+
- uses: actions/setup-python@v7
38+
with:
39+
python-version: "3.14"
40+
cache: pip
41+
cache-dependency-path: ${{ matrix.example }}/requirements.txt
42+
- run: pip install -r requirements.txt
43+
- if: matrix.example == 'playwright'
44+
run: playwright install --with-deps chromium
45+
- name: Wait for Visual Regression Tracker
46+
run: timeout 180 bash -c 'until curl -s -o /dev/null http://localhost:4200; do sleep 2; done'
47+
- run: python example.py

‎README.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
# List of examples
2-
* [Selenium + SDK](https://github.com/Visual-Regression-Tracker/examples-python/tree/master/selenium)
3-
* [Playwright + SDK](https://github.com/Visual-Regression-Tracker/examples-python/tree/master/playwright)
1+
# Visual Regression Tracker examples for Python
2+
3+
Both examples use [sdk-python](https://github.com/Visual-Regression-Tracker/sdk-python) 5.0.0 from PyPI (Python 3.10 or later) and open https://the-internet.herokuapp.com headless:
4+
5+
- [Selenium + SDK](selenium)
6+
- [Playwright + SDK](playwright)

‎playwright/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# How to use
2-
* Install dependencies `$ pip install -r requirements.txt`
3-
* Copy configuration file `vrt.json` into directory.
4-
* Run tests `$ python example.py`
2+
3+
- Install dependencies: `pip install -r requirements.txt`
4+
- Install the browser: `playwright install chromium`
5+
- Copy `vrt.json.example` to `vrt.json` and set your connection, or use `VRT_*` environment variables
6+
- Run the example: `python example.py`

‎playwright/example.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from playwright.sync_api import sync_playwright
22

3-
from visual_regression_tracker import Config, IgnoreArea
3+
from visual_regression_tracker import IgnoreArea
44
from visual_regression_tracker.playwright import PlaywrightVisualRegressionTracker, PageTrackOptions, \
55
PageScreenshotOptions, Agent, ElementHandleScreenshotOptions, ElementHandleTrackOptions
66

77
playwright = sync_playwright().start()
88
browserType = playwright.chromium
9-
browser = browserType.launch(headless=False)
9+
browser = browserType.launch()
1010
page = browser.new_page()
11-
page.goto('https://www.python.org/')
1211

1312
try:
14-
vrt = PlaywrightVisualRegressionTracker(browserType, None)
13+
page.goto('https://the-internet.herokuapp.com/')
14+
vrt = PlaywrightVisualRegressionTracker(browserType)
1515

1616
with vrt:
1717
vrt.trackPage(page, 'Home page', PageTrackOptions(
@@ -34,7 +34,7 @@
3434
)
3535
))
3636

37-
vrt.trackElementHandle(page.query_selector(".search-the-site"), "Search form", ElementHandleTrackOptions(
37+
vrt.trackElementHandle(page.query_selector("h1.heading"), "Heading", ElementHandleTrackOptions(
3838
diffTollerancePercent=1.34,
3939
ignoreAreas=[
4040
IgnoreArea(

‎playwright/requirements.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
playwright >= 1.10
2-
visual_regression_tracker >= 4.8.0
1+
visual-regression-tracker[playwright]==5.0.0
2+
playwright==1.64.1

‎playwright/vrt.json.example‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"apiUrl": "http://localhost:4200",
3+
"apiKey": "DEFAULTUSERAPIKEYTOBECHANGED",
4+
"project": "Default project",
5+
"branchName": "master",
6+
"enableSoftAssert": true
7+
}

‎selenium/README.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# How to use
2-
* Install dependencies `$ pip install -r requirements.txt`
3-
* Copy configuration file `vrt.json` into directory.
4-
* Run tests `$ python example.py`
2+
3+
- Install dependencies: `pip install -r requirements.txt`
4+
- Copy `vrt.json.example` to `vrt.json` and set your connection, or use `VRT_*` environment variables
5+
- Run the example: `python example.py`

‎selenium/example.py‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
from selenium import webdriver
2-
from webdriver_manager.chrome import ChromeDriverManager
3-
from visual_regression_tracker import VisualRegressionTracker, Config, TestRun
2+
from selenium.webdriver.common.by import By
3+
from visual_regression_tracker import VisualRegressionTracker, TestRun
44

5-
driver = webdriver.Chrome(ChromeDriverManager().install())
5+
options = webdriver.ChromeOptions()
6+
options.add_argument('--headless=new')
7+
options.add_argument('--window-size=1280,1024')
8+
driver = webdriver.Chrome(options=options)
69
vrt = VisualRegressionTracker()
710

811
with vrt:
912
try:
10-
driver.get("http://www.python.org")
13+
driver.get('https://the-internet.herokuapp.com/')
1114
vrt.track(TestRun(
12-
name='Image name',
15+
name='Home page',
16+
imageBase64=driver.get_screenshot_as_base64(),
17+
))
18+
19+
driver.find_element(By.LINK_TEXT, 'Checkboxes').click()
20+
vrt.track(TestRun(
21+
name='Checkboxes page',
1322
imageBase64=driver.get_screenshot_as_base64(),
14-
diffTollerancePercent=0,
15-
os='Mac',
1623
browser='Chrome',
17-
viewport='800x600',
24+
viewport='1280x1024',
1825
device='PC',
1926
))
2027
finally:

0 commit comments

Comments
 (0)