Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: 2
updates:
- package-ecosystem: pip
directories:
- "/playwright"
- "/selenium"
schedule:
interval: weekly
groups:
pip-minor-patch:
patterns:
- "*"
update-types:
- minor
- patch
pip-major:
patterns:
- "*"
update-types:
- major
pip-security:
applies-to: security-updates
patterns:
- "*"

- package-ecosystem: docker-compose
directory: "/.github/vrt"
schedule:
interval: weekly
groups:
docker:
patterns:
- "*"

- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
groups:
github-actions:
patterns:
- "*"
33 changes: 33 additions & 0 deletions .github/vrt/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:
api:
image: visualregressiontracker/api:6.0.0-rc1
environment:
DATABASE_URL: postgresql://vrt:vrt@postgres:5432/vrt
JWT_SECRET: ci
APP_FRONTEND_URL: http://localhost:8080
BODY_PARSER_JSON_LIMIT: 5mb
ports:
- "4200:3000"
depends_on:
migration:
condition: service_completed_successfully
migration:
image: visualregressiontracker/migration:6.0.0-rc1
environment:
DATABASE_URL: postgresql://vrt:vrt@postgres:5432/vrt
DEFAULT_USER_EMAIL: visual-regression-tracker@example.com
DEFAULT_USER_PASSWORD: "123456"
DEFAULT_USER_API_KEY: DEFAULTUSERAPIKEYTOBECHANGED
depends_on:
postgres:
condition: service_healthy
postgres:
image: postgres:17
environment:
POSTGRES_USER: vrt
POSTGRES_PASSWORD: vrt
POSTGRES_DB: vrt
healthcheck:
test: ["CMD-SHELL", "pg_isready -d vrt -U vrt"]
interval: 2s
retries: 30
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI

on:
push:
branches: [master]
pull_request:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
example:
name: ${{ matrix.example }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
example: [playwright, selenium]
defaults:
run:
working-directory: ${{ matrix.example }}
env:
VRT_APIURL: http://localhost:4200
VRT_APIKEY: DEFAULTUSERAPIKEYTOBECHANGED
VRT_PROJECT: Default project
VRT_BRANCHNAME: master
VRT_ENABLESOFTASSERT: "true"
steps:
- uses: actions/checkout@v7
- name: Start Visual Regression Tracker
working-directory: .github/vrt
run: docker compose up -d --quiet-pull
- uses: actions/setup-python@v7
with:
python-version: "3.14"
cache: pip
cache-dependency-path: ${{ matrix.example }}/requirements.txt
- run: pip install -r requirements.txt
- if: matrix.example == 'playwright'
run: playwright install --with-deps chromium
- name: Wait for Visual Regression Tracker
run: timeout 180 bash -c 'until curl -s -o /dev/null http://localhost:4200; do sleep 2; done'
- run: python example.py
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# List of examples
* [Selenium + SDK](https://github.com/Visual-Regression-Tracker/examples-python/tree/master/selenium)
* [Playwright + SDK](https://github.com/Visual-Regression-Tracker/examples-python/tree/master/playwright)
# Visual Regression Tracker examples for Python

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:

- [Selenium + SDK](selenium)
- [Playwright + SDK](playwright)
8 changes: 5 additions & 3 deletions playwright/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# How to use
* Install dependencies `$ pip install -r requirements.txt`
* Copy configuration file `vrt.json` into directory.
* Run tests `$ python example.py`

- Install dependencies: `pip install -r requirements.txt`
- Install the browser: `playwright install chromium`
- Copy `vrt.json.example` to `vrt.json` and set your connection, or use `VRT_*` environment variables
- Run the example: `python example.py`
10 changes: 5 additions & 5 deletions playwright/example.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from playwright.sync_api import sync_playwright

from visual_regression_tracker import Config, IgnoreArea
from visual_regression_tracker import IgnoreArea
from visual_regression_tracker.playwright import PlaywrightVisualRegressionTracker, PageTrackOptions, \
PageScreenshotOptions, Agent, ElementHandleScreenshotOptions, ElementHandleTrackOptions

playwright = sync_playwright().start()
browserType = playwright.chromium
browser = browserType.launch(headless=False)
browser = browserType.launch()
page = browser.new_page()
page.goto('https://www.python.org/')

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

with vrt:
vrt.trackPage(page, 'Home page', PageTrackOptions(
Expand All @@ -34,7 +34,7 @@
)
))

vrt.trackElementHandle(page.query_selector(".search-the-site"), "Search form", ElementHandleTrackOptions(
vrt.trackElementHandle(page.query_selector("h1.heading"), "Heading", ElementHandleTrackOptions(
diffTollerancePercent=1.34,
ignoreAreas=[
IgnoreArea(
Expand Down
4 changes: 2 additions & 2 deletions playwright/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
playwright >= 1.10
visual_regression_tracker >= 4.8.0
visual-regression-tracker[playwright]==5.0.0
playwright==1.64.1
7 changes: 7 additions & 0 deletions playwright/vrt.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"apiUrl": "http://localhost:4200",
"apiKey": "DEFAULTUSERAPIKEYTOBECHANGED",
"project": "Default project",
"branchName": "master",
"enableSoftAssert": true
}
7 changes: 4 additions & 3 deletions selenium/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# How to use
* Install dependencies `$ pip install -r requirements.txt`
* Copy configuration file `vrt.json` into directory.
* Run tests `$ python example.py`

- Install dependencies: `pip install -r requirements.txt`
- Copy `vrt.json.example` to `vrt.json` and set your connection, or use `VRT_*` environment variables
- Run the example: `python example.py`
23 changes: 15 additions & 8 deletions selenium/example.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from visual_regression_tracker import VisualRegressionTracker, Config, TestRun
from selenium.webdriver.common.by import By
from visual_regression_tracker import VisualRegressionTracker, TestRun

driver = webdriver.Chrome(ChromeDriverManager().install())
options = webdriver.ChromeOptions()
options.add_argument('--headless=new')
options.add_argument('--window-size=1280,1024')
driver = webdriver.Chrome(options=options)
vrt = VisualRegressionTracker()

with vrt:
try:
driver.get("http://www.python.org")
driver.get('https://the-internet.herokuapp.com/')
vrt.track(TestRun(
name='Image name',
name='Home page',
imageBase64=driver.get_screenshot_as_base64(),
))

driver.find_element(By.LINK_TEXT, 'Checkboxes').click()
vrt.track(TestRun(
name='Checkboxes page',
imageBase64=driver.get_screenshot_as_base64(),
diffTollerancePercent=0,
os='Mac',
browser='Chrome',
viewport='800x600',
viewport='1280x1024',
device='PC',
))
finally:
Expand Down
6 changes: 2 additions & 4 deletions selenium/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
pytest
selenium
webdriver_manager
visual_regression_tracker >= 4.7.0
visual-regression-tracker==5.0.0
selenium==4.52.0
7 changes: 7 additions & 0 deletions selenium/vrt.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"apiUrl": "http://localhost:4200",
"apiKey": "DEFAULTUSERAPIKEYTOBECHANGED",
"project": "Default project",
"branchName": "master",
"enableSoftAssert": true
}
Loading