Skip to main content

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)

Metadata

Release files for pytest-stf 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-stf 0.3.0
File Size Uploaded Provenance Actions
pytest-stf-0.3.0.tar.gz 7.8 kB Without provenance Details for pytest-stf-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-stf 0.3.0
File Interpreter ABI Platform Actions
pytest_stf-0.3.0-py3-none-any.whl Python 3 none any Details for pytest_stf-0.3.0-py3-none-any.whl

Total release size: 13.1 kB

Release files / pytest-stf-0.3.0.tar.gz

Download URL pytest-stf-0.3.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a6883362b53268d2b0e27e5eaca27b95863359fdd19de8a4c23d7e8b088819f5
BLAKE2b-256 checksum
How to use checksums
852b50ebae0868abeb2e12dd6fc7226a43482b7ab3d6b8f4a170e91a3aa440f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / pytest_stf-0.3.0-py3-none-any.whl

Download URL pytest_stf-0.3.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad9b73d56a39562193afa1e9dce7d6f7c7ec2f005003978b911c2b2303689af7
BLAKE2b-256 checksum
How to use checksums
73d9165def4c5fca1fa3c53f4dcc21de1fc7f47eb1bd320abb301beaa307e565
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Security for pytest-stf 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page