# Percy playwright python
![Test](https://github.com/percy/percy-playwright-python/workflows/Test/badge.svg)
[Percy](https://percy.io) visual testing for Python Playwright.
## Installation
npm install `@percy/cli`:
```sh-session
$ npm install --save-dev @percy/cli
```
pip install Percy playwright package:
```ssh-session
$ pip install percy-playwright
```
## Usage
This is an example test using the `percy_snapshot` function.
``` python
from percy import percy_snapshot
with sync_playwright() as playwright:
browser = playwright.chromium.connect()
page = browser.new_page()
page.goto('http://example.com')
# take a snapshot
percy_snapshot(browser, '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(page, name[, **kwargs])`
- `page` (**required**) - A playwright page instance
- `name` (**required**) - The snapshot name; must be unique to each snapshot
- `**kwargs` - [See per-snapshot configuration options](https://www.browserstack.com/docs/percy/take-percy-snapshots/overview#per-snapshot-configuration)
## Percy on Automate
## Usage
``` python
from playwright.sync_api import sync_playwright
from percy import percy_screenshot, percy_snapshot
desired_cap = {
'browser': 'chrome',
'browser_version': 'latest',
'os': 'osx',
'os_version': 'ventura',
'name': 'Percy Playwright PoA Demo',
'build': 'percy-playwright-python-tutorial',
'browserstack.username': 'username',
'browserstack.accessKey': 'accesskey'
}
with sync_playwright() as playwright:
cdpUrl = 'wss://cdp.browserstack.com/playwright?caps=' + urllib.parse.quote(json.dumps(desired_cap))
browser = playwright.chromium.connect(cdpUrl)
page = browser.new_page()
page.goto("https://percy.io/")
percy_screenshot(page, name = "Screenshot 1")
```
# take a snapshot
```python
percy_screenshot(page, name = 'Screenshot 1')
```
- `page` (**required**) - A Playwright page instance
- `name` (**required**) - The screenshot name; must be unique to each screenshot
- `options` (**optional**) - There are various options supported by percy_screenshot to server further functionality.
- `sync` - Boolean value by default it falls back to `false`, Gives the processed result around screenshot [From CLI v1.28.8]
- `full_page` - Boolean value by default it falls back to `false`, Takes full page screenshot [From CLI v1.28.8]
- `freeze_animated_image` - Boolean value by default it falls back to `false`, you can pass `true` and percy will freeze image based animations.
- `freeze_image_by_selectors` -List of selectors. Images will be freezed which are passed using selectors. For this to work `freeze_animated_image` must be set to true.
- `freeze_image_by_xpaths` - List of xpaths. Images will be freezed which are passed using xpaths. For this to work `freeze_animated_image` must be set to true.
- `percy_css` - Custom CSS to be added to DOM before the screenshot being taken. Note: This gets removed once the screenshot is taken.
- `ignore_region_xpaths` - List of xpaths. elements in the DOM can be ignored using xpath
- `ignore_region_selectors` - List of selectors. elements in the DOM can be ignored using selectors.
- `custom_ignore_regions` - List of custom objects. elements can be ignored using custom boundaries. Just passing a simple object for it like below.
- example: ```{"top": 10, "right": 10, "bottom": 120, "left": 10}```
- In above example it will draw rectangle of ignore region as per given coordinates.
- `top` (int): Top coordinate of the ignore region.
- `bottom` (int): Bottom coordinate of the ignore region.
- `left` (int): Left coordinate of the ignore region.
- `right` (int): Right coordinate of the ignore region.
- `consider_region_xpaths` - List of xpaths. elements in the DOM can be considered for diffing and will be ignored by Intelli Ignore using xpaths.
- `consider_region_selectors` - List of selectors. elements in the DOM can be considered for diffing and will be ignored by Intelli Ignore using selectors.
- `custom_consider_regions` - List of custom objects. elements can be considered for diffing and will be ignored by Intelli Ignore using custom boundaries
- example:```{"top": 10, "right": 10, "bottom": 120, "left": 10}```
- In above example it will draw rectangle of consider region will be drawn.
- Parameters:
- `top` (int): Top coordinate of the consider region.
- `bottom` (int): Bottom coordinate of the consider region.
- `left` (int): Left coordinate of the consider region.
- `right` (int): Right coordinate of the consider region.
### Creating Percy on automate build
Note: Automate Percy Token starts with `auto` keyword. The command can be triggered using `exec` keyword.
```sh-session
$ export PERCY_TOKEN=[your-project-token]
$ percy exec -- [python test command]
[percy] Percy has started!
[percy] [Python example] : Starting automate screenshot ...
[percy] Screenshot taken "Python example"
[percy] Stopping percy...
[percy] Finalized build #1: https://percy.io/[your-project]
[percy] Done!
```
Refer to docs here: [Percy on Automate](https://www.browserstack.com/docs/percy/integrate/functional-and-visual)
Raw data
{
"_id": null,
"home_page": "https://github.com/percy/percy-playwright-python",
"name": "percy-playwright",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "percy visual testing",
"author": "Perceptual Inc.",
"author_email": "team@percy.io",
"download_url": "https://files.pythonhosted.org/packages/72/83/674b08607fa2950eff367a524d477936a1821ca49a78a7e66d19ede79360/percy_playwright-1.0.0.tar.gz",
"platform": null,
"description": "# Percy playwright python\n![Test](https://github.com/percy/percy-playwright-python/workflows/Test/badge.svg)\n\n[Percy](https://percy.io) visual testing for Python Playwright.\n\n## Installation\n\nnpm install `@percy/cli`:\n\n```sh-session\n$ npm install --save-dev @percy/cli\n```\n\npip install Percy playwright package:\n\n```ssh-session\n$ pip install percy-playwright\n```\n\n## Usage\n\nThis is an example test using the `percy_snapshot` function.\n\n``` python\nfrom percy import percy_snapshot\n\nwith sync_playwright() as playwright:\n browser = playwright.chromium.connect()\n page = browser.new_page()\n page.goto('http://example.com')\n \u200b\n # take a snapshot\n percy_snapshot(browser, 'Python example')\n```\n\nRunning the test above normally will result in the following log:\n\n```sh-session\n[percy] Percy is not running, disabling snapshots\n```\n\nWhen running with [`percy\nexec`](https://github.com/percy/cli/tree/master/packages/cli-exec#percy-exec), and your project's\n`PERCY_TOKEN`, a new Percy build will be created and snapshots will be uploaded to your project.\n\n```sh-session\n$ export PERCY_TOKEN=[your-project-token]\n$ percy exec -- [python test command]\n[percy] Percy has started!\n[percy] Created build #1: https://percy.io/[your-project]\n[percy] Snapshot taken \"Python example\"\n[percy] Stopping percy...\n[percy] Finalized build #1: https://percy.io/[your-project]\n[percy] Done!\n```\n\n## Configuration\n\n`percy_snapshot(page, name[, **kwargs])`\n\n- `page` (**required**) - A playwright page instance\n- `name` (**required**) - The snapshot name; must be unique to each snapshot\n- `**kwargs` - [See per-snapshot configuration options](https://www.browserstack.com/docs/percy/take-percy-snapshots/overview#per-snapshot-configuration)\n\n\n## Percy on Automate\n\n## Usage\n\n``` python\nfrom playwright.sync_api import sync_playwright\nfrom percy import percy_screenshot, percy_snapshot\n\ndesired_cap = {\n 'browser': 'chrome',\n 'browser_version': 'latest',\n 'os': 'osx',\n 'os_version': 'ventura',\n 'name': 'Percy Playwright PoA Demo',\n 'build': 'percy-playwright-python-tutorial',\n 'browserstack.username': 'username',\n 'browserstack.accessKey': 'accesskey'\n}\n\nwith sync_playwright() as playwright:\n cdpUrl = 'wss://cdp.browserstack.com/playwright?caps=' + urllib.parse.quote(json.dumps(desired_cap))\n browser = playwright.chromium.connect(cdpUrl)\n page = browser.new_page()\n page.goto(\"https://percy.io/\")\n percy_screenshot(page, name = \"Screenshot 1\")\n```\n# take a snapshot\n```python\npercy_screenshot(page, name = 'Screenshot 1')\n```\n\n- `page` (**required**) - A Playwright page instance\n- `name` (**required**) - The screenshot name; must be unique to each screenshot\n- `options` (**optional**) - There are various options supported by percy_screenshot to server further functionality.\n - `sync` - Boolean value by default it falls back to `false`, Gives the processed result around screenshot [From CLI v1.28.8]\n - `full_page` - Boolean value by default it falls back to `false`, Takes full page screenshot [From CLI v1.28.8]\n - `freeze_animated_image` - Boolean value by default it falls back to `false`, you can pass `true` and percy will freeze image based animations.\n - `freeze_image_by_selectors` -List of selectors. Images will be freezed which are passed using selectors. For this to work `freeze_animated_image` must be set to true.\n - `freeze_image_by_xpaths` - List of xpaths. Images will be freezed which are passed using xpaths. For this to work `freeze_animated_image` must be set to true.\n - `percy_css` - Custom CSS to be added to DOM before the screenshot being taken. Note: This gets removed once the screenshot is taken.\n - `ignore_region_xpaths` - List of xpaths. elements in the DOM can be ignored using xpath\n - `ignore_region_selectors` - List of selectors. elements in the DOM can be ignored using selectors.\n - `custom_ignore_regions` - List of custom objects. elements can be ignored using custom boundaries. Just passing a simple object for it like below.\n - example: ```{\"top\": 10, \"right\": 10, \"bottom\": 120, \"left\": 10}```\n - In above example it will draw rectangle of ignore region as per given coordinates.\n - `top` (int): Top coordinate of the ignore region.\n - `bottom` (int): Bottom coordinate of the ignore region.\n - `left` (int): Left coordinate of the ignore region.\n - `right` (int): Right coordinate of the ignore region.\n - `consider_region_xpaths` - List of xpaths. elements in the DOM can be considered for diffing and will be ignored by Intelli Ignore using xpaths.\n - `consider_region_selectors` - List of selectors. elements in the DOM can be considered for diffing and will be ignored by Intelli Ignore using selectors.\n - `custom_consider_regions` - List of custom objects. elements can be considered for diffing and will be ignored by Intelli Ignore using custom boundaries\n - example:```{\"top\": 10, \"right\": 10, \"bottom\": 120, \"left\": 10}```\n - In above example it will draw rectangle of consider region will be drawn.\n - Parameters:\n - `top` (int): Top coordinate of the consider region.\n - `bottom` (int): Bottom coordinate of the consider region.\n - `left` (int): Left coordinate of the consider region.\n - `right` (int): Right coordinate of the consider region.\n\n\n### Creating Percy on automate build\nNote: Automate Percy Token starts with `auto` keyword. The command can be triggered using `exec` keyword.\n\n```sh-session\n$ export PERCY_TOKEN=[your-project-token]\n$ percy exec -- [python test command]\n[percy] Percy has started!\n[percy] [Python example] : Starting automate screenshot ...\n[percy] Screenshot taken \"Python example\"\n[percy] Stopping percy...\n[percy] Finalized build #1: https://percy.io/[your-project]\n[percy] Done!\n```\n\nRefer to docs here: [Percy on Automate](https://www.browserstack.com/docs/percy/integrate/functional-and-visual)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python client for visual testing with Percy",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/percy/percy-playwright-python"
},
"split_keywords": [
"percy",
"visual",
"testing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "74d8f223d082165d962972c8e1904268ed46975648f40c1e7ab161403becc657",
"md5": "ed0575322b82a8fef20fd5d91eaf24c9",
"sha256": "4ac13917e6823bb6bf42a2cf7c5c58ddd214a4bb15cc5bbae2919be8d75c3b88"
},
"downloads": -1,
"filename": "percy_playwright-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ed0575322b82a8fef20fd5d91eaf24c9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7576,
"upload_time": "2024-06-25T08:14:10",
"upload_time_iso_8601": "2024-06-25T08:14:10.738783Z",
"url": "https://files.pythonhosted.org/packages/74/d8/f223d082165d962972c8e1904268ed46975648f40c1e7ab161403becc657/percy_playwright-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7283674b08607fa2950eff367a524d477936a1821ca49a78a7e66d19ede79360",
"md5": "ab18e174c88d8375a256235af6c71bc5",
"sha256": "0237249d9445ad7a1961b7938941678850e47d690f85a4e1dc82fad1164b5e9b"
},
"downloads": -1,
"filename": "percy_playwright-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "ab18e174c88d8375a256235af6c71bc5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 10785,
"upload_time": "2024-06-25T08:14:11",
"upload_time_iso_8601": "2024-06-25T08:14:11.854825Z",
"url": "https://files.pythonhosted.org/packages/72/83/674b08607fa2950eff367a524d477936a1821ca49a78a7e66d19ede79360/percy_playwright-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-25 08:14:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "percy",
"github_project": "percy-playwright-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "percy-playwright"
}