BrowserStack 1to1 Devices #57
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
| # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | |
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven | |
| # This workflow uses actions that are not certified by GitHub. | |
| # They are provided by a third-party and are governed by | |
| # separate terms of service, privacy policy, and support | |
| # documentation. | |
| name: BrowserStack 1to1 Devices | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| filter: | |
| description: 'Filter for tests' | |
| required: true | |
| default: '@Smoke and @Automated' | |
| device: | |
| description: 'Select the device to test' | |
| required: true | |
| type: choice | |
| options: | |
| - Samsung Galaxy A52 | |
| - Motorola Moto G71 5G | |
| - Google Pixel 7 Pro | |
| - Xiaomi Redmi Note 11 | |
| - Huawei P30 | |
| - Oppo Reno 6 | |
| default: 'Google Pixel 7 Pro' | |
| jobs: | |
| test: | |
| runs-on: ubuntu-22.04 | |
| container: crowdar/lippia:3.3.0.0-jdk17 | |
| environment: Automation | |
| env: | |
| BSUSER: ${{ secrets.BSUSER }} | |
| AUTHTOKEN: ${{ secrets.AUTHTOKEN }} | |
| BSAPP: ${{ secrets.BSAPP }} | |
| LTM_GENERAL: ${{ secrets.LTM_GENERAL }} | |
| LTM_GENERAL_PASS: ${{ secrets.LTM_GENERAL_PASS }} | |
| steps: | |
| - name: Checkout to the repository | |
| uses: actions/checkout@v4 | |
| - name: Configuring JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Resolve BrowserStack device and OS | |
| shell: bash | |
| env: | |
| INPUT_DEVICE: ${{ github.event.inputs.device }} | |
| VAR_DEVICE: ${{ vars.BSDEVICE }} | |
| SECRET_DEVICE: ${{ secrets.BSDEVICE }} | |
| VAR_BSOS: ${{ vars.BSOS }} | |
| SECRET_BSOS: ${{ secrets.BSOS }} | |
| run: | | |
| set -e | |
| RAW="${INPUT_DEVICE:-${VAR_DEVICE:-${SECRET_DEVICE:-}}}" | |
| CLEAN="$(printf '%s' "$RAW" | tr -d '\r\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/^"//' -e 's/"$//')" | |
| if [ -z "$CLEAN" ]; then | |
| echo "ERROR: BSDEVICE is empty. Pick a device in the workflow form or set Automation variable/secret BSDEVICE." | |
| exit 1 | |
| fi | |
| case "$CLEAN" in | |
| "Samsung Galaxy A52") OS="11" ;; | |
| "Motorola Moto G71 5G") OS="11" ;; | |
| "Google Pixel 7 Pro") OS="13" ;; | |
| "Xiaomi Redmi Note 11") OS="11" ;; | |
| "Huawei P30") OS="9" ;; | |
| "Oppo Reno 6") OS="11" ;; | |
| *) | |
| echo "ERROR: Unknown device '$CLEAN'. Use exact BrowserStack name (e.g. Google Pixel 7 Pro)." | |
| exit 1 | |
| ;; | |
| esac | |
| RAW_OS="${VAR_BSOS:-${SECRET_BSOS:-}}" | |
| if [ -n "$RAW_OS" ]; then | |
| OS="$(printf '%s' "$RAW_OS" | tr -d '\r\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" | |
| fi | |
| echo "BSDEVICE=$CLEAN" >> "$GITHUB_ENV" | |
| echo "BSOS=$OS" >> "$GITHUB_ENV" | |
| echo "Resolved device: $CLEAN (Android $OS)" | |
| - name: Configure Maven settings | |
| run: | | |
| mkdir -p ~/.m2 | |
| echo '<settings> | |
| <mirrors> | |
| <mirror> | |
| <id>central</id> | |
| <url>https://repo.maven.apache.org/maven2</url> | |
| <mirrorOf>*</mirrorOf> | |
| </mirror> | |
| </mirrors> | |
| </settings>' > ~/.m2/settings.xml | |
| - name: List directories to verify path | |
| run: ls -al ~/.m2 | |
| - name: Cache Maven dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| - name: Checking Maven dependencies | |
| run: mvn dependency:resolve | |
| - name: Setting environment variable | |
| run: echo "COMBINED_FILTER=${{ github.event.inputs.filter }}" >> $GITHUB_ENV | |
| - name: Debugging environment variables | |
| run: | | |
| echo "BSDEVICE: $BSDEVICE" | |
| echo "BSOS: $BSOS" | |
| echo "BSUSER: $BSUSER" | |
| echo "AUTHTOKEN: $AUTHTOKEN" | |
| echo "BSAPP: $BSAPP" | |
| echo "LTM_GENERAL: $LTM_GENERAL" | |
| echo "LTM_GENERAL_PASS: $LTM_GENERAL_PASS" | |
| - name: Verify BSAPP against BrowserStack | |
| run: | | |
| set -e | |
| if [ -z "$BSAPP" ]; then | |
| echo "ERROR: BSAPP is empty. Set it under Settings -> Environments -> Automation." | |
| exit 1 | |
| fi | |
| # Strip accidental quotes/whitespace/newlines that pass the prefix check but break the capability. | |
| CLEAN_BSAPP="$(printf '%s' "$BSAPP" | tr -d '\r\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/^"//' -e 's/"$//')" | |
| if [ "$CLEAN_BSAPP" != "$BSAPP" ]; then | |
| echo "WARNING: BSAPP contained quotes/whitespace. Using cleaned value." | |
| echo "BSAPP=$CLEAN_BSAPP" >> "$GITHUB_ENV" | |
| BSAPP="$CLEAN_BSAPP" | |
| fi | |
| case "$BSAPP" in | |
| bs://*) : ;; | |
| *) echo "ERROR: BSAPP must start with bs:// (got: '$BSAPP')"; exit 1 ;; | |
| esac | |
| LAST6="$(printf '%s' "$BSAPP" | tail -c 6)" | |
| echo "Last 6 chars of BSAPP actually in use: '${LAST6}' (should be 'e8e887')" | |
| echo "Checking that $BSAPP exists on the BrowserStack account for user '$BSUSER'..." | |
| apps_json="$(curl -sS -u "$BSUSER:$AUTHTOKEN" https://api-cloud.browserstack.com/app-automate/recent_apps || true)" | |
| if echo "$apps_json" | grep -q "$BSAPP"; then | |
| echo "OK: BSAPP is present in this account's uploaded apps." | |
| else | |
| echo "ERROR: BSAPP was NOT found in the uploaded apps for the CI BrowserStack account." | |
| echo "Last 6 chars of BSAPP in use: '${LAST6}' (expected: 'e8e887' if using the current mtls APK)" | |
| echo "" | |
| echo "FIX: GitHub repo -> Settings -> Environments -> Automation -> Environment secrets -> BSAPP" | |
| echo " (NOT Settings -> Secrets and variables -> Actions — that scope is ignored by this workflow)" | |
| echo " Set BSAPP to one of the app_url values listed below, with no quotes or trailing newline." | |
| echo "" | |
| echo "Apps currently available to this account (app_url / custom_id):" | |
| echo "$apps_json" | tr ',' '\n' | grep -E 'app_url|custom_id' || echo "$apps_json" | |
| exit 1 | |
| fi | |
| - name: Verify device selection | |
| shell: bash | |
| env: | |
| INPUT_DEVICE: ${{ github.event.inputs.device }} | |
| VAR_DEVICE: ${{ vars.BSDEVICE }} | |
| SECRET_DEVICE: ${{ secrets.BSDEVICE }} | |
| VAR_BSOS: ${{ vars.BSOS }} | |
| SECRET_BSOS: ${{ secrets.BSOS }} | |
| run: | | |
| set -e | |
| # Resolve device: workflow input > Automation variable > secret > already in env | |
| RAW="${INPUT_DEVICE:-${VAR_DEVICE:-${SECRET_DEVICE:-${BSDEVICE:-}}}}" | |
| CLEAN="$(printf '%s' "$RAW" | tr -d '\r\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/^"//' -e 's/"$//')" | |
| if [ -z "$CLEAN" ]; then | |
| echo "ERROR: BSDEVICE is empty." | |
| exit 1 | |
| fi | |
| # Resolve OS from settings or map from device name | |
| RAW_OS="${VAR_BSOS:-${SECRET_BSOS:-${BSOS:-}}}" | |
| OS="$(printf '%s' "$RAW_OS" | tr -d '\r\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/\.0$//')" | |
| if [ -z "$OS" ]; then | |
| case "$CLEAN" in | |
| "Samsung Galaxy A52") OS="11" ;; | |
| "Motorola Moto G71 5G") OS="11" ;; | |
| "Google Pixel 7 Pro") OS="13" ;; | |
| "Xiaomi Redmi Note 11") OS="11" ;; | |
| "Huawei P30") OS="9" ;; | |
| "Oppo Reno 6") OS="11" ;; | |
| *) | |
| echo "ERROR: BSOS is empty and device '$CLEAN' is unknown. Set BSOS in GitHub settings (e.g. 13 for Pixel 7 Pro)." | |
| exit 1 | |
| ;; | |
| esac | |
| fi | |
| case "$CLEAN" in | |
| "Samsung Galaxy A11"|"Samsung Galaxy A51") | |
| echo "ERROR: '$CLEAN' is deprecated on BrowserStack." | |
| exit 1 | |
| ;; | |
| esac | |
| echo "BSDEVICE=$CLEAN" >> "$GITHUB_ENV" | |
| echo "BSOS=$OS" >> "$GITHUB_ENV" | |
| echo "Device OK: $CLEAN (Android $OS)" | |
| - name: Running Maven clean test | |
| run: | | |
| echo "Running tests with filter: '$COMBINED_FILTER' on device: '$BSDEVICE' with OS version: '$BSOS'" | |
| mvn clean test -Dcrowdar.cucumber.filter="'$COMBINED_FILTER'" \ | |
| -Denv.BSDEVICE="$BSDEVICE" \ | |
| -Denv.BSOS="$BSOS" \ | |
| -Denv.BSAPP="$BSAPP" \ | |
| -Dcrowdar.bs.device="$BSDEVICE" \ | |
| -Dcrowdar.deviceName="$BSDEVICE" \ | |
| -Dcrowdar.os.version="$BSOS" \ | |
| -Dcrowdar.bs.app="$BSAPP" \ | |
| -Dcrowdar.appLocation="$BSAPP" \ | |
| -DTEST_MANAGER_RUN_NAME="AUTO-$BSDEVICE-${{ github.event.inputs.filter }}" \ | |
| -DLTM_GENERAL="${{ secrets.LTM_GENERAL }}" \ | |
| -DLTM_GENERAL_PASS="${{ secrets.LTM_GENERAL_PASS }}" \ | |
| -PBrowserStack,!Local -PAndroid -U | |
| shell: bash | |
| - name: Uploading test reports | |
| if: always() | |
| uses: actions/upload-artifact@v4.3.4 | |
| with: | |
| name: test-results | |
| path: target/reports/ | |
| - name: Uploading HTML test report | |
| if: always() | |
| uses: actions/upload-artifact@v4.3.4 | |
| with: | |
| name: html-report | |
| path: target/cucumber-reports/cucumber-html-report/*.html | |
| - name: Uploading surefire test reports | |
| if: always() | |
| uses: actions/upload-artifact@v4.3.4 | |
| with: | |
| name: test-results-surefire | |
| path: target/surefire-reports/ | |