Appium-Python-Client


NameAppium-Python-Client JSON
Version 4.0.0 PyPI version JSON
download
home_pagehttp://appium.io/
SummaryPython client for Appium
upload_time2024-03-12 04:56:52
maintainerKazuaki Matsuo, Mykola Mokhnach, Mori Atsushi
docs_urlNone
authorIsaac Murchie
requires_python
licenseApache 2.0
keywords appium selenium selenium 4 python client mobile automation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Appium Python Client

[![PyPI version](https://badge.fury.io/py/Appium-Python-Client.svg)](https://badge.fury.io/py/Appium-Python-Client)
[![Downloads](https://pepy.tech/badge/appium-python-client)](https://pepy.tech/project/appium-python-client)

[![Build Status](https://dev.azure.com/AppiumCI/Appium%20CI/_apis/build/status/appium.python-client?branchName=master)](https://dev.azure.com/AppiumCI/Appium%20CI/_build/latest?definitionId=56&branchName=master)

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

An extension library for adding [WebDriver Protocol](https://www.w3.org/TR/webdriver/) and Appium commands to the Selenium Python language binding for use with the mobile testing framework [Appium](https://appium.io).

## Getting the Appium Python client

There are three ways to install and use the Appium Python client.

1. Install from [PyPi](https://pypi.org), as
['Appium-Python-Client'](https://pypi.org/project/Appium-Python-Client/).

    ```shell
    pip install Appium-Python-Client
    ```

    You can see the history from [here](https://pypi.org/project/Appium-Python-Client/#history)

2. Install from source, via [PyPi](https://pypi.org). From ['Appium-Python-Client'](https://pypi.org/project/Appium-Python-Client/),
download and unarchive the source tarball (Appium-Python-Client-X.X.tar.gz).

    ```shell
    tar -xvf Appium-Python-Client-X.X.tar.gz
    cd Appium-Python-Client-X.X
    python setup.py install
    ```

3. Install from source via [GitHub](https://github.com/appium/python-client).

    ```shell
    git clone git@github.com:appium/python-client.git
    cd python-client
    python setup.py install
    ```

## Compatibility Matrix

|Appium Python Client| Selenium binding| Python version |
|----|----|----|
|`3.0.0`+ |`4.12.0`+ | 3.8+ |
|`2.10.0` - `2.11.1` |`4.1.0` - `4.11.2` | 3.7+ |
|`2.2.0` - `2.9.0` |`4.1.0` - `4.9.0` | 3.7+ |
|`2.0.0` - `2.1.4` |`4.0.0` | 3.7+ |
|`1.0.0` - `1.1.0` |`3.x`| 3.7, 3.8 |
|`0.52` and below|`3.x`| 2.7, 3.4 - 3.7 |

The Appium Python Client depends on [Selenium Python binding](https://pypi.org/project/selenium/), thus
the Selenium Python binding update might affect the Appium Python Client behavior.
For example, some changes in the Selenium binding could break the Appium client.

> **Note**
> We strongly recommend you manage dependencies with version management tools such as Pipenv and requirements.txt
> to keep compatible version combinations.


### Quick migration guide from v3 to v4
- Removal
    - `MultiAction` and `TouchAction` are removed. Please use W3C WebDriver actions or `mobile:` extensions
        - [appium/webdriver/extensions/action_helpers.py](appium/webdriver/extensions/action_helpers.py)
        - https://www.selenium.dev/documentation/webdriver/actions_api/
        - https://www.youtube.com/watch?v=oAJ7jwMNFVU
        - https://appiumpro.com/editions/30-ios-specific-touch-action-methods
        - https://appiumpro.com/editions/29-automating-complex-gestures-with-the-w3c-actions-api
    - Deprecated `AppiumBy.WINDOWS_UI_AUTOMATION`, which has no usage right now.

### Quick migration guide from v2 to v3
- `options` keyword argument in the `webdriver.Remote` constructor such as `XCUITestOptions` instead of `desired_capabilities`
    - Available options are https://github.com/appium/python-client/tree/master/appium/options
        - Please check the [Usage](#usage) below as an exampple.
    - Not a "new" change, but the `desired_capabilities` argument has been removed since v3.
- Replacement
    - `start_activity` method: Please use [`mobile: startActivity`](https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#mobile-startactivity)
    - `launch_app`, `close_app` and `reset` methods: Please refer to https://github.com/appium/appium/issues/15807
    - `available_ime_engines`, `is_ime_active`, `activate_ime_engine`, `deactivate_ime_engine` and `active_ime_engine` methods: Please use [`mobile: shell`](https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#mobile-shell)
    - `set_value` and `set_text` methods: Please use `element.send_keys` or `send_keys` by W3C Actions
- Removal
    - `end_test_coverage` method is no longer available
    - `session` property is no longer available
    - `all_sessions` property is no longer available

### Quick migration guide from v1 to v2
- Enhancement
    - Updated base Selenium Python binding version to v4
        - Removed `forceMjsonwp` since Selenium v4 and Appium Python client v2 expect only W3C WebDriver protocol
    - Methods `ActionHelpers#scroll`, `ActionHelpers#drag_and_drop`, `ActionHelpers#tap`, `ActionHelpers#swipe` and `ActionHelpers#flick` now call W3C actions as its backend
        - Please check each behavior. Their behaviors could slightly differ.
    - Added `strict_ssl` to relax SSL errors such as self-signed ones
- Deprecated
    - `MultiAction` and `TouchAction` are deprecated. Please use W3C WebDriver actions or `mobile:` extensions
    - `launch_app`, `close_app`, and `reset` are deprecated. Please read [issues#15807](https://github.com/appium/appium/issues/15807) for more details

#### MultiAction/TouchAction to W3C actions

On UIA2, some elements can be handled with `touch` pointer action instead of the default `mouse` pointer action in the Selenium Python client.
For example, the below action builder is to replace the default one with the `touch` pointer action.

```python
from selenium.webdriver import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput

actions = ActionChains(driver)
# override as 'touch' pointer action
actions.w3c_actions = ActionBuilder(driver, mouse=PointerInput(interaction.POINTER_TOUCH, "touch"))
actions.w3c_actions.pointer_action.move_to_location(start_x, start_y)
actions.w3c_actions.pointer_action.pointer_down()
actions.w3c_actions.pointer_action.pause(2)
actions.w3c_actions.pointer_action.move_to_location(end_x, end_y)
actions.w3c_actions.pointer_action.release()
actions.perform()
```

- [appium/webdriver/extensions/action_helpers.py](appium/webdriver/extensions/action_helpers.py)
- https://www.selenium.dev/documentation/webdriver/actions_api/

## Usage

The Appium Python Client is fully compliant with the WebDriver Protocol
including several helpers to make mobile testing in Python easier.

To use the new functionality now, and to use the superset of functions, instead of
including the Selenium `webdriver` module in your test code, use that from
Appium instead.

```python
from appium import webdriver
```

From there much of your test code will work with no change.

As a base for the following code examples, the following set up the [UnitTest](https://docs.python.org/3/library/unittest.html)
environment:

```python
# Python/Pytest
import pytest

from appium import webdriver
# Options are only available since client version 2.3.0
# If you use an older client then switch to desired_capabilities
# instead: https://github.com/appium/python-client/pull/720
from appium.options.android import UiAutomator2Options
from appium.options.ios import XCUITestOptions
from appium.webdriver.appium_service import AppiumService
from appium.webdriver.common.appiumby import AppiumBy

APPIUM_PORT = 4723
APPIUM_HOST = '127.0.0.1'


# HINT: fixtures below could be extracted into conftest.py
# HINT: and shared across all tests in the suite
@pytest.fixture(scope='session')
def appium_service():
    service = AppiumService()
    service.start(
        # Check the output of `appium server --help` for the complete list of
        # server command line arguments
        args=['--address', APPIUM_HOST, '-p', str(APPIUM_PORT)],
        timeout_ms=20000,
    )
    yield service
    service.stop()


def create_ios_driver(custom_opts = None):
    options = XCUITestOptions()
    options.platformVersion = '13.4'
    options.udid = '123456789ABC'
    if custom_opts is not None:
        options.load_capabilities(custom_opts)
    # Appium1 points to http://127.0.0.1:4723/wd/hub by default
    return webdriver.Remote(f'http://{APPIUM_HOST}:{APPIUM_PORT}', options=options)


def create_android_driver(custom_opts = None):
    options = UiAutomator2Options()
    options.platformVersion = '10'
    options.udid = '123456789ABC'
    if custom_opts is not None:
        options.load_capabilities(custom_opts)
    # Appium1 points to http://127.0.0.1:4723/wd/hub by default
    return webdriver.Remote(f'http://{APPIUM_HOST}:{APPIUM_PORT}', options=options)


@pytest.fixture
def ios_driver_factory():
    return create_ios_driver


@pytest.fixture
def ios_driver():
    # prefer this fixture if there is no need to customize driver options in tests
    driver = create_ios_driver()
    yield driver
    driver.quit()


@pytest.fixture
def android_driver_factory():
    return create_android_driver


@pytest.fixture
def android_driver():
    # prefer this fixture if there is no need to customize driver options in tests
    driver = create_android_driver()
    yield driver
    driver.quit()


def test_ios_click(appium_service, ios_driver_factory):
    # Usage of the context manager ensures the driver session is closed properly
    # after the test completes. Otherwise, make sure to call `driver.quit()` on teardown.
    with ios_driver_factory({
        'appium:app': '/path/to/app/UICatalog.app.zip'
    }) as driver:
        el = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='item')
        el.click()


def test_android_click(appium_service, android_driver_factory):
    # Usage of the context manager ensures the driver session is closed properly
    # after the test completes. Otherwise, make sure to call `driver.quit()` on teardown.
    with android_driver_factory({
        'appium:app': '/path/to/app/test-app.apk',
        'appium:udid': '567890',
    }) as driver:
        el = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='item')
        el.click()
```

## Direct Connect URLs

If your Selenium/Appium server decorates the new session capabilities response with the following keys:

- `directConnectProtocol`
- `directConnectHost`
- `directConnectPort`
- `directConnectPath`

Then python client will switch its endpoint to the one specified by the values of those keys.

```python
from appium import webdriver
# Options are only available since client version 2.3.0
# If you use an older client then switch to desired_capabilities
# instead: https://github.com/appium/python-client/pull/720
from appium.options.ios import XCUITestOptions

# load_capabilities API could be used to
# load options mapping stored in a dictionary
options = XCUITestOptions().load_capabilities({
    'platformVersion': '13.4',
    'deviceName': 'iPhone Simulator',
    'app': '/full/path/to/app/UICatalog.app.zip',
})

driver = webdriver.Remote(
    # Appium1 points to http://127.0.0.1:4723/wd/hub by default
    'http://127.0.0.1:4723',
    options=options,
    direct_connection=True
)
```

## Relax SSL validation

`strict_ssl` option allows you to send commands to an invalid certificate host like a self-signed one.

```python
from appium import webdriver
# Options are only available since client version 2.3.0
# If you use an older client then switch to desired_capabilities
# instead: https://github.com/appium/python-client/pull/720
from appium.options.common import AppiumOptions

options = AppiumOptions()
options.platform_name = 'mac'
options.automation_name = 'safari'
# set_capability API allows to provide any custom option
# calls to it could be chained
options.set_capability('browser_name', 'safari')

# Appium1 points to http://127.0.0.1:4723/wd/hub by default
driver = webdriver.Remote('http://127.0.0.1:4723', options=options, strict_ssl=False)
```

## Set custom `AppiumConnection`

The first argument of `webdriver.Remote` can set an arbitrary command executor for you.

1. Set init arguments for the pool manager Appium Python client uses to manage HTTP requests.

```python
from appium import webdriver
from appium.options.ios import XCUITestOptions

import urllib3
from appium.webdriver.appium_connection import AppiumConnection

# Retry connection error up to 3 times.
init_args_for_pool_manage = {
    'retries': urllib3.util.retry.Retry(total=3, connect=3, read=False)
}
appium_executor = AppiumConnection(
    remote_server_addr='http://127.0.0.1:4723',
    init_args_for_pool_manage=init_args_for_pool_manage
)

options = XCUITestOptions()
options.platformVersion = '13.4'
options.udid = '123456789ABC'
options.app = '/full/path/to/app/UICatalog.app.zip'
driver = webdriver.Remote(appium_executor, options=options)
```


2. Define a subclass of `AppiumConnection`

```python
from appium import webdriver
from appium.options.ios import XCUITestOptions

from appium.webdriver.appium_connection import AppiumConnection

class CustomAppiumConnection(AppiumConnection):
    # Can add your own methods for the custom class
    pass

custom_executor = CustomAppiumConnection(remote_server_addr='http://127.0.0.1:4723')

options = XCUITestOptions().load_capabilities({
    'platformVersion': '13.4',
    'deviceName': 'iPhone Simulator',
    'app': '/full/path/to/app/UICatalog.app.zip',
})
driver = webdriver.Remote(custom_executor, options=options)

```


## Documentation

- https://appium.github.io/python-client-sphinx/ is detailed documentation
- [functional tests](test/functional) also may help to see concrete examples.

## Development

- Code Style: [PEP-0008](https://www.python.org/dev/peps/pep-0008/)
  - Apply `black`, `isort` and `mypy` as pre commit hook
  - Run `make` command for development. See `make help` output for details
- Docstring style: [Google Style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html)
- `gitchangelog` generates `CHANGELOG.rst`

### Setup

- `pip install --user pipenv`
- `python -m pipenv lock --clear`
  - If you experience `Locking Failed! unknown locale: UTF-8` error, then refer [pypa/pipenv#187](https://github.com/pypa/pipenv/issues/187) to solve it.
- `python -m pipenv install --dev --system`
- `pre-commit install`

### Run tests

You can run all of the tests running on CI via `tox` in your local.

```bash
$ tox
```

You also can run particular tests like below.

#### Unit

```bash
$ pytest test/unit
```

Run with `pytest-xdist`

```bash
$ pytest -n 2 test/unit
```

#### Functional

```bash
$ pytest test/functional/ios/search_context/find_by_ios_class_chain_tests.py
```

#### In parallel for iOS

1. Create simulators named 'iPhone X - 8100' and 'iPhone X - 8101'
2. Install test libraries via pip, `pip install pytest pytest-xdist`
3. Run tests

```bash
$ pytest -n 2 test/functional/ios/search_context/find_by_ios_class_chain_tests.py
```

## Release

Follow the below steps.

```bash
$ pip install twine
$ pip install git+git://github.com/vaab/gitchangelog.git # Getting via GitHub repository is necessary for Python 3.7
# Type the new version number and 'yes' if you can publish it
# You can test the command with DRY_RUN
$ DRY_RUN=1 ./release.sh
$ ./release.sh # release
```

## License

Apache License v2

            

Raw data

            {
    "_id": null,
    "home_page": "http://appium.io/",
    "name": "Appium-Python-Client",
    "maintainer": "Kazuaki Matsuo, Mykola Mokhnach, Mori Atsushi",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "appium,selenium,selenium 4,python client,mobile automation",
    "author": "Isaac Murchie",
    "author_email": "isaac@saucelabs.com",
    "download_url": "https://files.pythonhosted.org/packages/5f/a7/979639464093481bb5fe48e22598a4482a9e4fc660988fcc7237efdc2b58/Appium-Python-Client-4.0.0.tar.gz",
    "platform": null,
    "description": "# Appium Python Client\n\n[![PyPI version](https://badge.fury.io/py/Appium-Python-Client.svg)](https://badge.fury.io/py/Appium-Python-Client)\n[![Downloads](https://pepy.tech/badge/appium-python-client)](https://pepy.tech/project/appium-python-client)\n\n[![Build Status](https://dev.azure.com/AppiumCI/Appium%20CI/_apis/build/status/appium.python-client?branchName=master)](https://dev.azure.com/AppiumCI/Appium%20CI/_build/latest?definitionId=56&branchName=master)\n\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\nAn extension library for adding [WebDriver Protocol](https://www.w3.org/TR/webdriver/) and Appium commands to the Selenium Python language binding for use with the mobile testing framework [Appium](https://appium.io).\n\n## Getting the Appium Python client\n\nThere are three ways to install and use the Appium Python client.\n\n1. Install from [PyPi](https://pypi.org), as\n['Appium-Python-Client'](https://pypi.org/project/Appium-Python-Client/).\n\n    ```shell\n    pip install Appium-Python-Client\n    ```\n\n    You can see the history from [here](https://pypi.org/project/Appium-Python-Client/#history)\n\n2. Install from source, via [PyPi](https://pypi.org). From ['Appium-Python-Client'](https://pypi.org/project/Appium-Python-Client/),\ndownload and unarchive the source tarball (Appium-Python-Client-X.X.tar.gz).\n\n    ```shell\n    tar -xvf Appium-Python-Client-X.X.tar.gz\n    cd Appium-Python-Client-X.X\n    python setup.py install\n    ```\n\n3. Install from source via [GitHub](https://github.com/appium/python-client).\n\n    ```shell\n    git clone git@github.com:appium/python-client.git\n    cd python-client\n    python setup.py install\n    ```\n\n## Compatibility Matrix\n\n|Appium Python Client| Selenium binding| Python version |\n|----|----|----|\n|`3.0.0`+ |`4.12.0`+ | 3.8+ |\n|`2.10.0` - `2.11.1` |`4.1.0` - `4.11.2` | 3.7+ |\n|`2.2.0` - `2.9.0` |`4.1.0` - `4.9.0` | 3.7+ |\n|`2.0.0` - `2.1.4` |`4.0.0` | 3.7+ |\n|`1.0.0` - `1.1.0` |`3.x`| 3.7, 3.8 |\n|`0.52` and below|`3.x`| 2.7, 3.4 - 3.7 |\n\nThe Appium Python Client depends on [Selenium Python binding](https://pypi.org/project/selenium/), thus\nthe Selenium Python binding update might affect the Appium Python Client behavior.\nFor example, some changes in the Selenium binding could break the Appium client.\n\n> **Note**\n> We strongly recommend you manage dependencies with version management tools such as Pipenv and requirements.txt\n> to keep compatible version combinations.\n\n\n### Quick migration guide from v3 to v4\n- Removal\n    - `MultiAction` and `TouchAction` are removed. Please use W3C WebDriver actions or `mobile:` extensions\n        - [appium/webdriver/extensions/action_helpers.py](appium/webdriver/extensions/action_helpers.py)\n        - https://www.selenium.dev/documentation/webdriver/actions_api/\n        - https://www.youtube.com/watch?v=oAJ7jwMNFVU\n        - https://appiumpro.com/editions/30-ios-specific-touch-action-methods\n        - https://appiumpro.com/editions/29-automating-complex-gestures-with-the-w3c-actions-api\n    - Deprecated `AppiumBy.WINDOWS_UI_AUTOMATION`, which has no usage right now.\n\n### Quick migration guide from v2 to v3\n- `options` keyword argument in the `webdriver.Remote` constructor such as `XCUITestOptions` instead of `desired_capabilities`\n    - Available options are https://github.com/appium/python-client/tree/master/appium/options\n        - Please check the [Usage](#usage) below as an exampple.\n    - Not a \"new\" change, but the `desired_capabilities` argument has been removed since v3.\n- Replacement\n    - `start_activity` method: Please use [`mobile: startActivity`](https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#mobile-startactivity)\n    - `launch_app`, `close_app` and `reset` methods: Please refer to https://github.com/appium/appium/issues/15807\n    - `available_ime_engines`, `is_ime_active`, `activate_ime_engine`, `deactivate_ime_engine` and `active_ime_engine` methods: Please use [`mobile: shell`](https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#mobile-shell)\n    - `set_value` and `set_text` methods: Please use `element.send_keys` or `send_keys` by W3C Actions\n- Removal\n    - `end_test_coverage` method is no longer available\n    - `session` property is no longer available\n    - `all_sessions` property is no longer available\n\n### Quick migration guide from v1 to v2\n- Enhancement\n    - Updated base Selenium Python binding version to v4\n        - Removed `forceMjsonwp` since Selenium v4 and Appium Python client v2 expect only W3C WebDriver protocol\n    - Methods `ActionHelpers#scroll`, `ActionHelpers#drag_and_drop`, `ActionHelpers#tap`, `ActionHelpers#swipe` and `ActionHelpers#flick` now call W3C actions as its backend\n        - Please check each behavior. Their behaviors could slightly differ.\n    - Added `strict_ssl` to relax SSL errors such as self-signed ones\n- Deprecated\n    - `MultiAction` and `TouchAction` are deprecated. Please use W3C WebDriver actions or `mobile:` extensions\n    - `launch_app`, `close_app`, and `reset` are deprecated. Please read [issues#15807](https://github.com/appium/appium/issues/15807) for more details\n\n#### MultiAction/TouchAction to W3C actions\n\nOn UIA2, some elements can be handled with `touch` pointer action instead of the default `mouse` pointer action in the Selenium Python client.\nFor example, the below action builder is to replace the default one with the `touch` pointer action.\n\n```python\nfrom selenium.webdriver import ActionChains\nfrom selenium.webdriver.common.actions import interaction\nfrom selenium.webdriver.common.actions.action_builder import ActionBuilder\nfrom selenium.webdriver.common.actions.pointer_input import PointerInput\n\nactions = ActionChains(driver)\n# override as 'touch' pointer action\nactions.w3c_actions = ActionBuilder(driver, mouse=PointerInput(interaction.POINTER_TOUCH, \"touch\"))\nactions.w3c_actions.pointer_action.move_to_location(start_x, start_y)\nactions.w3c_actions.pointer_action.pointer_down()\nactions.w3c_actions.pointer_action.pause(2)\nactions.w3c_actions.pointer_action.move_to_location(end_x, end_y)\nactions.w3c_actions.pointer_action.release()\nactions.perform()\n```\n\n- [appium/webdriver/extensions/action_helpers.py](appium/webdriver/extensions/action_helpers.py)\n- https://www.selenium.dev/documentation/webdriver/actions_api/\n\n## Usage\n\nThe Appium Python Client is fully compliant with the WebDriver Protocol\nincluding several helpers to make mobile testing in Python easier.\n\nTo use the new functionality now, and to use the superset of functions, instead of\nincluding the Selenium `webdriver` module in your test code, use that from\nAppium instead.\n\n```python\nfrom appium import webdriver\n```\n\nFrom there much of your test code will work with no change.\n\nAs a base for the following code examples, the following set up the [UnitTest](https://docs.python.org/3/library/unittest.html)\nenvironment:\n\n```python\n# Python/Pytest\nimport pytest\n\nfrom appium import webdriver\n# Options are only available since client version 2.3.0\n# If you use an older client then switch to desired_capabilities\n# instead: https://github.com/appium/python-client/pull/720\nfrom appium.options.android import UiAutomator2Options\nfrom appium.options.ios import XCUITestOptions\nfrom appium.webdriver.appium_service import AppiumService\nfrom appium.webdriver.common.appiumby import AppiumBy\n\nAPPIUM_PORT = 4723\nAPPIUM_HOST = '127.0.0.1'\n\n\n# HINT: fixtures below could be extracted into conftest.py\n# HINT: and shared across all tests in the suite\n@pytest.fixture(scope='session')\ndef appium_service():\n    service = AppiumService()\n    service.start(\n        # Check the output of `appium server --help` for the complete list of\n        # server command line arguments\n        args=['--address', APPIUM_HOST, '-p', str(APPIUM_PORT)],\n        timeout_ms=20000,\n    )\n    yield service\n    service.stop()\n\n\ndef create_ios_driver(custom_opts = None):\n    options = XCUITestOptions()\n    options.platformVersion = '13.4'\n    options.udid = '123456789ABC'\n    if custom_opts is not None:\n        options.load_capabilities(custom_opts)\n    # Appium1 points to http://127.0.0.1:4723/wd/hub by default\n    return webdriver.Remote(f'http://{APPIUM_HOST}:{APPIUM_PORT}', options=options)\n\n\ndef create_android_driver(custom_opts = None):\n    options = UiAutomator2Options()\n    options.platformVersion = '10'\n    options.udid = '123456789ABC'\n    if custom_opts is not None:\n        options.load_capabilities(custom_opts)\n    # Appium1 points to http://127.0.0.1:4723/wd/hub by default\n    return webdriver.Remote(f'http://{APPIUM_HOST}:{APPIUM_PORT}', options=options)\n\n\n@pytest.fixture\ndef ios_driver_factory():\n    return create_ios_driver\n\n\n@pytest.fixture\ndef ios_driver():\n    # prefer this fixture if there is no need to customize driver options in tests\n    driver = create_ios_driver()\n    yield driver\n    driver.quit()\n\n\n@pytest.fixture\ndef android_driver_factory():\n    return create_android_driver\n\n\n@pytest.fixture\ndef android_driver():\n    # prefer this fixture if there is no need to customize driver options in tests\n    driver = create_android_driver()\n    yield driver\n    driver.quit()\n\n\ndef test_ios_click(appium_service, ios_driver_factory):\n    # Usage of the context manager ensures the driver session is closed properly\n    # after the test completes. Otherwise, make sure to call `driver.quit()` on teardown.\n    with ios_driver_factory({\n        'appium:app': '/path/to/app/UICatalog.app.zip'\n    }) as driver:\n        el = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='item')\n        el.click()\n\n\ndef test_android_click(appium_service, android_driver_factory):\n    # Usage of the context manager ensures the driver session is closed properly\n    # after the test completes. Otherwise, make sure to call `driver.quit()` on teardown.\n    with android_driver_factory({\n        'appium:app': '/path/to/app/test-app.apk',\n        'appium:udid': '567890',\n    }) as driver:\n        el = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='item')\n        el.click()\n```\n\n## Direct Connect URLs\n\nIf your Selenium/Appium server decorates the new session capabilities response with the following keys:\n\n- `directConnectProtocol`\n- `directConnectHost`\n- `directConnectPort`\n- `directConnectPath`\n\nThen python client will switch its endpoint to the one specified by the values of those keys.\n\n```python\nfrom appium import webdriver\n# Options are only available since client version 2.3.0\n# If you use an older client then switch to desired_capabilities\n# instead: https://github.com/appium/python-client/pull/720\nfrom appium.options.ios import XCUITestOptions\n\n# load_capabilities API could be used to\n# load options mapping stored in a dictionary\noptions = XCUITestOptions().load_capabilities({\n    'platformVersion': '13.4',\n    'deviceName': 'iPhone Simulator',\n    'app': '/full/path/to/app/UICatalog.app.zip',\n})\n\ndriver = webdriver.Remote(\n    # Appium1 points to http://127.0.0.1:4723/wd/hub by default\n    'http://127.0.0.1:4723',\n    options=options,\n    direct_connection=True\n)\n```\n\n## Relax SSL validation\n\n`strict_ssl` option allows you to send commands to an invalid certificate host like a self-signed one.\n\n```python\nfrom appium import webdriver\n# Options are only available since client version 2.3.0\n# If you use an older client then switch to desired_capabilities\n# instead: https://github.com/appium/python-client/pull/720\nfrom appium.options.common import AppiumOptions\n\noptions = AppiumOptions()\noptions.platform_name = 'mac'\noptions.automation_name = 'safari'\n# set_capability API allows to provide any custom option\n# calls to it could be chained\noptions.set_capability('browser_name', 'safari')\n\n# Appium1 points to http://127.0.0.1:4723/wd/hub by default\ndriver = webdriver.Remote('http://127.0.0.1:4723', options=options, strict_ssl=False)\n```\n\n## Set custom `AppiumConnection`\n\nThe first argument of `webdriver.Remote` can set an arbitrary command executor for you.\n\n1. Set init arguments for the pool manager Appium Python client uses to manage HTTP requests.\n\n```python\nfrom appium import webdriver\nfrom appium.options.ios import XCUITestOptions\n\nimport urllib3\nfrom appium.webdriver.appium_connection import AppiumConnection\n\n# Retry connection error up to 3 times.\ninit_args_for_pool_manage = {\n    'retries': urllib3.util.retry.Retry(total=3, connect=3, read=False)\n}\nappium_executor = AppiumConnection(\n    remote_server_addr='http://127.0.0.1:4723',\n    init_args_for_pool_manage=init_args_for_pool_manage\n)\n\noptions = XCUITestOptions()\noptions.platformVersion = '13.4'\noptions.udid = '123456789ABC'\noptions.app = '/full/path/to/app/UICatalog.app.zip'\ndriver = webdriver.Remote(appium_executor, options=options)\n```\n\n\n2. Define a subclass of `AppiumConnection`\n\n```python\nfrom appium import webdriver\nfrom appium.options.ios import XCUITestOptions\n\nfrom appium.webdriver.appium_connection import AppiumConnection\n\nclass CustomAppiumConnection(AppiumConnection):\n    # Can add your own methods for the custom class\n    pass\n\ncustom_executor = CustomAppiumConnection(remote_server_addr='http://127.0.0.1:4723')\n\noptions = XCUITestOptions().load_capabilities({\n    'platformVersion': '13.4',\n    'deviceName': 'iPhone Simulator',\n    'app': '/full/path/to/app/UICatalog.app.zip',\n})\ndriver = webdriver.Remote(custom_executor, options=options)\n\n```\n\n\n## Documentation\n\n- https://appium.github.io/python-client-sphinx/ is detailed documentation\n- [functional tests](test/functional) also may help to see concrete examples.\n\n## Development\n\n- Code Style: [PEP-0008](https://www.python.org/dev/peps/pep-0008/)\n  - Apply `black`, `isort` and `mypy` as pre commit hook\n  - Run `make` command for development. See `make help` output for details\n- Docstring style: [Google Style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html)\n- `gitchangelog` generates `CHANGELOG.rst`\n\n### Setup\n\n- `pip install --user pipenv`\n- `python -m pipenv lock --clear`\n  - If you experience `Locking Failed! unknown locale: UTF-8` error, then refer [pypa/pipenv#187](https://github.com/pypa/pipenv/issues/187) to solve it.\n- `python -m pipenv install --dev --system`\n- `pre-commit install`\n\n### Run tests\n\nYou can run all of the tests running on CI via `tox` in your local.\n\n```bash\n$ tox\n```\n\nYou also can run particular tests like below.\n\n#### Unit\n\n```bash\n$ pytest test/unit\n```\n\nRun with `pytest-xdist`\n\n```bash\n$ pytest -n 2 test/unit\n```\n\n#### Functional\n\n```bash\n$ pytest test/functional/ios/search_context/find_by_ios_class_chain_tests.py\n```\n\n#### In parallel for iOS\n\n1. Create simulators named 'iPhone X - 8100' and 'iPhone X - 8101'\n2. Install test libraries via pip, `pip install pytest pytest-xdist`\n3. Run tests\n\n```bash\n$ pytest -n 2 test/functional/ios/search_context/find_by_ios_class_chain_tests.py\n```\n\n## Release\n\nFollow the below steps.\n\n```bash\n$ pip install twine\n$ pip install git+git://github.com/vaab/gitchangelog.git # Getting via GitHub repository is necessary for Python 3.7\n# Type the new version number and 'yes' if you can publish it\n# You can test the command with DRY_RUN\n$ DRY_RUN=1 ./release.sh\n$ ./release.sh # release\n```\n\n## License\n\nApache License v2\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "Python client for Appium",
    "version": "4.0.0",
    "project_urls": {
        "Homepage": "http://appium.io/"
    },
    "split_keywords": [
        "appium",
        "selenium",
        "selenium 4",
        "python client",
        "mobile automation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5fa7979639464093481bb5fe48e22598a4482a9e4fc660988fcc7237efdc2b58",
                "md5": "bfc9ba015dd1e8a0c47095dadcb64dd6",
                "sha256": "d13cbd6dd81d0290701ba451145ec7ebf5a6d74222bdaefc12b62ef6f56a1fd6"
            },
            "downloads": -1,
            "filename": "Appium-Python-Client-4.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bfc9ba015dd1e8a0c47095dadcb64dd6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3360305,
            "upload_time": "2024-03-12T04:56:52",
            "upload_time_iso_8601": "2024-03-12T04:56:52.852446Z",
            "url": "https://files.pythonhosted.org/packages/5f/a7/979639464093481bb5fe48e22598a4482a9e4fc660988fcc7237efdc2b58/Appium-Python-Client-4.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-12 04:56:52",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "appium-python-client"
}
        
Elapsed time: 0.19965s