|
1 | 1 | # junit-appium-app-browserstack |
2 | | -[JUnit](http://junit.org/junit4/) Integration with BrowserStack. |
| 2 | +[JUnit4](http://junit.org/junit4/) and [Junit5](https://junit.org/junit5/) Integration with BrowserStack. |
3 | 3 |
|
4 | 4 |  |
5 | 5 |
|
6 | 6 |  |
7 | 7 |
|
8 | | -Code samples to get started with Appium tests for your Native App using the JUnit framework. |
| 8 | +## Setup |
9 | 9 |
|
10 | | -## Resources |
11 | | -* [Android Get Started guide](https://www.browserstack.com/app-automate/get-started) |
12 | | -* [Android sample code repo](https://github.com/browserstack/junit-appium-app-browserstack/tree/master/android) |
13 | | -* [IOS Get Started guide](https://www.browserstack.com/app-automate/get-started-ios) |
14 | | -* [IOS sample code repo](https://github.com/browserstack/junit-appium-app-browserstack/tree/master/ios) |
| 10 | +### Requirements |
| 11 | + |
| 12 | +1. Java 8 |
| 13 | + |
| 14 | + - If Java is not installed, follow these instructions: |
| 15 | + - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable |
| 16 | + - 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/) |
| 17 | + |
| 18 | +2. Maven |
| 19 | + |
| 20 | + - If Maven is not installed, follow the instructions [here](https://maven.apache.org/install.html) |
| 21 | + |
| 22 | +### Install the dependencies |
| 23 | + |
| 24 | +To install the dependencies for Android tests, run : |
| 25 | + |
| 26 | +- For Junit4 |
| 27 | + |
| 28 | + ```sh |
| 29 | + cd android/junit4-examples |
| 30 | + mvn clean |
| 31 | + ``` |
| 32 | + |
| 33 | +- For Junit5 |
| 34 | + |
| 35 | + ```sh |
| 36 | + cd android/junit5-examples |
| 37 | + mvn clean |
| 38 | + ``` |
| 39 | + |
| 40 | +Or, |
| 41 | + |
| 42 | +To install the dependencies for iOS tests, run : |
| 43 | + |
| 44 | +- For Junit4 |
| 45 | + |
| 46 | + ```sh |
| 47 | + cd ios/junit4-examples |
| 48 | + mvn clean |
| 49 | + ``` |
| 50 | + |
| 51 | +- For Junit5 |
| 52 | + |
| 53 | + ```sh |
| 54 | + cd ios/junit5-examples |
| 55 | + mvn clean |
| 56 | + ``` |
| 57 | + |
| 58 | +### Update `username` and `access_key` keys in *.conf.json |
| 59 | + |
| 60 | +- Junit4 |
| 61 | + |
| 62 | + - Update *.conf.json files for `username`, `access_key` keys inside the [android/junit4-examples/src/test/resources/](android/junit4-examples/src/test/resources) for Android examples and inside [ios/junit4-examples/src/test/resources](ios/junit4-examples/src/test/resources) for iOS examples with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). |
| 63 | + |
| 64 | +- Junit5 |
| 65 | + |
| 66 | + - Update *.conf.json files for `username`, `access_key` inside the [android/junit5-examples/src/test/resources](android/junit5-examples/src/test/resources) for Android examples and inside [ios/junit5-examples/src/test/resources](ios/junit5-examples/src/test/resources) for iOS examples with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). |
| 67 | + |
| 68 | +- Note: You can also export the environment variables for the Username and Access Key of your BrowserStack account. |
| 69 | + |
| 70 | + ``` |
| 71 | + export BROWSERSTACK_USERNAME=<browserstack-username> && |
| 72 | + export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key> |
| 73 | + ``` |
| 74 | + |
| 75 | +### Upload app and update `app` key in *.conf.json |
| 76 | + |
| 77 | +- Android |
| 78 | + - Upload your Native App (.apk file) to BrowserStack servers using upload API: |
| 79 | + |
| 80 | + ``` |
| 81 | + curl -u "username:access_key" -X POST "https://api-cloud.browserstack.com/app-automate/upload" -F "file=@/path/to/app/file/Application-debug.apk" |
| 82 | + ``` |
| 83 | + - If you do not have an .apk file and looking to simply try App Automate, [you can download our sample app and upload](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) |
| 84 | + to the BrowserStack servers using the above API. |
| 85 | + |
| 86 | + - You can use public url as well to upload your app |
| 87 | + |
| 88 | + ``` |
| 89 | + curl -u "username:access_key" \ |
| 90 | + -X POST "https://api-cloud.browserstack.com/app-automate/upload" \ |
| 91 | + -F "url=https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk" |
| 92 | + ``` |
| 93 | + - Please note the value of app_url in the API response (bs://f7c874f21852.... in the above examples). |
| 94 | + |
| 95 | + - Update *.conf.json with value of `app_url`(got from response) for `app` key |
| 96 | + |
| 97 | + - Junit4 |
| 98 | + |
| 99 | + - Files inside the [android/junit4-examples/src/test/resources/](android/junit4-examples/src/test/resources) for Android examples and inside [ios/junit4-examples/src/test/resources](ios/junit4-examples/src/test/resources) for iOS examples. |
| 100 | + |
| 101 | + - Junit5 |
| 102 | + |
| 103 | + - Files inside the [android/junit5-examples/src/test/resources](android/junit5-examples/src/test/resources) for Android examples and inside [ios/junit5-examples/src/test/resources](ios/junit5-examples/src/test/resources) for iOS examples . |
| 104 | + |
| 105 | + |
| 106 | +## Getting Started |
| 107 | + |
| 108 | +Getting Started with Appium tests in Junit4 and Junit5 on BrowserStack couldn't be easier! |
| 109 | +
|
| 110 | +### **Run first test :** |
| 111 | +
|
| 112 | +- Junit4 |
| 113 | + - Switch to `run_first_test` directory under [Android examples](android/junit4-examples) or [iOS examples](ios/junit4-examples) |
| 114 | + - Then run |
| 115 | + ```sh |
| 116 | + mvn test -P first |
| 117 | + ``` |
| 118 | +- Junit5 |
| 119 | + - Switch to `run_first_test` directory under [Android examples](android/junit5-examples) or [iOS examples](ios/junit5-examples) |
| 120 | + - Then run |
| 121 | + ```sh |
| 122 | + mvn test -P first |
| 123 | + ``` |
| 124 | +- Alternatively, you can follow the steps outlined in the documentation - [Get Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/junit) |
| 125 | +
|
| 126 | +### **Speed up test execution with parallel testing :** |
| 127 | +
|
| 128 | +- Junit4 |
| 129 | + - Switch to `run_parallel_test` directory under [Android examples](android/junit4-examples/) or [iOS examples](ios/junit4-examples/) |
| 130 | + - Then run |
| 131 | + ```sh |
| 132 | + mvn test -P parallel |
| 133 | + ``` |
| 134 | +- Junit5 |
| 135 | + - Switch to `run_parallel_test` directory under [Android examples](android/junit5-examples/) or [iOS examples](ios/junit5-examples/) |
| 136 | + - Then run |
| 137 | + ```sh |
| 138 | + mvn test -P parallel |
| 139 | + ``` |
| 140 | + |
| 141 | +- Alternatively, you can follow the steps outlined in the documentation - [Get Started with your parallel test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/junit/parallelize-tests) |
| 142 | +
|
| 143 | +### **Use Local testing for apps that access resources hosted in development or testing environments :** |
| 144 | +
|
| 145 | +- Junit4 |
| 146 | + - Switch to `run-local-test` directory under [Android examples](android/junit4-examples/) or [iOS examples](ios/junit4-examples/) |
| 147 | + - Then run |
| 148 | + ```sh |
| 149 | + mvn test -P local |
| 150 | + ``` |
| 151 | +- Junit5 |
| 152 | + - Switch to `run-local-test` directory under [Android examples](android/junit5-examples/) or [iOS examples](ios/junit5-examples/) |
| 153 | + - Then run |
| 154 | + ```sh |
| 155 | + mvn test -P local |
| 156 | + ``` |
| 157 | +- Alternatively, you can follow the steps outlined in the documentation - [Get Started with Local testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/java/junit/local-testing) |
| 158 | +
|
| 159 | +**Note**: If you are facing any issues, refer [Getting Help section](#Getting-Help) |
| 160 | +
|
| 161 | +## Integration with other Java frameworks |
| 162 | +
|
| 163 | +For other Java frameworks samples, refer to following repositories : |
| 164 | +
|
| 165 | +- [TestNG](https://github.com/browserstack/testng-appium-app-browserstack) |
| 166 | +- [Java](https://github.com/browserstack/java-appium-app-browserstack) |
| 167 | +
|
| 168 | +Note: For other test frameworks supported by App-Automate refer our [Developer documentation](https://www.browserstack.com/docs/) |
| 169 | +
|
| 170 | +## Getting Help |
| 171 | +
|
| 172 | +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