Skip to main content

pytest plugin for openSTF

Project description

pytest-stf PyPI version

pytest plugin for OpenSTF

Plugin for simplify OpenSTF 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

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:

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.

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-stf-0.8.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_stf-0.8.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest-stf-0.8.0.tar.gz.

File metadata

  • Download URL: pytest-stf-0.8.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for pytest-stf-0.8.0.tar.gz
Algorithm Hash digest
SHA256 f479933cd39e9aa02de0e249e1f92bf56ea7bda8fd55166e55a3cc2e52e891fb
MD5 ee92df39f654776680ee9b53a4d39a41
BLAKE2b-256 f7b8db8c8238a423708a20f6f780859caf053d857642805ba0d5fe859d99c162

See more details on using hashes here.

File details

Details for the file pytest_stf-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_stf-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for pytest_stf-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 233d405e670a247843b5eefa0c92d63798a44eec668cbf04e70419ed5ae59a38
MD5 0e60d8408c1aa04dcada364393aacbf5
BLAKE2b-256 e4f0e1affcee94bf58f9b47321367a5b1ef613cef965b47315bfb56bc671f1e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page