pytest-stf


Namepytest-stf JSON
Version 0.6.1 PyPI version JSON
download
home_pagehttps://github.com/opentmi/pytest-stf
Summarypytest plugin for openSTF
upload_time2024-03-25 10:03:02
maintainerNone
docs_urlNone
authorJussi Vatjus-Anttila
requires_python>=3.8
licenseMozilla Public License 2.0 (MPL 2.0)
keywords py.test pytest openstf android phone
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![pytest-stf](https://github.com/OpenTMI/pytest-stf/actions/workflows/test.yml/badge.svg)](https://github.com/OpenTMI/pytest-stf/actions/workflows/test.yml) [![PyPI version](https://badge.fury.io/py/pytest-stf.svg)](https://pypi.org/project/pytest-stf/)


## pytest plugin for OpenSTF

Plugin for simplify [OpenSTF](https://github.com/DeviceFarmer/stf) usage with pytest 
framework by providing simple fixture that do all primitive tasks for appium based tests.

Target is to easily scale up tests in CI environment where external stf service is used to 
provide android phones.

Plugin based on [stf-appium-python-client](https://github.com/OpenTMI/stf-appium-python-client)


## pytest arguments
```
openstf:
  --stf_host=STF_HOST   Openstf host
  --stf_token=STF_TOKEN
                        Openstf access token
  --phone_requirements=PHONE_REQUIREMENTS
                        Phone requirements
  --stf_allocation_timeout=STF_ALLOCATION_TIMEOUT
                        Maximum time in seconds after which STF releases allocated devices
  --appium_server=APPIUM_SERVER
                        Appium server API URL
  --appium_capabilities=APPIUM_CAPABILITIES
                        Appium capabilities
  --appium_logs=APPIUM_LOGS
                        Appium server log file path
```

## Fixtures

### `allocated_phone`

- Session scoped
- Find and allocate a phone based on `--phone_requirements` cli argument from STF or using pytest-lockable

**NOTE:** only one phone is handled by this fixture.

### `phone_with_adb`

- Session scoped
- Depends on `allocated_phone`
- Create ADB tunnel to phone if using STF

**NOTE:** `Android SDK` (commandline tools, platform tools and build tools) need to be installed separately!

### `appium_server`

- Session scoped
- Depends on `phone_with_adb`
- Start Appium server or alternatively use remote one passed via `--appium_server` cli argument or `appium_server` lockable resource property

**NOTE:** `appium` need to be installed separately! (`npm i appium`) .

### `appium_client`

- Session scoped
- Depends on `appium_server`
- Start Appium webdriver client

### `capabilities`

- Session scoped
- Returns arguments passed to Appium webdriver
- Tests can override this fixture in order to pass custom arguments

### `appium_args`

- Session scoped
- Returns arguments passed to Appium server
- Tests can override this fixture in order to pass custom arguments

## Usage example

*sample.py:*

```python

from appium.webdriver.webdriver import WebDriver


def test_create(appium_client):
    client, appium, adb, phone = appium_client
    # device is dictionary of device metadata
    # adb: AdbServer instance, that is already connected
    # appium: AppiumServer instance that provide server address for appium client
    print(phone)
    print(f'wd_hub: {appium.get_api_path()}')
    
    client: WebDriver
    client, *_ = appium_client
    URL = 'https://google.com'
    client.get(URL)
    url = client.current_url
    assert url == URL, 'Wrong URL'
```

Execution:
```
> pytest sample/test_samples.py --stf_host localhost --stf_token $TOKEN --phone_requirements platform=Android
```


See more examples from [sample/test_samples.py](sample/test_samples.py).

Custom capabilities:
```
> pytest --appium_capabilities cab=val1&cab=val2
```

### Usage with local devices

Testing with a local device you can omit `--stf_host` and `--stf_token` cli arguments and use lockable resources file (defaults to `resources.json`).

`resources.json` example:
```
[
  {
    "id": "1",
    "type": "Phone",
    "platform": "Android",
    "online": true,
    "hostname": <HOSTNAME>,
    "version": "12",
    "appium_server": "http://localhost:4723"
  }
]
```

Execution:
```
> pytest sample/test_samples.py --phone_requirements platform=Android
```

**NOTE:** Appium server need to be run separately! (`appium -a 127.0.0.1`)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/opentmi/pytest-stf",
    "name": "pytest-stf",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "py.test pytest openstf android phone",
    "author": "Jussi Vatjus-Anttila",
    "author_email": "jussiva@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a2/3d/b6afe2caa376b641ecc8110bfa65d45db02daa81a6a982e109e865440ad6/pytest-stf-0.6.1.tar.gz",
    "platform": null,
    "description": "[![pytest-stf](https://github.com/OpenTMI/pytest-stf/actions/workflows/test.yml/badge.svg)](https://github.com/OpenTMI/pytest-stf/actions/workflows/test.yml) [![PyPI version](https://badge.fury.io/py/pytest-stf.svg)](https://pypi.org/project/pytest-stf/)\n\n\n## pytest plugin for OpenSTF\n\nPlugin for simplify [OpenSTF](https://github.com/DeviceFarmer/stf) usage with pytest \nframework by providing simple fixture that do all primitive tasks for appium based tests.\n\nTarget is to easily scale up tests in CI environment where external stf service is used to \nprovide android phones.\n\nPlugin based on [stf-appium-python-client](https://github.com/OpenTMI/stf-appium-python-client)\n\n\n## pytest arguments\n```\nopenstf:\n  --stf_host=STF_HOST   Openstf host\n  --stf_token=STF_TOKEN\n                        Openstf access token\n  --phone_requirements=PHONE_REQUIREMENTS\n                        Phone requirements\n  --stf_allocation_timeout=STF_ALLOCATION_TIMEOUT\n                        Maximum time in seconds after which STF releases allocated devices\n  --appium_server=APPIUM_SERVER\n                        Appium server API URL\n  --appium_capabilities=APPIUM_CAPABILITIES\n                        Appium capabilities\n  --appium_logs=APPIUM_LOGS\n                        Appium server log file path\n```\n\n## Fixtures\n\n### `allocated_phone`\n\n- Session scoped\n- Find and allocate a phone based on `--phone_requirements` cli argument from STF or using pytest-lockable\n\n**NOTE:** only one phone is handled by this fixture.\n\n### `phone_with_adb`\n\n- Session scoped\n- Depends on `allocated_phone`\n- Create ADB tunnel to phone if using STF\n\n**NOTE:** `Android SDK` (commandline tools, platform tools and build tools) need to be installed separately!\n\n### `appium_server`\n\n- Session scoped\n- Depends on `phone_with_adb`\n- Start Appium server or alternatively use remote one passed via `--appium_server` cli argument or `appium_server` lockable resource property\n\n**NOTE:** `appium` need to be installed separately! (`npm i appium`) .\n\n### `appium_client`\n\n- Session scoped\n- Depends on `appium_server`\n- Start Appium webdriver client\n\n### `capabilities`\n\n- Session scoped\n- Returns arguments passed to Appium webdriver\n- Tests can override this fixture in order to pass custom arguments\n\n### `appium_args`\n\n- Session scoped\n- Returns arguments passed to Appium server\n- Tests can override this fixture in order to pass custom arguments\n\n## Usage example\n\n*sample.py:*\n\n```python\n\nfrom appium.webdriver.webdriver import WebDriver\n\n\ndef test_create(appium_client):\n    client, appium, adb, phone = appium_client\n    # device is dictionary of device metadata\n    # adb: AdbServer instance, that is already connected\n    # appium: AppiumServer instance that provide server address for appium client\n    print(phone)\n    print(f'wd_hub: {appium.get_api_path()}')\n    \n    client: WebDriver\n    client, *_ = appium_client\n    URL = 'https://google.com'\n    client.get(URL)\n    url = client.current_url\n    assert url == URL, 'Wrong URL'\n```\n\nExecution:\n```\n> pytest sample/test_samples.py --stf_host localhost --stf_token $TOKEN --phone_requirements platform=Android\n```\n\n\nSee more examples from [sample/test_samples.py](sample/test_samples.py).\n\nCustom capabilities:\n```\n> pytest --appium_capabilities cab=val1&cab=val2\n```\n\n### Usage with local devices\n\nTesting with a local device you can omit `--stf_host` and `--stf_token` cli arguments and use lockable resources file (defaults to `resources.json`).\n\n`resources.json` example:\n```\n[\n  {\n    \"id\": \"1\",\n    \"type\": \"Phone\",\n    \"platform\": \"Android\",\n    \"online\": true,\n    \"hostname\": <HOSTNAME>,\n    \"version\": \"12\",\n    \"appium_server\": \"http://localhost:4723\"\n  }\n]\n```\n\nExecution:\n```\n> pytest sample/test_samples.py --phone_requirements platform=Android\n```\n\n**NOTE:** Appium server need to be run separately! (`appium -a 127.0.0.1`)\n",
    "bugtrack_url": null,
    "license": "Mozilla Public License 2.0 (MPL 2.0)",
    "summary": "pytest plugin for openSTF",
    "version": "0.6.1",
    "project_urls": {
        "Homepage": "https://github.com/opentmi/pytest-stf"
    },
    "split_keywords": [
        "py.test",
        "pytest",
        "openstf",
        "android",
        "phone"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "12421492a33fffc41e39ac9f192c4fc7da0a21465e4aa2815ec1a8f16dbedd06",
                "md5": "baa16aec7707f8befc37278252d43239",
                "sha256": "0be053e6c70e90dcb1059d2d90eee99f0032e667f5c2833f6fa242e25c40d6b8"
            },
            "downloads": -1,
            "filename": "pytest_stf-0.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "baa16aec7707f8befc37278252d43239",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5328,
            "upload_time": "2024-03-25T10:03:00",
            "upload_time_iso_8601": "2024-03-25T10:03:00.943718Z",
            "url": "https://files.pythonhosted.org/packages/12/42/1492a33fffc41e39ac9f192c4fc7da0a21465e4aa2815ec1a8f16dbedd06/pytest_stf-0.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a23db6afe2caa376b641ecc8110bfa65d45db02daa81a6a982e109e865440ad6",
                "md5": "9a59da72869780a33ec97727c1896559",
                "sha256": "ff60da321f3e0f84f64b5fa6ed5edcb54c68ca9a925ae79c90951c8dd364e7b9"
            },
            "downloads": -1,
            "filename": "pytest-stf-0.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9a59da72869780a33ec97727c1896559",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7867,
            "upload_time": "2024-03-25T10:03:02",
            "upload_time_iso_8601": "2024-03-25T10:03:02.916325Z",
            "url": "https://files.pythonhosted.org/packages/a2/3d/b6afe2caa376b641ecc8110bfa65d45db02daa81a6a982e109e865440ad6/pytest-stf-0.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-25 10:03:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "opentmi",
    "github_project": "pytest-stf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-stf"
}
        
Elapsed time: 0.21339s