|
| 1 | +# Cross-Device Automation Agent Demo (BrowserStack App Automate) |
| 2 | + |
| 3 | +[TestNG](http://testng.org) Integration with BrowserStack App Automate for Android and iOS. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## What Does This Repo Do? |
| 8 | + |
| 9 | +This repository showcases the use of **BrowserStack's Cross-Device Automation Agent** for mobile app automation using TestNG and Appium. The key feature is the ability to write test steps in **Natural Language (Plain English)**, moving away from explicit Appium locators and actions. |
| 10 | + |
| 11 | +It contains demo scripts: |
| 12 | +* **Android - `AppiumTest.java`**: Runs test objectives on the Wikipedia Android app using simple English commands like searching for articles and validating results. |
| 13 | +* **iOS - `AppiumTest.java`**: Runs test objectives on the BBC News iOS app using simple English commands like navigating to Culture tab and validating page headings. |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## How It Works |
| 18 | + |
| 19 | +1. **Enablement:** The feature is enabled by declaring the capability `aiAuthoring: true` in your `browserstack.yml` configuration file. |
| 20 | +2. **The Command:** Inside the test scripts, the test uses a standard Selenium `JavascriptExecutor` to pass the Natural Language instruction to the BrowserStack environment: |
| 21 | + ```java |
| 22 | + // Example for Android: Search for "india" on Wikipedia app |
| 23 | + jse.executeScript("browserstack_executor: {\"action\": \"ai\", \"arguments\": [\"Tap on the \\\"Search\\\" option from below navigation bar and type \\\" india\\\" on the search bar and tap on the first suggestion\"]}"); |
| 24 | + |
| 25 | + // Example for iOS: Navigate to Culture tab |
| 26 | + jse.executeScript("browserstack_executor: {\"action\": \"ai\", \"arguments\": [\"Tap on culture tab from the top navigation bar\"]}"); |
| 27 | + ``` |
| 28 | +3. **Execution:** The BrowserStack Cross-Device Automation Agent intercepts this command, interprets the natural language, and executes the equivalent low-level Appium actions on the mobile app. |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Setup |
| 33 | + |
| 34 | +### Requirements |
| 35 | + |
| 36 | +1. Java 8+ |
| 37 | + - If Java is not installed, follow these instructions: |
| 38 | + - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable |
| 39 | + - For Mac and Linux, run `java -version` to see what java version is pre-installed. If you want a different version download from [here](https://java.com/en/download/) |
| 40 | + |
| 41 | +2. Maven (Only required if using Maven as the build tool) |
| 42 | + - If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi) |
| 43 | + - For installation, follow the instructions [here](https://maven.apache.org/install.html) |
| 44 | + |
| 45 | +3. Gradle (Only required if using Gradle as the build tool) |
| 46 | + - If Gradle is not downloaded, download it from [here](https://gradle.org/releases/) |
| 47 | + - For installation, follow the instructions [here](https://gradle.org/install/) |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +## Running the Tests |
| 52 | + |
| 53 | +### For Android |
| 54 | + |
| 55 | +#### Using Maven |
| 56 | + |
| 57 | +- Clone the repository |
| 58 | +- Navigate to the Android directory: `cd app-automate/android` |
| 59 | +- Replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` with your BrowserStack access credentials in `browserstack.yml`. |
| 60 | +- Declare capability **`aiAuthoring: true`** in `browserstack.yml` file (if not already present). |
| 61 | +- Install dependencies `mvn compile` |
| 62 | +- To run the test suite having cross-platform with parallelization, run `mvn test -P sample-test`. |
| 63 | +- To run local tests, run `mvn test -P sample-local-test`. |
| 64 | + |
| 65 | +#### Using Gradle |
| 66 | + |
| 67 | +- Clone the repository |
| 68 | +- Navigate to the Android directory: `cd app-automate/android` |
| 69 | +- Replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` with your BrowserStack access credentials in `browserstack.yml`. |
| 70 | +- Declare capability **`aiAuthoring: true`** in `browserstack.yml` file (if not already present). |
| 71 | +- Install dependencies `gradle build` |
| 72 | +- To run the test suite having cross-platform with parallelization, run `gradle sampleTest`. |
| 73 | +- To run local tests, run `gradle sampleLocalTest`. |
| 74 | + |
| 75 | +### For iOS |
| 76 | + |
| 77 | +#### Using Maven |
| 78 | + |
| 79 | +- Clone the repository |
| 80 | +- Navigate to the iOS directory: `cd app-automate/ios` |
| 81 | +- Replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` with your BrowserStack access credentials in `browserstack.yml`. |
| 82 | +- Declare capability **`aiAuthoring: true`** in `browserstack.yml` file (if not already present). |
| 83 | +- Install dependencies `mvn compile` |
| 84 | +- To run the test suite having cross-platform with parallelization, run `mvn test -P sample-test`. |
| 85 | +- To run local tests, run `mvn test -P sample-local-test`. |
| 86 | + |
| 87 | +#### Using Gradle |
| 88 | + |
| 89 | +- Clone the repository |
| 90 | +- Navigate to the iOS directory: `cd app-automate/ios` |
| 91 | +- Replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` with your BrowserStack access credentials in `browserstack.yml`. |
| 92 | +- Declare capability **`aiAuthoring: true`** in `browserstack.yml` file (if not already present). |
| 93 | +- Install dependencies `gradle build` |
| 94 | +- To run the test suite having cross-platform with parallelization, run `gradle sampleTest`. |
| 95 | +- To run local tests, run `gradle sampleLocalTest`. |
| 96 | + |
| 97 | +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github). |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## Integrate Your Test Suite |
| 102 | + |
| 103 | +### Maven Integration |
| 104 | + |
| 105 | +* Add maven dependency of `browserstack-java-sdk` in your `pom.xml` file: |
| 106 | + ```xml |
| 107 | + <dependency> |
| 108 | + <groupId>com.browserstack</groupId> |
| 109 | + <artifactId>browserstack-java-sdk</artifactId> |
| 110 | + <version>LATEST</version> |
| 111 | + <scope>compile</scope> |
| 112 | + </dependency> |
| 113 | + ``` |
| 114 | +* Modify your build plugin to run tests by adding `argLine -javaagent:${com.browserstack:browserstack-java-sdk:jar}` in the Surefire plugin configuration. |
| 115 | +* Install dependencies `mvn compile`. |
| 116 | + |
| 117 | +### Gradle Integration |
| 118 | + |
| 119 | +* Add `compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies in your `build.gradle`. |
| 120 | +* Fetch Artifact Information and add `jvmArgs` property in tasks. |
| 121 | +* Install dependencies `gradle build`. |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +## Notes |
| 126 | + |
| 127 | +* You can view your test results on the [BrowserStack App Automate dashboard](https://www.browserstack.com/app-automate). |
| 128 | +* For detailed documentation on Appium and Java setup with BrowserStack App Automate, please refer to the [official documentation](https://www.browserstack.com/docs/app-automate/appium). |
| 129 | + |
| 130 | +## Getting Help |
| 131 | + |
| 132 | +If you are running into any issues or have any queries, please check [Browserstack Support page](https://www.browserstack.com/support/app-automate) or [get in touch with us](https://www.browserstack.com/contact?ref=help). |
0 commit comments