{"id":19509263,"url":"https://github.com/opentmi/pytest-stf","last_synced_at":"2025-02-25T22:43:21.364Z","repository":{"id":58929690,"uuid":"440411659","full_name":"OpenTMI/pytest-stf","owner":"OpenTMI","description":"pytest plugin for stf usage","archived":false,"fork":false,"pushed_at":"2024-03-25T10:02:20.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-27T16:47:32.876Z","etag":null,"topics":["adb","android","appium","openstf","pytest","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenTMI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-21T06:19:03.000Z","updated_at":"2022-12-15T00:00:07.000Z","dependencies_parsed_at":"2024-11-10T23:11:42.299Z","dependency_job_id":"7a34a182-f496-4802-8063-ac202d8d6ad8","html_url":"https://github.com/OpenTMI/pytest-stf","commit_stats":{"total_commits":19,"total_committers":3,"mean_commits":6.333333333333333,"dds":0.1578947368421053,"last_synced_commit":"cfdd4fa37fb5298f65064271d9f141aa9946c5dd"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenTMI%2Fpytest-stf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenTMI%2Fpytest-stf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenTMI%2Fpytest-stf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenTMI%2Fpytest-stf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenTMI","download_url":"https://codeload.github.com/OpenTMI/pytest-stf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240761095,"owners_count":19853254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adb","android","appium","openstf","pytest","python"],"created_at":"2024-11-10T23:11:30.211Z","updated_at":"2025-02-25T22:43:21.329Z","avatar_url":"https://github.com/OpenTMI.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![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\u003e 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\u003e pytest --appium_capabilities cab=val1\u0026cab=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\": \u003cHOSTNAME\u003e,\n    \"version\": \"12\",\n    \"appium_server\": \"http://localhost:4723\"\n  }\n]\n```\n\nExecution:\n```\n\u003e 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentmi%2Fpytest-stf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentmi%2Fpytest-stf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentmi%2Fpytest-stf/lists"}