# percy-appium-python
[![PyPI version](https://badge.fury.io/py/percy-appium-app.svg)](https://pypi.org/project/percy-appium-app/)
![Test](https://github.com/percy/percy-appium-python/workflows/Test/badge.svg)
[Percy](https://percy.io) visual testing for Python Appium.
## Installation
npm install `@percy/cli`:
```sh-session
$ npm install --save-dev @percy/cli
```
pip install Percy appium package:
```ssh-session
$ pip install percy-appium-app
```
> Note: This package is tested on Python versions 3.6, 3.8, 3.9 as part of unit tests. It should ideally work on all Python 3.6+ versions
[NOTE] Appium-Python-Client(>= v2.9.0) is having compatibility issues with urllib3 latest versions. To solve the issue it is recommended to add `urllib3>=1.26.15,<2` in your requirements.txt file.
## Usage
This is an example test using the `percy_screenshot` function.
``` python
from appium import webdriver
from percy import percy_screenshot
driver = webdriver.Remote("https://" + userName + ":" + accessKey + "@hub-cloud.browserstack.com/wd/hub", desired_caps)
# take a screenshot
percy_screenshot(driver, 'here is some name')
```
Running the test above normally will result in the following log:
```sh-session
[percy] Percy is not running, disabling screenshots
```
When running with [`percy
app:exec`](https://github.com/percy/cli/tree/master/packages/cli-exec#app-exec), and your project's
`PERCY_TOKEN`, a new Percy build will be created and screenshots will be uploaded to your project.
```sh-session
$ export PERCY_TOKEN=[your-project-token]
$ percy app:exec -- [python test command]
[percy] Percy has started!
[percy] Created build #1: https://percy.io/[your-project]
[percy] Screenshot taken "Python example"
[percy] Stopping percy...
[percy] Finalized build #1: https://percy.io/[your-project]
[percy] Done!
```
## Configuration
`percy_screenshot(driver, name[, **kwargs])`
- `driver` (**required**) - A appium driver instance
- `name` (**required**) - The screenshot name; must be unique to each screenshot
- `device_name` (**optional**) - The device name used for capturing screenshot
- `orientation` (**optional**) - Orientation of device while capturing screeenshot; Allowed values [`portrait` | `landscape`]
- `status_bar_height` (**optional**) - Height of status bar; int
- `nav_bar_height` (**optional**) - Height of navigation bar; int
- `sync` - Boolean value by default it falls back to `false`, Gives the processed result around screenshot [From CLI v1.28.0-beta.0+]
- `fullpage` (**optional**) - [Alpha] Only supported on App Automate driver sessions [ needs @percy/cli 1.20.2+ ]; boolean
- `screen_lengths` (**optional**) - [Alpha] Max screen lengths for fullPage; int
- In case scrollview is overlapping with other app elements. Offsets can be provided to reduce the area which needs to be considered for scrolling:
- `top_scrollview_offset`: (**optional**) - [Alpha] Offset from top of scrollview; int
- `bottom_scrollview_offset` (**optional**) - [Alpha] Offset from bottom of scrollview; int
- `full_screen` (**optional**) - Indicate whether app is full screen; boolean [ needs @percy/cli 1.20.2+ ];
- `scrollable_xpath` (**optional**) - [Alpha] Scrollable element xpath for fullpage [ needs @percy/cli 1.20.2+ ]; string
- `scrollable_id` (**optional**) - [Alpha] Scrollable element accessibility id for fullpage [ needs @percy/cli 1.20.2+ ]; string
- `ignore_regions_xpaths` (**optional**) - Elements xpaths that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of string
- `ignore_region_accessibility_ids` (**optional**) - Elements accessibility_ids that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of string
- `ignore_region_appium_elements` (**optional**) - Appium elements that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of appium element object
- `custom_ignore_regions` (**optional**) - Custom locations that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of ignore_region object
- IgnoreRegion:-
- Description: This class represents a rectangular area on a screen that needs to be ignored for visual diff.
- Constructor:
```
init(self, top, bottom, left, right)
```
- Parameters:
- `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.
## Running with Hybrid Apps
For a hybrid app, we need to switch to native context before taking screenshot.
- Add a helper method similar to following for say flutter based hybrid app:
```python
def percy_screenshot_flutter(driver, name: str, **kwargs):
driver.switch_to.context('NATIVE_APP')
percy_screenshot(driver, name, **kwargs)
driver.switch_to.context('FLUTTER')
```
- Call PercyScreenshotFlutter helper function when you want to take screenshot.
```python
percy_screenshot_flutter(driver, name, **kwargs)
```
> Note:
>
> For other hybrid apps the `driver.switch_to.context('FLUTTER')` would change to context that it uses like say WEBVIEW etc.
>
## Running Percy on Automate
`percy_screenshot(driver, name, options)` [ needs @percy/cli 1.27.0-beta.0+ ];
- `driver` (**required**) - A appium driver 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.
- `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.
- `ignore_region_appium_elements` - List of appium web-element. elements can be ignored using appium_elements.
- `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.
- `consider_region_appium_elements` - List of appium web-element. elements can be considered for diffing and will be ignored by Intelli Ignore using appium_elements.
- `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)
### 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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/percy/percy-appium-python",
"name": "percy-appium-app",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "appium percy visual testing",
"author": "Perceptual Inc.",
"author_email": "team@percy.io",
"download_url": "https://files.pythonhosted.org/packages/2e/e7/ffb5f8cfedc8a3d8671a6af5bb00ec9f66a38bb0138d14fb8211f543b095/percy_appium_app-2.0.6.tar.gz",
"platform": null,
"description": "# percy-appium-python\n[![PyPI version](https://badge.fury.io/py/percy-appium-app.svg)](https://pypi.org/project/percy-appium-app/)\n![Test](https://github.com/percy/percy-appium-python/workflows/Test/badge.svg)\n\n[Percy](https://percy.io) visual testing for Python Appium.\n\n## Installation\n\nnpm install `@percy/cli`:\n\n```sh-session\n$ npm install --save-dev @percy/cli\n```\n\npip install Percy appium package:\n\n```ssh-session\n$ pip install percy-appium-app\n```\n> Note: This package is tested on Python versions 3.6, 3.8, 3.9 as part of unit tests. It should ideally work on all Python 3.6+ versions\n\n[NOTE] Appium-Python-Client(>= v2.9.0) is having compatibility issues with urllib3 latest versions. To solve the issue it is recommended to add `urllib3>=1.26.15,<2` in your requirements.txt file.\n\n## Usage\n\nThis is an example test using the `percy_screenshot` function.\n\n``` python\nfrom appium import webdriver\nfrom percy import percy_screenshot\n\ndriver = webdriver.Remote(\"https://\" + userName + \":\" + accessKey + \"@hub-cloud.browserstack.com/wd/hub\", desired_caps)\n\n# take a screenshot\npercy_screenshot(driver, 'here is some name')\n```\n\nRunning the test above normally will result in the following log:\n\n```sh-session\n[percy] Percy is not running, disabling screenshots\n```\n\nWhen running with [`percy\napp:exec`](https://github.com/percy/cli/tree/master/packages/cli-exec#app-exec), and your project's\n`PERCY_TOKEN`, a new Percy build will be created and screenshots will be uploaded to your project.\n\n```sh-session\n$ export PERCY_TOKEN=[your-project-token]\n$ percy app:exec -- [python test command]\n[percy] Percy has started!\n[percy] Created build #1: https://percy.io/[your-project]\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\n## Configuration\n\n`percy_screenshot(driver, name[, **kwargs])`\n\n- `driver` (**required**) - A appium driver instance\n- `name` (**required**) - The screenshot name; must be unique to each screenshot\n- `device_name` (**optional**) - The device name used for capturing screenshot\n- `orientation` (**optional**) - Orientation of device while capturing screeenshot; Allowed values [`portrait` | `landscape`]\n- `status_bar_height` (**optional**) - Height of status bar; int\n- `nav_bar_height` (**optional**) - Height of navigation bar; int\n- `sync` - Boolean value by default it falls back to `false`, Gives the processed result around screenshot [From CLI v1.28.0-beta.0+]\n- `fullpage` (**optional**) - [Alpha] Only supported on App Automate driver sessions [ needs @percy/cli 1.20.2+ ]; boolean\n - `screen_lengths` (**optional**) - [Alpha] Max screen lengths for fullPage; int\n - In case scrollview is overlapping with other app elements. Offsets can be provided to reduce the area which needs to be considered for scrolling:\n - `top_scrollview_offset`: (**optional**) - [Alpha] Offset from top of scrollview; int\n - `bottom_scrollview_offset` (**optional**) - [Alpha] Offset from bottom of scrollview; int\n- `full_screen` (**optional**) - Indicate whether app is full screen; boolean [ needs @percy/cli 1.20.2+ ];\n- `scrollable_xpath` (**optional**) - [Alpha] Scrollable element xpath for fullpage [ needs @percy/cli 1.20.2+ ]; string\n- `scrollable_id` (**optional**) - [Alpha] Scrollable element accessibility id for fullpage [ needs @percy/cli 1.20.2+ ]; string\n- `ignore_regions_xpaths` (**optional**) - Elements xpaths that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of string\n- `ignore_region_accessibility_ids` (**optional**) - Elements accessibility_ids that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of string\n- `ignore_region_appium_elements` (**optional**) - Appium elements that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of appium element object\n- `custom_ignore_regions` (**optional**) - Custom locations that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of ignore_region object\n - IgnoreRegion:-\n - Description: This class represents a rectangular area on a screen that needs to be ignored for visual diff.\n - Constructor:\n ```\n init(self, top, bottom, left, right)\n ```\n - Parameters:\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\n## Running with Hybrid Apps\n\nFor a hybrid app, we need to switch to native context before taking screenshot.\n\n- Add a helper method similar to following for say flutter based hybrid app:\n```python\ndef percy_screenshot_flutter(driver, name: str, **kwargs):\n driver.switch_to.context('NATIVE_APP')\n percy_screenshot(driver, name, **kwargs)\n driver.switch_to.context('FLUTTER')\n```\n\n- Call PercyScreenshotFlutter helper function when you want to take screenshot.\n```python\npercy_screenshot_flutter(driver, name, **kwargs)\n```\n\n> Note: \n>\n> For other hybrid apps the `driver.switch_to.context('FLUTTER')` would change to context that it uses like say WEBVIEW etc.\n>\n\n## Running Percy on Automate\n`percy_screenshot(driver, name, options)` [ needs @percy/cli 1.27.0-beta.0+ ];\n- `driver` (**required**) - A appium driver 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 - `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 - `ignore_region_appium_elements` - List of appium web-element. elements can be ignored using appium_elements.\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 - `consider_region_appium_elements` - List of appium web-element. elements can be considered for diffing and will be ignored by Intelli Ignore using appium_elements.\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### 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\n### Migrating Config\n\nIf you have a previous Percy configuration file, migrate it to the newest version with the\n[`config:migrate`](https://github.com/percy/cli/tree/master/packages/cli-config#percy-configmigrate-filepath-output) command:\n\n```sh-session\n$ percy config:migrate\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python client for visual testing with Percy for mobile apps",
"version": "2.0.6",
"project_urls": {
"Homepage": "https://github.com/percy/percy-appium-python"
},
"split_keywords": [
"appium",
"percy",
"visual",
"testing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f97a732eb8d80bce4dfa49e4fae50e064827ed9e12a04fba4018fd41531b7a7f",
"md5": "21e5827508e84f62e84af4dcb35e1768",
"sha256": "b9ce5156f8a54bacf1215d7c65bd72c105f9cb408ae6fa91dbb1ef8c28217996"
},
"downloads": -1,
"filename": "percy_appium_app-2.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "21e5827508e84f62e84af4dcb35e1768",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 21727,
"upload_time": "2024-10-18T11:11:40",
"upload_time_iso_8601": "2024-10-18T11:11:40.039753Z",
"url": "https://files.pythonhosted.org/packages/f9/7a/732eb8d80bce4dfa49e4fae50e064827ed9e12a04fba4018fd41531b7a7f/percy_appium_app-2.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2ee7ffb5f8cfedc8a3d8671a6af5bb00ec9f66a38bb0138d14fb8211f543b095",
"md5": "7b59163a57a017afbed373fa64c93806",
"sha256": "7eab9aa61bc49fb31f587afc68c81162261555e1c0d32c6c3beb0a63f894b445"
},
"downloads": -1,
"filename": "percy_appium_app-2.0.6.tar.gz",
"has_sig": false,
"md5_digest": "7b59163a57a017afbed373fa64c93806",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 29959,
"upload_time": "2024-10-18T11:11:41",
"upload_time_iso_8601": "2024-10-18T11:11:41.675181Z",
"url": "https://files.pythonhosted.org/packages/2e/e7/ffb5f8cfedc8a3d8671a6af5bb00ec9f66a38bb0138d14fb8211f543b095/percy_appium_app-2.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-18 11:11:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "percy",
"github_project": "percy-appium-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "percy-appium-app"
}