Name | appium-swipe-actions JSON |
Version |
0.1.2
JSON |
| download |
home_page | None |
Summary | Enhanced Swipe Actions Library for Appium. |
upload_time | 2024-07-02 06:11:17 |
maintainer | None |
docs_url | None |
author | Tanakrit-D |
requires_python | <4.0,>=3.12 |
license | MIT |
keywords |
appium
swipe
scroll
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Enhanced Swipe Actions Library
The purpose of this library is to provide more robust and useful swiping/scrolling functionality for Appium mobile automation.
It currently only targets use with Android, and has not been tested against iOS.
## Install
```bash
pip install appium-swipe-actions
# or
poetry add appium-swipe-actions
```
## Available Methods
```python
swipe_up()
swipe_down()
swipe_left()
swipe_right()
swipe_next()
swipe_previous()
swipe_on_element()
swipe_element_into_view()
```
## Demo and Example Usage
![Library Demo](https://github.com/Tanakrit-D/Appium-Swipe-Actions/raw/main/demo/example.gif)
```python
from appium_swipe_actions.core import SwipeActions, SeekDirection
class TestDemo(TestCore):
def test_element_search(self):
swipe = SwipeActions(self.driver)
self.driver.find_element(
by=AppiumBy.ANDROID_UIAUTOMATOR,
value='new UiSelector().description("Today")',
)
self.driver.find_element(
by=AppiumBy.ANDROID_UIAUTOMATOR,
value='new UiSelector().className("android.widget.Button").instance(3)',
).click()
swipe.swipe_element_into_view(
AppiumBy.ANDROID_UIAUTOMATOR,
'new UiSelector().descriptionContains("Day planted")',
SeekDirection.DOWN,
)
```
## Defining a Scrollable Region
This library divides the viewport into four bounds: upper, lower, left, and right. The default values can be overwritten.
Using these bounds, we then define a 'scrollable region'. We can then perform our scroll/swipe actions within this space.
The impetus for this is to recreate scrolling/swiping behaviour more similar to a user and avoid hardcoding co-ordinates.
Additionally, it avoids the automation attempting to perform actions on top of elements (such as headers or footers).
![Viewport Diagram](https://github.com/Tanakrit-D/Appium-Swipe-Actions/raw/main/resources/viewport_scrollable_bounds.png)
## Defining Element Points
The importance of dynamically generating 'points' of an element to interact with allows us to account for re-sizing under a number of conditions (such as different devices/resolutions).
For the purpose of this library, we are only concered with two attributes of an element: position and size.
The element's co-ordinates within the viewport is considered the top-left-point.
We can then use the element size to determine where it occupies relative to the view-port position.
![Element Diagram](https://github.com/Tanakrit-D/Appium-Swipe-Actions/raw/main/resources/understanding_element_position-dimension.png)
```python
top_left_point = element.location["x"], element.location["y"]
top_mid_point = element.location["x"] + (element.size["width"] // 2), element.location["y"]
top_right_point = element.location["x"] + element.size["width"], element.location["y"]
left_mid_point = element.location["x"], element.location["y"] + (element.size["height"] // 2)
mid_point = element.location["x"] + (element.size["width"] // 2), element.location["y"] + (element.size["height"] // 2)
right_mid_point = element.location["x"] + element.size["width"], element.location["y"] + (element.size["height"] // 2)
bottom_left_point = element.location["x"], element.location["y"] + element.size["height"]
bottom_mid_point = element.location["x"] + (element.size["width"] // 2), element.location["y"] + element.size["height"]
bottom_right_point = element.location["x"] + element.size["width"], element.location["y"] + element.size["height"]
```
Using the example element from the image, the above calculations would output as follows:
```console
Top-Left-Point: (20, 20)
Top-Mid-Point: (40, 20)
Top-Right-Point: (60, 20)
Left-Mid-Point: (20, 30)
Mid-Point: (40, 30)
Right-Mid-Point: (60, 30)
Bottom-Left-Point: (20, 40)
Bottom-Mid-Point: (40, 40)
Bottom-Right-Point: (60, 40)
```
An example of this is available here: [demo/calc_coordinates.py](https://raw.githubusercontent.com/Tanakrit-D/Appium-Swipe-Actions/blob/main/demo/calc_coordinates.py)
## Notes
### Swipe Element Into View
The method `swipe_element_into_view()` contains the helper `_probe_for_element()`.
This is because in the event an element is not loaded into the DOM yet or the driver context is NATIVE - it will not be able to locate the element.
Instead, it will start calling `perform_navigation_partial_()` and seek the element for a set number of attempts.
This can be set/overwritten when initialising the class with the `**kwargs("probe_attempts")`.
Additionally, the `if actions_partial > 50:` ensures the pixel distance is large enough to warrant an action.
If it is less than 50px, the swipe action will be interpreted by the OS as a double-tap.
### Wait/Expected Conditions
The library will not wait for the elements to be visible before interacting with them (such as `swipe_on_element()`).
Ensure you implement this yourself.
### Debugging
#### Android
If you would like to see the pointer interactions and coordinates, this can be enabled on a device level in `Settings > Developer Options > Pointer location`
Raw data
{
"_id": null,
"home_page": null,
"name": "appium-swipe-actions",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.12",
"maintainer_email": null,
"keywords": "appium, swipe, scroll",
"author": "Tanakrit-D",
"author_email": "127579510+Tanakrit-D@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/36/4c/b6abec344989be5f55193639a63138cc5a0137597f760481992952ba51d7/appium_swipe_actions-0.1.2.tar.gz",
"platform": null,
"description": "# Enhanced Swipe Actions Library\nThe purpose of this library is to provide more robust and useful swiping/scrolling functionality for Appium mobile automation. \nIt currently only targets use with Android, and has not been tested against iOS.\n\n## Install\n```bash\npip install appium-swipe-actions\n# or\npoetry add appium-swipe-actions\n```\n\n## Available Methods\n```python\nswipe_up()\nswipe_down()\nswipe_left()\nswipe_right()\nswipe_next()\nswipe_previous()\nswipe_on_element()\nswipe_element_into_view()\n```\n\n## Demo and Example Usage\n![Library Demo](https://github.com/Tanakrit-D/Appium-Swipe-Actions/raw/main/demo/example.gif)\n\n```python\nfrom appium_swipe_actions.core import SwipeActions, SeekDirection\n\nclass TestDemo(TestCore):\n def test_element_search(self):\n swipe = SwipeActions(self.driver)\n self.driver.find_element(\n by=AppiumBy.ANDROID_UIAUTOMATOR,\n value='new UiSelector().description(\"Today\")',\n )\n self.driver.find_element(\n by=AppiumBy.ANDROID_UIAUTOMATOR,\n value='new UiSelector().className(\"android.widget.Button\").instance(3)',\n ).click()\n swipe.swipe_element_into_view(\n AppiumBy.ANDROID_UIAUTOMATOR,\n 'new UiSelector().descriptionContains(\"Day planted\")',\n SeekDirection.DOWN,\n )\n```\n\n## Defining a Scrollable Region\nThis library divides the viewport into four bounds: upper, lower, left, and right. The default values can be overwritten. \nUsing these bounds, we then define a 'scrollable region'. We can then perform our scroll/swipe actions within this space. \nThe impetus for this is to recreate scrolling/swiping behaviour more similar to a user and avoid hardcoding co-ordinates. \nAdditionally, it avoids the automation attempting to perform actions on top of elements (such as headers or footers). \n![Viewport Diagram](https://github.com/Tanakrit-D/Appium-Swipe-Actions/raw/main/resources/viewport_scrollable_bounds.png)\n\n## Defining Element Points\nThe importance of dynamically generating 'points' of an element to interact with allows us to account for re-sizing under a number of conditions (such as different devices/resolutions).\n\nFor the purpose of this library, we are only concered with two attributes of an element: position and size. \nThe element's co-ordinates within the viewport is considered the top-left-point.\n\nWe can then use the element size to determine where it occupies relative to the view-port position.\n![Element Diagram](https://github.com/Tanakrit-D/Appium-Swipe-Actions/raw/main/resources/understanding_element_position-dimension.png)\n\n```python\ntop_left_point = element.location[\"x\"], element.location[\"y\"]\ntop_mid_point = element.location[\"x\"] + (element.size[\"width\"] // 2), element.location[\"y\"]\ntop_right_point = element.location[\"x\"] + element.size[\"width\"], element.location[\"y\"]\n\nleft_mid_point = element.location[\"x\"], element.location[\"y\"] + (element.size[\"height\"] // 2)\nmid_point = element.location[\"x\"] + (element.size[\"width\"] // 2), element.location[\"y\"] + (element.size[\"height\"] // 2)\nright_mid_point = element.location[\"x\"] + element.size[\"width\"], element.location[\"y\"] + (element.size[\"height\"] // 2)\n\nbottom_left_point = element.location[\"x\"], element.location[\"y\"] + element.size[\"height\"]\nbottom_mid_point = element.location[\"x\"] + (element.size[\"width\"] // 2), element.location[\"y\"] + element.size[\"height\"]\nbottom_right_point = element.location[\"x\"] + element.size[\"width\"], element.location[\"y\"] + element.size[\"height\"]\n```\nUsing the example element from the image, the above calculations would output as follows: \n```console\nTop-Left-Point: (20, 20) \nTop-Mid-Point: (40, 20) \nTop-Right-Point: (60, 20)\n \nLeft-Mid-Point: (20, 30) \nMid-Point: (40, 30) \nRight-Mid-Point: (60, 30)\n \nBottom-Left-Point: (20, 40) \nBottom-Mid-Point: (40, 40) \nBottom-Right-Point: (60, 40)\n```\n\nAn example of this is available here: [demo/calc_coordinates.py](https://raw.githubusercontent.com/Tanakrit-D/Appium-Swipe-Actions/blob/main/demo/calc_coordinates.py)\n\n## Notes\n### Swipe Element Into View\nThe method `swipe_element_into_view()` contains the helper `_probe_for_element()`. \nThis is because in the event an element is not loaded into the DOM yet or the driver context is NATIVE - it will not be able to locate the element. \nInstead, it will start calling `perform_navigation_partial_()` and seek the element for a set number of attempts. \nThis can be set/overwritten when initialising the class with the `**kwargs(\"probe_attempts\")`.\n\nAdditionally, the `if actions_partial > 50:` ensures the pixel distance is large enough to warrant an action. \nIf it is less than 50px, the swipe action will be interpreted by the OS as a double-tap.\n\n### Wait/Expected Conditions\nThe library will not wait for the elements to be visible before interacting with them (such as `swipe_on_element()`). \nEnsure you implement this yourself.\n\n### Debugging\n#### Android\nIf you would like to see the pointer interactions and coordinates, this can be enabled on a device level in `Settings > Developer Options > Pointer location`",
"bugtrack_url": null,
"license": "MIT",
"summary": "Enhanced Swipe Actions Library for Appium.",
"version": "0.1.2",
"project_urls": null,
"split_keywords": [
"appium",
" swipe",
" scroll"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0b3b72023c618cc3f3ce0e0d23ea6fda65214b4384d3366cee769d34352a558f",
"md5": "63145b973bed20c9e4fe4ac41e15fd37",
"sha256": "ce3c7e2260b032594c369240ff4a58a6f17c69ea5729024578d94df5a2ce10a9"
},
"downloads": -1,
"filename": "appium_swipe_actions-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "63145b973bed20c9e4fe4ac41e15fd37",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.12",
"size": 7330,
"upload_time": "2024-07-02T06:11:15",
"upload_time_iso_8601": "2024-07-02T06:11:15.998080Z",
"url": "https://files.pythonhosted.org/packages/0b/3b/72023c618cc3f3ce0e0d23ea6fda65214b4384d3366cee769d34352a558f/appium_swipe_actions-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "364cb6abec344989be5f55193639a63138cc5a0137597f760481992952ba51d7",
"md5": "62f2abeaadcbd5e39593d1b0f2fb803f",
"sha256": "8529d434722fbd388da5d14b7abab433632bc03753f44aedba2d5e573e47eb7b"
},
"downloads": -1,
"filename": "appium_swipe_actions-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "62f2abeaadcbd5e39593d1b0f2fb803f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.12",
"size": 6678,
"upload_time": "2024-07-02T06:11:17",
"upload_time_iso_8601": "2024-07-02T06:11:17.896353Z",
"url": "https://files.pythonhosted.org/packages/36/4c/b6abec344989be5f55193639a63138cc5a0137597f760481992952ba51d7/appium_swipe_actions-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-02 06:11:17",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "appium-swipe-actions"
}