Skip to content

Commit 5d6e7d3

Browse files
author
Dmitry Vorobjev
committed
1.0.0.dev3
1 parent 62c8f06 commit 5d6e7d3

File tree

6 files changed

+29
-103
lines changed

6 files changed

+29
-103
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.0.0.dev3
2+
### Добавлено
3+
- добавлено описание плагина и пример работы с ним
4+
### Удалено
5+
- удалены неиспользуемые зависимости и файлы
6+
17
## 1.0.0.dev2
28
### Добавлено
39
- добавлена настройка максимально допустимого количество отличающихся пикселей

README.md

Lines changed: 22 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,27 @@
1-
# Pytest plugin for visual testing
1+
# pytest-assert-screenshot
22

3-
Based on [pixelmatch-py](https://github.com/whtsky/pixelmatch-py) image comparison library.
3+
Этот плагин - форк плагина [pytest-playwright-visual](https://github.com/symon-storozhenko/pytest-playwright-visual).
44

5-
## Main Features:
6-
- snapshots creation on the first run
7-
- visual review of mismatches
8-
- failing on `--update-screenshots` to make users manually review images
9-
- snapshot name is optional, `test_name.png` is auto-generated by default
10-
- updated folder structure: `snapshots/file_name/test_name/test_name.png`
5+
Плагин предназначен для сравнения скриншотов при UI-тестировании веб-приложений. Плагин может быть исопльзован с любым UI-фреймворком.
116

12-
## Installation
7+
В плагине добавлена возможность задавать допустимое количество отличающихся пикселей на скриншоте. Это помогает сделать тесты более стабильными.
138

14-
```bash
15-
$ pip install pytest-playwright-visual
16-
```
17-
18-
## Usage
19-
20-
This plugin provides a `assert_screenshot` fixture which is used to create snapshots and compare it.
21-
22-
Example:
23-
24-
```python
25-
def test_myapp(page, assert_snapshot):
26-
page.goto("https://example.com")
27-
assert_snapshot(page.screenshot())
28-
```
29-
Then, run pytest:
30-
```bash
31-
$ pytest
32-
```
33-
The first time you run pytest, snapshots will be created, and you will get the error:
34-
35-
```console
36-
Failed: --> New snapshot(s) created. Please review images
37-
```
38-
39-
The next run, the snapshots comparison will take place.
40-
41-
To update snapshots, run:
42-
43-
```bash
44-
$ pytest --update-screenshots
45-
```
46-
47-
After updating, tests will fail and you will need to review images.
48-
49-
In case of a mismatch, `screenshot_tests_failures` folder will be created with `Actual_..`, `Expected_..` and `Diff_..` images generated.
50-
51-
## Folder Structure Example
52-
53-
![img_2.png](img_2.png)
54-
55-
## API
56-
**assert_snapshot(page.screenshot(), threshold: float = 0.1, name='test_name[browser][os].png', fail_fast=False)**
57-
- `threshold` - sets the threshold for the comparison of the screenshots:`0` to `1`. Default is `0.1`
58-
- `name` - `.png` extensions only. Default is `test_name.png` (recommended)
59-
- `fail_fast` - If `True`, will fail after first different pixel. `False` by default
60-
61-
## Change snapshots path
62-
63-
You can change the default path where snapshots are stored by setting `pytest.snapshots_path` and/or
64-
`pytest.screenshot_failures_path` value in `pytest_configure()` hook in your root `conftest.py`:
9+
После установки пакета в тестах с использованием библиотеки pytest становится доступна фикстура assert-screenshot:
6510
```python
66-
def pytest_configure():
67-
pytest.snapshots_path = Path.cwd() / "screenshots"
68-
pytest.snapshot_failures_path = Path.cwd() / "screenshots_failures"
69-
```
70-
71-
## License
72-
73-
Apache 2.0 LICENSE
11+
class TestExamplesVisual:
12+
def test_visual_auth_page(self, ui_client: UIClient, assert_screenshot):
13+
"""Визуальный тест страницы авторизации"""
14+
# ARRANGE
15+
ui_client.page_auth.navigate()
16+
# ACT
17+
screenshot_page_auth = ui_client.page_auth.make_screenshot()
18+
# ASSERT
19+
screenshot_name = OperationsFile.generate_screenshot_name()
20+
logger.debug('Имя базового скриншота = ' + screenshot_name)
21+
assert_screenshot(
22+
screenshot_page_auth,
23+
threshold=0.12,
24+
name=screenshot_name,
25+
fail_fast=False,
26+
)
27+
```

img_2.png

-111 KB
Binary file not shown.

requirements.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
black==21.7b0
2-
mypy==0.910
3-
requests==2.25.1
4-
types-requests==2.25.6

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='pytest-assert-screenshot',
7-
version='1.0.0.dev2',
7+
version='1.0.0.dev3',
88
author='Dmitry Vorobjev',
99
author_email='[email protected]',
1010
description='A pytest fixture for visual testing',

0 commit comments

Comments
 (0)