Modern QA2026BrowserStack Integration Example — tiles
Log inJoin
33 / 66 · 09 Mobile & Cross-Platform Testing · Cloud Device Farms← prev⊞ allnext →☰ Read as one page

6.3BrowserStack Integration Example

GitHub Actions Workflow

# .github/workflows/mobile-tests.yml
name: Mobile E2E Tests
on:
  push:
    branches: [main]

jobs:
  mobile-tests:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
          - device: "iPhone 15"
            os_version: "18"
            platform: "ios"
          - device: "Samsung Galaxy S24"
            os_version: "14.0"
            platform: "android"
          - device: "Google Pixel 8"
            os_version: "14.0"
            platform: "android"

    steps:
      - uses: actions/checkout@v4

      - name: Upload app to BrowserStack
        run: |
          RESPONSE=$(curl -u "$BS_USER:$BS_KEY" \
            -X POST "https://api-cloud.browserstack.com/app-automate/upload" \
            -F "file=@./builds/app-release.apk")
          echo "APP_URL=$(echo $RESPONSE | jq -r '.app_url')" >> $GITHUB_ENV

      - name: Run Appium tests
        env:
          BROWSERSTACK_USER: ${{ secrets.BS_USER }}
          BROWSERSTACK_KEY: ${{ secrets.BS_KEY }}
          DEVICE: ${{ matrix.device }}
          OS_VERSION: ${{ matrix.os_version }}
        run: |
          pytest tests/mobile/ \
            --device="$DEVICE" \
            --os-version="$OS_VERSION" \
            --app-url="$APP_URL" \
            --junitxml=results-${{ matrix.device }}.xml

BrowserStack Capabilities Configuration

# conftest.py -- BrowserStack configuration
import os
from appium import webdriver
from appium.options.android import UiAutomator2Options
import pytest

@pytest.fixture
def bs_driver(request):
    """Create a BrowserStack Appium driver."""
    device = os.environ.get("DEVICE", "Samsung Galaxy S24")
    os_version = os.environ.get("OS_VERSION", "14.0")
    app_url = os.environ.get("APP_URL")

    options = UiAutomator2Options()
    options.set_capability("platformName", "Android")
    options.set_capability("appium:deviceName", device)
    options.set_capability("appium:platformVersion", os_version)
    options.set_capability("appium:app", app_url)

    # BrowserStack-specific capabilities
    options.set_capability("bstack:options", {
        "userName": os.environ["BROWSERSTACK_USER"],
        "accessKey": os.environ["BROWSERSTACK_KEY"],
        "projectName": "MyApp Mobile Tests",
        "buildName": f"Build-{os.environ.get('GITHUB_SHA', 'local')[:8]}",
        "sessionName": request.node.name,
        "debug": True,
        "networkLogs": True,
        "video": True,
        "appiumVersion": "2.6.0",
        "idleTimeout": 300,
    })

    driver = webdriver.Remote(
        command_executor="https://hub-cloud.browserstack.com/wd/hub",
        options=options,
    )
    yield driver

    # Mark test status in BrowserStack
    status = "passed" if request.node.rep_call.passed else "failed"
    driver.execute_script(
        f"browserstack_executor: {{\"action\": \"setSessionStatus\", "
        f"\"arguments\": {{\"status\": \"{status}\"}}}}"
    )
    driver.quit()