-
Notifications
You must be signed in to change notification settings - Fork 0
Add pytest-bdd + Appium App Automate sample (Android + iOS) #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AakashHotchandani
wants to merge
8
commits into
main
Choose a base branch
from
sdk-sample
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9845907
Add pytest-bdd + Appium App Automate sample (Android + iOS)
AakashHotchandani f3adebf
Restore scaffold files dropped by import (Semgrep CI workflow, CODEOW…
AakashHotchandani e8dec65
Add BrowserStack SDK sample-test GitHub Actions workflow (workflow_di…
AakashHotchandani 0ab5d23
Add least-privilege permissions to sample-test workflow (CodeQL: limi…
AakashHotchandani 142d261
Commit public sample app(s) + reference by relative path (drop accoun…
AakashHotchandani 20cbe76
Commit sample + local apps referenced by relative app: paths (force-a…
AakashHotchandani c26e941
Framework-led source token (pytest-bdd) to match published sibling co…
AakashHotchandani 80a6830
Fix README cd path to the full repo directory name
AakashHotchandani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Runs the BrowserStack SDK sample against a given commit and reports a status check. | ||
| # Trigger: Actions tab -> "pytest-bdd Appium App Automate SDK sample test" -> Run workflow -> paste the PR's full commit SHA. | ||
| # Requires repo secrets: BROWSERSTACK_USERNAME, BROWSERSTACK_ACCESS_KEY. | ||
| # NOTE (App Automate): the app under test is referenced via `app: bs://...` in browserstack.yml; | ||
| # ensure that uploaded app exists on the account whose secrets are used (re-upload + update if expired). | ||
| name: pytest-bdd Appium App Automate SDK sample test | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| commit_sha: | ||
| description: 'The full commit id to build' | ||
| required: true | ||
|
|
||
| permissions: | ||
| contents: read # checkout | ||
| checks: write # github-script creates the status check | ||
|
|
||
| jobs: | ||
| sdk-sample: | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| max-parallel: 3 | ||
| matrix: | ||
| os: [ubuntu-latest] | ||
| python: ['3.10', '3.11'] | ||
| name: pytest-bdd-appium Python ${{ matrix.python }} sample | ||
| env: | ||
| BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} | ||
| BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} | ||
| defaults: | ||
| run: | ||
| working-directory: android | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.inputs.commit_sha }} | ||
| - name: Mark status check in_progress | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| job_name: pytest-bdd-appium Python ${{ matrix.python }} sample | ||
| commit_sha: ${{ github.event.inputs.commit_sha }} | ||
| with: | ||
| github-token: ${{ github.token }} | ||
| script: | | ||
| await github.rest.checks.create({ | ||
| owner: context.repo.owner, repo: context.repo.repo, | ||
| name: process.env.job_name, head_sha: process.env.commit_sha, | ||
| status: 'in_progress' | ||
| }).catch(e => console.log('check create failed:', e.status)); | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python }} | ||
| - name: Install | ||
| run: | | ||
| pip install -r requirements.txt | ||
| - name: Run sample test | ||
| run: | | ||
| browserstack-sdk pytest tests/test_sample.py | ||
| - name: Mark status check completed | ||
| if: always() | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| conclusion: ${{ job.status }} | ||
| job_name: pytest-bdd-appium Python ${{ matrix.python }} sample | ||
| commit_sha: ${{ github.event.inputs.commit_sha }} | ||
| with: | ||
| github-token: ${{ github.token }} | ||
| script: | | ||
| await github.rest.checks.create({ | ||
| owner: context.repo.owner, repo: context.repo.repo, | ||
| name: process.env.job_name, head_sha: process.env.commit_sha, | ||
| status: 'completed', conclusion: process.env.conclusion | ||
| }).catch(e => console.log('check create failed:', e.status)); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| .vscode | ||
| __pycache__ | ||
| .pytest_cache | ||
| .venv | ||
| env | ||
| local.log | ||
| log/ | ||
| *.apk | ||
| *.ipa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,84 @@ | ||
| # pytest-bdd-appium-app-browserstack | ||
| We require the following new public repositories under the browserstack GitHub organization to host customer-facing sample projects for the BrowserStack SDK. | ||
| # pytest-bdd + Appium with BrowserStack App Automate | ||
|
|
||
| Run Appium (mobile app) tests written with **pytest-bdd** on real devices on | ||
| [BrowserStack App Automate](https://app-automate.browserstack.com/) using the | ||
| BrowserStack Python SDK. No capability boilerplate in your tests — the SDK reads | ||
| `browserstack.yml` and routes each session to the BrowserStack device cloud. | ||
|
|
||
| This repo has two self-contained platform directories: | ||
|
|
||
| ``` | ||
| android/ Android sample (WikipediaSample.apk) + local (LocalSample.apk) | ||
| ios/ iOS sample (BStackSampleApp.ipa) + local (LocalSample.ipa) | ||
| ``` | ||
|
|
||
| Each directory has its own `browserstack.yml`, `conftest.py` (Appium driver | ||
| fixture), `features/` (Gherkin), `tests/` (pytest-bdd step definitions), and | ||
| `requirements.txt`. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - A [BrowserStack](https://www.browserstack.com/) account (username + access key). | ||
| - Python 3.8+. | ||
| - An application to test. The Android directory is pre-wired to a pre-uploaded | ||
| `WikipediaSample.apk` (`bs://...`); the iOS directory uploads | ||
| `BStackSampleApp.ipa` from a local path. | ||
|
|
||
| ## Setup | ||
|
|
||
| ```bash | ||
| git clone <this-repo> | ||
| cd pytest-bdd-appium-app-browserstack/android # or: cd pytest-bdd-appium-app-browserstack/ios | ||
|
|
||
| python3 -m venv .venv | ||
| .venv/bin/pip install -r requirements.txt | ||
| ``` | ||
|
|
||
| Configure credentials via env vars (recommended) or by editing `browserstack.yml`: | ||
|
|
||
| ```bash | ||
| export BROWSERSTACK_USERNAME="YOUR_USERNAME" | ||
| export BROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY" | ||
| ``` | ||
|
|
||
| ## Run Sample Test (Android) | ||
|
|
||
| From inside `android/`: | ||
|
|
||
| ```bash | ||
| browserstack-sdk pytest -s tests/ | ||
| ``` | ||
|
|
||
| This runs the **Wikipedia search** scenario on a real Samsung Galaxy S22 Ultra: | ||
| tap "Search Wikipedia", type "BrowserStack", and assert results are returned. | ||
| It also runs the **local** scenario (LocalSample.apk over the BrowserStack Local | ||
| tunnel — `browserstackLocal: true`). | ||
|
|
||
| To run a single scenario: | ||
|
|
||
| ```bash | ||
| browserstack-sdk pytest -s tests/test_sample.py | ||
| ``` | ||
|
|
||
| ## Run Sample Test (iOS) | ||
|
|
||
| From inside `ios/`: | ||
|
|
||
| ```bash | ||
| browserstack-sdk pytest -s tests/ | ||
| ``` | ||
|
|
||
| ## Run Local Test | ||
|
|
||
| The local scenarios (`tests/test_local.py`) exercise BrowserStack Local. With | ||
| `browserstackLocal: true` in `browserstack.yml` the SDK starts the Local tunnel | ||
| automatically — no separate binary to launch. | ||
|
|
||
| ## Notes / Dashboard | ||
|
|
||
| - View runs and shareable session links at | ||
| [app-automate.browserstack.com](https://app-automate.browserstack.com/). | ||
| - Test Observability (`testObservability: true`) reports also appear at | ||
| [observability.browserstack.com](https://observability.browserstack.com/). | ||
| - The `app:` value can be a local path (the SDK uploads it and rewrites to | ||
| `bs://<hashed-id>`) or a pre-uploaded `bs://<id>`. |
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # ============================= | ||
| # Set BrowserStack Credentials | ||
| # ============================= | ||
| # Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME | ||
| # and BROWSERSTACK_ACCESS_KEY as env variables. | ||
| userName: YOUR_USERNAME | ||
| accessKey: YOUR_ACCESS_KEY | ||
|
|
||
| # ====================== | ||
| # BrowserStack Reporting | ||
| # ====================== | ||
| projectName: BrowserStack Samples | ||
| buildName: appauto-pytest-bdd-appium | ||
| buildIdentifier: '#${BUILD_NUMBER}' | ||
| # `framework` lets the SDK instrument pytest-bdd and send test context to BrowserStack. | ||
| framework: pytest-bdd | ||
|
|
||
| # ========================================== | ||
| # Application under test | ||
| # ========================================== | ||
| # Pre-uploaded WikipediaSample.apk. Use a local path (./WikipediaSample.apk) to | ||
| # Public sample app committed in this repo (relative path); the SDK uploads it at run time. | ||
| app: ./WikipediaSample.apk | ||
|
|
||
| # ======================================= | ||
| # Platforms (Devices to test) | ||
| # ======================================= | ||
| platforms: | ||
| - deviceName: Samsung Galaxy S22 Ultra | ||
| osVersion: "12.0" | ||
| platformName: android | ||
|
|
||
| # ======================= | ||
| # Parallels per Platform | ||
| # ======================= | ||
| parallelsPerPlatform: 1 | ||
|
|
||
| source: pytest-bdd:appium-sample-sdk:v1.0 | ||
|
|
||
| # ====================== | ||
| # Test Observability | ||
| # ====================== | ||
| testObservability: true | ||
|
|
||
| # =================== | ||
| # Debugging features | ||
| # =================== | ||
| debug: true | ||
| networkLogs: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import os | ||
|
|
||
| import pytest | ||
| from appium import webdriver | ||
| from appium.options.android import UiAutomator2Options | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def driver(request): | ||
| """Appium driver fixture shared by the pytest-bdd step definitions. | ||
|
|
||
| The BrowserStack SDK injects the app + device capabilities from | ||
| browserstack.yml, so an empty UiAutomator2Options object is enough — no | ||
| hub URL caps or device caps are set here. When launched with | ||
| `browserstack-sdk pytest`, the session is routed to the BrowserStack | ||
| cloud automatically. | ||
| """ | ||
| options = UiAutomator2Options() | ||
| options.set_capability("bstack:options", { | ||
| "userName": os.environ.get("BROWSERSTACK_USERNAME", "YOUR_USERNAME"), | ||
| "accessKey": os.environ.get("BROWSERSTACK_ACCESS_KEY", "YOUR_ACCESS_KEY"), | ||
| }) | ||
| drv = webdriver.Remote("https://hub.browserstack.com/wd/hub", options=options) | ||
| yield drv | ||
| drv.quit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Feature: BrowserStack App Automate local test | ||
| As a BrowserStack user | ||
| I want the local sample app to reach a service over the BrowserStack Local tunnel | ||
| So that I can verify BrowserStack Local tunnelling works for mobile apps | ||
|
|
||
| Scenario: Reach the local endpoint from the device | ||
| Given I have launched the local sample app | ||
| When I trigger the local network test | ||
| Then the app reports it is up and running |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Feature: BrowserStack App Automate sample test | ||
| As a BrowserStack user | ||
| I want to search Wikipedia in the WikipediaSample app | ||
| So that I can verify search results are returned | ||
|
|
||
| Scenario: Search Wikipedia for BrowserStack | ||
| Given I have launched the Wikipedia sample app | ||
| When I search Wikipedia for "BrowserStack" | ||
| Then search results are displayed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Appium-Python-Client | ||
| selenium>=3.14 | ||
| pytest==7.4.4 | ||
| pytest-bdd | ||
| browserstack-local | ||
| browserstack-sdk @ https://sdk-assets.browserstack.com/python/browserstack_sdk-latest.tar.gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import os | ||
|
|
||
| from pytest_bdd import scenario, given, when, then | ||
| from appium.webdriver.common.appiumby import AppiumBy | ||
|
|
||
| FEATURES = os.path.join(os.path.dirname(os.path.dirname(__file__)), "features") | ||
|
|
||
|
|
||
| @scenario(os.path.join(FEATURES, "local.feature"), "Reach the local endpoint from the device") | ||
| def test_local(): | ||
| """LocalSample.apk over the BrowserStack Local tunnel (browserstackLocal: true).""" | ||
|
|
||
|
|
||
| @given("I have launched the local sample app") | ||
| def launch_local_app(driver): | ||
| # The SDK launches the local sample app from browserstack.yml. | ||
| pass | ||
|
|
||
|
|
||
| @when("I trigger the local network test") | ||
| def trigger_local_test(driver): | ||
| driver.find_element( | ||
| AppiumBy.ID, "com.example.android.basicnetworking:id/test_action").click() | ||
|
|
||
|
|
||
| @then("the app reports it is up and running") | ||
| def app_up_and_running(driver): | ||
| texts = driver.find_elements(AppiumBy.CLASS_NAME, "android.widget.TextView") | ||
| assert any("Up and running" in (t.text or "") for t in texts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import os | ||
| import time | ||
|
|
||
| from pytest_bdd import scenario, given, when, then, parsers | ||
| from appium.webdriver.common.appiumby import AppiumBy | ||
|
|
||
| FEATURES = os.path.join(os.path.dirname(os.path.dirname(__file__)), "features") | ||
|
|
||
|
|
||
| @scenario(os.path.join(FEATURES, "sample.feature"), "Search Wikipedia for BrowserStack") | ||
| def test_search_wikipedia(): | ||
| """WikipediaSample.apk: search Wikipedia and assert results appear.""" | ||
|
|
||
|
|
||
| @given("I have launched the Wikipedia sample app") | ||
| def launch_app(driver): | ||
| # The SDK launches the app (WikipediaSample.apk) from browserstack.yml. | ||
| driver.find_element(AppiumBy.ACCESSIBILITY_ID, "Search Wikipedia").click() | ||
|
|
||
|
|
||
| @when(parsers.parse('I search Wikipedia for "{query}"')) | ||
| def search_wikipedia(driver, query): | ||
| search = driver.find_element( | ||
| AppiumBy.ID, "org.wikipedia.alpha:id/search_src_text") | ||
| search.send_keys(query) | ||
| time.sleep(5) | ||
|
|
||
|
|
||
| @then("search results are displayed") | ||
| def results_displayed(driver): | ||
| results = driver.find_elements(AppiumBy.CLASS_NAME, "android.widget.TextView") | ||
| assert len(results) > 0 |
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # ============================= | ||
| # Set BrowserStack Credentials | ||
| # ============================= | ||
| userName: YOUR_USERNAME | ||
| accessKey: YOUR_ACCESS_KEY | ||
|
|
||
| # ====================== | ||
| # BrowserStack Reporting | ||
| # ====================== | ||
| projectName: BrowserStack Samples | ||
| buildName: appauto-pytest-bdd-appium | ||
| buildIdentifier: '#${BUILD_NUMBER}' | ||
| framework: pytest-bdd | ||
|
|
||
| # ========================================== | ||
| # Application under test | ||
| # ========================================== | ||
| # Public sample app committed in this repo (relative path); the SDK uploads it at run time. | ||
| app: ./BStackSampleApp.ipa | ||
|
|
||
| # ======================================= | ||
| # Platforms (Devices to test) | ||
| # ======================================= | ||
| platforms: | ||
| - deviceName: iPhone 14 Pro | ||
| osVersion: "16" | ||
| platformName: ios | ||
|
|
||
| # ======================= | ||
| # Parallels per Platform | ||
| # ======================= | ||
| parallelsPerPlatform: 1 | ||
|
|
||
| source: pytest-bdd:appium-sample-sdk:v1.0 | ||
|
|
||
| # ====================== | ||
| # Test Observability | ||
| # ====================== | ||
| testObservability: true | ||
|
|
||
| # =================== | ||
| # Debugging features | ||
| # =================== | ||
| debug: true | ||
| networkLogs: true |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.