Skip to content

Commit

Permalink
✨ Use @percy/cli (#9)
Browse files Browse the repository at this point in the history
* ✨ Use @percy/cli

* 👷 Use GitHub Actions

* 📝 Update README

* ✨ Minor updates

Update environment variables

Update log label for debugging

Use f-strings rather than string concatenation

Use /percy/healthcheck explicitly to check availability

Use functools.cache to cache healthcheck and percy/dom results

Provide serialization script with passed options

Print snapshot errors without debug logs

* 🎨 Follow language conventions with snake case

A camelCase percySnapshot is still provided for backwards compatibility

* 📝 Update README

Co-authored-by: Wil Wilsman <wil@wilwilsman.com>
  • Loading branch information
Robdel12 and wwilsman committed Feb 3, 2021
1 parent c5cffae commit 2934f12
Show file tree
Hide file tree
Showing 21 changed files with 421 additions and 2,306 deletions.
20 changes: 0 additions & 20 deletions .circleci/config.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: '💥 Breaking Changes'
labels:
- breaking
- title: '✨ Enhancements'
labels:
- feature
- enhancement
- title: '🐛 Bug Fixes'
labels:
- fix
- bugfix
- bug
- title: '🏗 Maintenance'
labels:
- chore
- dependencies
change-title-escapes: '\<*_&#@'
version-resolver:
major:
labels:
- breaking
minor:
labels:
- feature
- enhancement
default: patch
template: '$CHANGES'
11 changes: 11 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Changelog
on:
push:
branches: [master]
jobs:
update_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lint
on: push
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.x
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: v1/${{ runner.os }}/pip/${{ hashFiles('{requirements,development}.txt') }}
restore-keys: v1/${{ runner.os }}/pip/
- run: make lint
20 changes: 20 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Release
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.x
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: v1/${{ runner.os }}/pip/${{ hashFiles('{requirements,development}.txt') }}
restore-keys: v1/${{ runner.os }}/pip/
- run: make release
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test
on: push
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.x
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: v1/${{ runner.os }}/pip/${{ hashFiles('{requirements,development}.txt') }}
restore-keys: v1/${{ runner.os }}/pip/
- run: make test
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_modules
geckodriver.log
*.pyc
.venv
*.egg-info
dist
build
*.egg-info
*.log
**/__pycache__
13 changes: 13 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[MASTER]
fail-under=10.0
disable=
broad-except,
global-statement,
invalid-name,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
multiple-statements,
no-member,
no-value-for-parameter,
redefined-builtin,
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.0
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
VENV=.venv/bin
REQUIREMENTS=$(wildcard requirements.txt development.txt)
MARKER=.initialized-with-makefile
VENVDEPS=$(REQUIREMENTS setup.py)

$(VENV):
python -m venv .venv
$(VENV)/python -m pip install --upgrade pip setuptools wheel

$(VENV)/$(MARKER): $(VENVDEPS) | $(VENV)
$(VENV)/pip install $(foreach path,$(REQUIREMENTS),-r $(path))
touch $(VENV)/$(MARKER)

.PHONY: venv lint test clean build release

venv: $(VENV)/$(MARKER)

lint: venv
$(VENV)/pylint percy/* tests/*

test: venv
$(VENV)/python -m unittest tests.test_snapshot

clean:
rm -rf $$(cat .gitignore)

build: venv
$(VENV)/python setup.py sdist bdist_wheel

release: venv
$(VENV)/twine upload dist/* --username __token__ --password ${PYPI_TOKEN}
77 changes: 64 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,75 @@
# percy-python-selenium
[![CircleCI](https://circleci.com/gh/percy/percy-python-selenium.svg?style=svg)](https://circleci.com/gh/percy/percy-python-selenium)
# percy-selenium-python
![Test](https://github.com/percy/percy-python-selenium/workflows/Test/badge.svg)

[Percy](https://percy.io) visual testing for Python Selenium.

## Quick start
## Installation

npm install `@percy/cli`:

```sh-session
$ npm install --save-dev @percy/cli
```

pip install Percy selenium package:

```ssh-session
$ pip install percy-selenium
```

## Usage

This is an example test using the `percy_snapshot` function.

- Install `@percy/agent` from NPM: `npm i -D @percy/agent`
- Install the Python SDK: `pip install percy-python-selenium`
- Import `percySnapshot` in your test file: `from percy import percySnapshot`
- Add a `percySnapshot` call to your test:
``` python
from percy import percySnapshot
from percy import percy_snapshot

browser = webdriver.Firefox()
browser.get('http://example.com')
# take a snapshot
percySnapshot(browser=browser, name='Home page')
percy_snapshot(browser=browser, name='Python example')
```

Running the test above normally will result in the following log:

```sh-session
[percy] Percy is not running, disabling snapshots
```

When running with [`percy
exec`](https://github.com/percy/cli/tree/master/packages/cli-exec#percy-exec), and your project's
`PERCY_TOKEN`, a new Percy build will be created and snapshots will be uploaded to your project.

```sh-session
$ export PERCY_TOKEN=[your-project-token]
$ percy exec -- [python test command]
[percy] Percy has started!
[percy] Created build #1: https://percy.io/[your-project]
[percy] Snapshot taken "Python example"
[percy] Stopping percy...
[percy] Finalized build #1: https://percy.io/[your-project]
[percy] Done!
```

## Configuration

`percy_snapshot(driver, name[, **kwargs])`

- `driver` (**required**) - A selenium-webdriver driver instance
- `name` (**required**) - The snapshot name; must be unique to each snapshot
- Additional snapshot options (overrides any project options) (`**kwargs**`):
- `widths` - An array of widths to take screenshots at
- `minHeight` - The minimum viewport height to take screenshots at
- `percyCSS` - Percy specific CSS only applied in Percy's rendering environment
- `requestHeaders` - Headers that should be used during asset discovery
- `enableJavaScript` - Enable JavaScript in Percy's rendering environment

### Migrating Config

If you have a previous Percy configuration file, migrate it to the newest version with the
[`config:migrate`](https://github.com/percy/cli/tree/master/packages/cli-config#percy-configmigrate-filepath-output) command:

```sh-session
$ percy config:migrate
```
- Set your `PERCY_TOKEN` in the current env (you can get this in your Percy
project settings)
- Run your tests with `percy exec -- [test command]`: `npx percy exec -- python
./tests.py` (or `yarn percy exec -- python ./tests.py`)
7 changes: 0 additions & 7 deletions RELEASING.md

This file was deleted.

3 changes: 3 additions & 0 deletions development.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
httpretty==1.*
pylint==2.*
twine
17 changes: 0 additions & 17 deletions package.json

This file was deleted.

11 changes: 4 additions & 7 deletions percy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-

__author__ = 'Perceptual Inc.'
__email__ = 'team@percy.io'
__version__ = '0.1.3'

from percy.snapshot import percySnapshot
from percy.snapshot import percy_snapshot
from percy.version import __version__
# for better backwards compatibility
percySnapshot = percy_snapshot
Loading

0 comments on commit 2934f12

Please sign in to comment.