|
1 |
| -App Automate Java Samples |
2 |
| ---------------------- |
| 1 | +# java-appium-app-browserstack |
3 | 2 |
|
4 |
| -This repository contains code for Automated Native App tests using Appium in Java. Please feel free to clone the repo and use the example code. |
| 3 | +This repository demonstrates how to run Appium Java tests on BrowserStack App Automate. |
5 | 4 |
|
6 |
| -For frameworks integration with BrowserStack, refer to their individual repositories - |
| 5 | +## Setup |
| 6 | + |
| 7 | +### Requirements |
| 8 | + |
| 9 | +1. Java 8+ |
| 10 | + |
| 11 | +- If Java is not installed, follow these instructions: |
| 12 | + - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable |
| 13 | + - 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/) |
| 14 | + |
| 15 | +2. Maven |
| 16 | + |
| 17 | + - If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi) |
| 18 | + - For installation, follow the instructions [here](https://maven.apache.org/install.html) |
| 19 | + |
| 20 | +### Install the dependencies |
| 21 | + |
| 22 | +To install the dependencies, run the following command in the project's base folder |
| 23 | + |
| 24 | +```cmd |
| 25 | +mvn clean install |
| 26 | +``` |
| 27 | + |
| 28 | +## Getting Started |
| 29 | + |
| 30 | +Getting Started with Appium tests in Java on BrowserStack couldn't be easier! |
| 31 | + |
| 32 | +### Run your first test : |
| 33 | + |
| 34 | +**1. Upload your Android or iOS App** |
| 35 | + |
| 36 | +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request : |
| 37 | + |
| 38 | +``` |
| 39 | +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ |
| 40 | +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ |
| 41 | +-F "file=@/path/to/apk/file" |
| 42 | +``` |
| 43 | + |
| 44 | +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. |
| 45 | + |
| 46 | +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). |
| 47 | + |
| 48 | +**2. Configure and run your first test** |
| 49 | + |
| 50 | +Open `BrowserStackSample.java` file in the `android` directory or `ios` directory : |
| 51 | + |
| 52 | +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) |
| 53 | + |
| 54 | +- Replace `bs://<app-id>` with the URL obtained from app upload step |
| 55 | + |
| 56 | +- Set the device and OS version |
| 57 | + |
| 58 | +- If you have uploaded your own app update the test case |
| 59 | + |
| 60 | +- To run the test, use the following command in the base directory : |
| 61 | + |
| 62 | + - For Android test, run |
| 63 | + |
| 64 | + ```cmd |
| 65 | + mvn test -P android-first-test |
| 66 | + ``` |
| 67 | +
|
| 68 | + - For iOS test, run |
| 69 | +
|
| 70 | + ```cmd |
| 71 | + mvn test -P ios-first-test |
| 72 | + ``` |
| 73 | +
|
| 74 | +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) |
| 75 | +
|
| 76 | +--- |
| 77 | +
|
| 78 | +### Use Local testing for apps that access resources hosted in development or testing environments : |
| 79 | +
|
| 80 | +**1. Upoad your Android or iOS App** |
| 81 | +
|
| 82 | +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) that access resources hosted on your internal or test environments to BrowserStack servers using our REST API. Here is an example cURL request : |
| 83 | +
|
| 84 | +``` |
| 85 | +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ |
| 86 | +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ |
| 87 | +-F "file=@/path/to/apk/file" |
| 88 | +``` |
| 89 | +
|
| 90 | +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. |
| 91 | +
|
| 92 | +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa). |
| 93 | +
|
| 94 | +**2. Configure and run your local test** |
| 95 | +
|
| 96 | +Open `BrowserStackSampleLocal.java` file in the `android` or `ios` directory : |
| 97 | +
|
| 98 | +- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) |
| 99 | +
|
| 100 | +- Replace `bs://<app-id>` with the URL obtained from app upload step |
| 101 | +
|
| 102 | +- Set the device and OS version |
| 103 | +
|
| 104 | +- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Java binding for BrowserStack Local. |
| 105 | +
|
| 106 | +- If you have uploaded your own app update the test case |
| 107 | +
|
| 108 | +- To run the test, use the following command in the base directory : |
| 109 | +
|
| 110 | + - For Android test, run |
| 111 | +
|
| 112 | + ```cmd |
| 113 | + mvn test -P android-local-test |
| 114 | + ``` |
| 115 | +
|
| 116 | + - For iOS test, run |
| 117 | +
|
| 118 | + ```cmd |
| 119 | + mvn test -P ios-local-test |
| 120 | + ``` |
| 121 | +
|
| 122 | +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) |
| 123 | +
|
| 124 | +
|
| 125 | +## Integration with other Java frameworks |
7 | 126 |
|
8 | 127 | - [JUnit](https://github.com/browserstack/junit-appium-app-browserstack)
|
9 |
| -- [TestNg](https://github.com/browserstack/testng-appium-app-browserstack) |
| 128 | +- [TestNg](https://github.com/browserstack/testng-appium-app-browserstack) |
| 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