|
1 | | -| [Using Java 7 client with MJSONWP protocol](./java_7) | [Using Java 8 client with w3c protocol](./java_8) | |
2 | | -|------------------------------------------------------ | ------------------------------------------------- | |
| 1 | +# java-appium-app-browserstack (BrowserStack SDK) |
| 2 | + |
| 3 | +This repository demonstrates how to run Appium Java tests on [BrowserStack App Automate](https://app-automate.browserstack.com) using the **BrowserStack SDK**. All device, credential, and build configuration is managed via `browserstack.yml` — no hardcoded capabilities in test code. |
| 4 | + |
| 5 | +## Setup |
| 6 | + |
| 7 | +### Requirements |
| 8 | + |
| 9 | +1. **Java 8+** |
| 10 | + - For Windows, download the latest version from [here](https://java.com/en/download/) and run the installer. |
| 11 | + - For Mac and Linux, run `java -version` to check your version. Download a different version from [here](https://java.com/en/download/) if needed. |
| 12 | + |
| 13 | +2. **Maven** |
| 14 | + - Download Maven from [here](https://maven.apache.org/download.cgi). |
| 15 | + - Follow the installation instructions [here](https://maven.apache.org/install.html). |
| 16 | + |
| 17 | +### Install the dependencies |
| 18 | + |
| 19 | +Navigate to the `java_8` directory and run: |
| 20 | + |
| 21 | +```sh |
| 22 | +cd java_8/ |
| 23 | +mvn clean install |
| 24 | +``` |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## Getting Started |
| 29 | + |
| 30 | +### Step 1 — Upload your App to BrowserStack |
| 31 | + |
| 32 | +Upload your Android (`.apk` / `.aab`) or iOS (`.ipa`) app to BrowserStack using the REST API: |
| 33 | + |
| 34 | +```sh |
| 35 | +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ |
| 36 | + -X POST "https://api-cloud.browserstack.com/app-automate/upload" \ |
| 37 | + -F "file=@/path/to/your/app" |
| 38 | +``` |
| 39 | + |
| 40 | +Note the `app_url` value (e.g. `bs://xxxxxxx`) returned in the response — you'll need it in the next step. |
| 41 | + |
| 42 | +> **Don't have an app?** Use the BrowserStack sample apps: |
| 43 | +> - [Sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) |
| 44 | +> - [Sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa) |
| 45 | +
|
| 46 | +--- |
| 47 | + |
| 48 | +### Step 2 — Configure `browserstack.yml` |
| 49 | + |
| 50 | +Open `java_8/browserstack.yml` and set your credentials, app, and target devices. |
| 51 | + |
| 52 | +```yaml |
| 53 | +# ===================== |
| 54 | +# BrowserStack Credentials |
| 55 | +# ===================== |
| 56 | +# Either set values directly here, or export as environment variables: |
| 57 | +# export BROWSERSTACK_USERNAME=your_username |
| 58 | +# export BROWSERSTACK_ACCESS_KEY=your_access_key |
| 59 | +userName: YOUR_USERNAME |
| 60 | +accessKey: YOUR_ACCESS_KEY |
| 61 | + |
| 62 | +# ===================== |
| 63 | +# Reporting |
| 64 | +# ===================== |
| 65 | +projectName: First Java Project |
| 66 | +buildName: browserstack-build-1 |
| 67 | +buildIdentifier: '#${BUILD_NUMBER}' |
| 68 | + |
| 69 | +# ===================== |
| 70 | +# App under test |
| 71 | +# ===================== |
| 72 | +app: bs://<app-id> # Replace with the app_url from Step 1 |
| 73 | + |
| 74 | +# ===================== |
| 75 | +# Target devices |
| 76 | +# ===================== |
| 77 | +platforms: |
| 78 | + - deviceName: <device-name> |
| 79 | + platformVersion: <os-version> |
| 80 | + platformName: <android/ios> |
| 81 | + |
| 82 | +parallelsPerPlatform: 1 |
| 83 | + |
| 84 | +# ===================== |
| 85 | +# Local Testing (optional) |
| 86 | +# ===================== |
| 87 | +browserstackLocal: <true/false> # Set to true for local/internal environment tests |
| 88 | +``` |
| 89 | +
|
| 90 | +--- |
| 91 | +
|
| 92 | +### Step 3 — Run your tests |
| 93 | +
|
| 94 | +Make sure you are inside the `java_8/` directory before running any of the following commands. |
| 95 | + |
| 96 | +#### Run Android sample test |
| 97 | + |
| 98 | +```sh |
| 99 | +mvn test -P android-first-test |
| 100 | +``` |
| 101 | + |
| 102 | +#### Run iOS sample test |
| 103 | + |
| 104 | +```sh |
| 105 | +mvn test -P ios-first-test |
| 106 | +``` |
| 107 | + |
| 108 | +#### Run Android local test |
| 109 | + |
| 110 | +```sh |
| 111 | +mvn test -P android-local-test |
| 112 | +``` |
| 113 | + |
| 114 | +#### Run iOS local test |
| 115 | + |
| 116 | +```sh |
| 117 | +mvn test -P ios-local-test |
| 118 | +``` |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | + |
| 123 | +## Local Testing |
| 124 | + |
| 125 | +Local Testing lets you test apps that access resources on your internal or staging environments. |
| 126 | + |
| 127 | +To enable it, set the following in `browserstack.yml`: |
| 128 | + |
| 129 | +```yaml |
| 130 | +browserstackLocal: true |
| 131 | +``` |
| 132 | + |
| 133 | +The SDK will automatically start and stop the BrowserStack Local tunnel — no manual binary setup needed. Then run the local test profile: |
| 134 | + |
| 135 | +```sh |
| 136 | +# Android |
| 137 | +mvn test -P android-local-test |
| 138 | +
|
| 139 | +# iOS |
| 140 | +mvn test -P ios-local-test |
| 141 | +``` |
| 142 | + |
| 143 | +> **Note for macOS users:** If you encounter Apple permission issues with the Local binary, go to: |
| 144 | +> `System Preferences → Security & Privacy → General → Allow app` |
| 145 | + |
| 146 | +--- |
| 147 | + |
| 148 | +## Notes on java-client 8.x |
| 149 | + |
| 150 | +This module uses `io.appium:java-client:8.x`. Key differences from 7.x: |
| 151 | + |
| 152 | +- Use `AppiumBy` instead of the deprecated `MobileBy`. |
| 153 | +- `MobileElement`, `IOSElement`, `AndroidElement` are removed — use `WebElement` instead. |
| 154 | +- `WebDriverWait` requires a `Duration` argument: |
| 155 | + ```java |
| 156 | + // java-client 7.x |
| 157 | + new WebDriverWait(driver, 30) |
| 158 | +
|
| 159 | + // java-client 8.x |
| 160 | + new WebDriverWait(driver, Duration.ofSeconds(30)) |
| 161 | + ``` |
| 162 | + |
| 163 | +See the full [v7 to v8 migration guide](https://github.com/appium/java-client/blob/master/docs/v7-to-v8-migration-guide.md#mobileelement) for details. |
| 164 | + |
| 165 | +--- |
| 166 | + |
| 167 | +## View Test Results |
| 168 | + |
| 169 | +After running your tests, visit the [App Automate Dashboard](https://app-automate.browserstack.com/dashboard) to see: |
| 170 | +- Test status (pass/fail) |
| 171 | +- Video recordings |
| 172 | +- Device logs |
| 173 | +- Network logs |
| 174 | + |
| 175 | +--- |
| 176 | + |
| 177 | +## Getting Help |
| 178 | + |
| 179 | +If you run into any issues, check the [BrowserStack Support page](https://www.browserstack.com/support/app-automate) or [contact us](https://www.browserstack.com/contact#technical-support). |
0 commit comments