|
1 | | -# LT-appium-java-junit |
| 1 | +# JUnit  |
2 | 2 |
|
3 | | -## Prerequisites |
| 3 | +<img height="300" src="https://img.shields.io/badge/Junit5-25A162?style=for-the-badge&logo=junit5&logoColor=white"> |
4 | 4 |
|
5 | | -To run your test script using JUnit with Appium, first you need to setup the environment. |
| 5 | +*JUnit is a popular unit testing framework for Java, and was an important part of test-driven development. It belongs to a family of unit testing frameworks known as xUnit.* |
6 | 6 |
|
7 | | -1. Install JDK 1.6 or higher version |
8 | | -2. Latest Selenium client and it’s WebDriver Bindings. |
9 | | -3. Download Maven([Windows](https://maven.apache.org/download.cgi), [Linux](https://maven.apache.org/install.html), and [Mac](https://maven.apache.org/install.html)) or Ant. Maven supports JUnit out of the box. You would just have to define Appium dependencies in it’s project object model file or pom.xml file. |
10 | | -4. Optional - To test your locally or privately hosted files, you need LambdaTest Tunnel binary file. |
| 7 | +*Learn the basics of [Appium testing on the LambdaTest platform](https://www.lambdatest.com/support/docs/getting-started-with-appium-testing/).* |
11 | 8 |
|
12 | | -## Steps to Run your First Test |
| 9 | +## Table of Contents |
13 | 10 |
|
14 | | -Step 1. Clone the Junit-Appium-Sample Repository. |
| 11 | +* [Objective](#objective) |
| 12 | +* [Pre-requisites](#pre-requisites) |
| 13 | +* [Run Your First Test](#run-your-first-test) |
15 | 14 |
|
16 | | -``` |
17 | | -git clone https://github.com/LambdaTest/LT-appium-java-junit.git |
18 | | -``` |
| 15 | +## JUnit With Appium |
19 | 16 |
|
20 | | -Step 2. Inside Junit-Appium-sample folder, set the Lambda-test Credentials. You can get these from your automation dashboard. |
| 17 | +In this topic, you will learn how to configure and run your **JUnit** automation testing scripts with **Appium** on **LambdaTest Real Device Cloud platform**. |
21 | 18 |
|
22 | | -<p align="center"> |
23 | | - <b>For Linux/macOS:</b> |
| 19 | +## Objective |
24 | 20 |
|
25 | | -``` |
26 | | -export LT_USERNAME="YOUR_USERNAME" |
27 | | -export LT_ACCESS_KEY="YOUR ACCESS KEY" |
28 | | -``` |
| 21 | +By the end of this topic, you will be able to: |
| 22 | + |
| 23 | +1. Run a sample automation script of **JUnit** for application testing with **Appium** on **LambdaTest**. |
| 24 | +2. Run test cases in **parallel** using JUnit with Appium to reduce build times. |
| 25 | +3. Learn more about Desired Capabilities for Appium testing. |
| 26 | +4. Explore advanced features of LambdaTest. |
| 27 | + |
| 28 | +## Pre-requisites |
| 29 | + |
| 30 | +Before you can start performing App automation testing with Appium, you would need to follow these steps: |
29 | 31 |
|
30 | | -<p align="center"> |
31 | | - <b>For Windows:</b> |
| 32 | +- Make sure you have Appium’s [Java client library](https://github.com/appium/java-client) installed. |
32 | 33 |
|
| 34 | +### Clone The Sample Project |
| 35 | + |
| 36 | +**Step-1:** Clone the LambdaTest’s :link: [LT-appium-java-junit](https://github.com/LambdaTest/LT-appium-java-junit) repository and navigate to the code directory as shown below: |
| 37 | + |
| 38 | +```bash |
| 39 | +git clone https://github.com/LambdaTest/LT-appium-java-junit |
| 40 | +cd LT-appium-java-junit |
33 | 41 | ``` |
34 | | -set LT_USERNAME="YOUR_USERNAME" |
35 | | -set LT_ACCESS_KEY="YOUR ACCESS KEY" |
| 42 | + |
| 43 | +### Setting Up Your Authentication |
| 44 | + |
| 45 | +Make sure you have your LambdaTest credentials with you to run test automation scripts on LambdaTest. To obtain your access credentials, [purchase a plan](https://billing.lambdatest.com/billing/plans) or access the [Automation Dashboard](https://appautomation.lambdatest.com/). |
| 46 | + |
| 47 | +**Step-2:** Set LambdaTest `Username` and `Access Key` in environment variables. |
| 48 | + |
| 49 | +**For Linux/macOS:** |
| 50 | + {`export LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" \\ |
| 51 | +export LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}`}" |
| 52 | + |
| 53 | + **For Windows:** |
| 54 | + {`set LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" \` |
| 55 | +set LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}`}" |
| 56 | + |
| 57 | +### Upload Your Application |
| 58 | + |
| 59 | +**Step-3:** Upload your **_iOS_** application (.ipa file) or **_android_** application (.apk file) to the LambdaTest servers using our **REST API**. You need to provide your **Username** and **AccessKey** in the format `Username:AccessKey` in the **cURL** command for authentication. Make sure to add the path of the **appFile** in the cURL request. Here is an example cURL request to upload your app using our REST API: |
| 60 | + |
| 61 | +**Using App File:** |
| 62 | + |
| 63 | +**For Linux/macOS:** |
| 64 | + |
| 65 | +{`curl -u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}" \\ |
| 66 | +--location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \\ |
| 67 | +--form 'name="Android_App"' \\ |
| 68 | +--form 'appFile=@"/Users/macuser/Downloads/proverbial_android.apk"' |
| 69 | +`} |
| 70 | + |
| 71 | +**For Windows:** |
| 72 | + |
| 73 | +{`curl -u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "appFile=@"/Users/macuser/Downloads/proverbial_android.apk""`} |
| 74 | + |
| 75 | +**Using App URL:** |
| 76 | + |
| 77 | +**For Linux/macOS:** |
| 78 | + |
| 79 | +{`curl -u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}" \\ |
| 80 | +--location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \\ |
| 81 | +--form 'name="Android_App"' \\ |
| 82 | +--form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"'`} |
| 83 | + |
| 84 | +**For Windows:** |
| 85 | + |
| 86 | +{`curl -u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -d "{\"url\":\"https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk\",\"name\":\"sample.apk\"}"`} |
| 87 | + |
| 88 | +**Tip:** |
| 89 | + |
| 90 | +- If you do not have any **.apk** or **.ipa** file, you can run your sample tests on LambdaTest by using our sample :link: [Android app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk) or sample :link: [iOS app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_ios.ipa). |
| 91 | +- Response of above cURL will be a **JSON** object containing the `App URL` of the format - <lt://APP123456789123456789> and will be used in the next step. |
| 92 | + |
| 93 | +## Run Your First Test |
| 94 | + |
| 95 | +Once you are done with the above-mentioned steps, you can initiate your first JUnit test on LambdaTest. |
| 96 | + |
| 97 | +**Test Scenario**: Check out [android.java](https://github.com/LambdaTest/LT-appium-java-junit/blob/master/src/test/java/com/lambdatest/android.java) file to view the sample test script for android and [ios.java](https://github.com/LambdaTest/LT-appium-java-junit/blob/master/src/test/java/com/lambdatest/ios.java) for iOS. |
| 98 | + |
| 99 | +### Configuring Your Test Capabilities |
| 100 | + |
| 101 | +**Step-4:** You can update your custom capabilities in test scripts. In this sample project, we are passing platform name, platform version, device name and app url (generated earlier) along with other capabilities like build name and test name via capabilities object. The capabilities object in the sample code are defined as: |
| 102 | + |
| 103 | +<Tabs className="docs__val"> |
| 104 | +<TabItem value="android-config" label="Android" default> |
| 105 | + |
| 106 | +```java |
| 107 | +DesiredCapabilities capabilities = new DesiredCapabilities(); |
| 108 | + |
| 109 | + capabilities.setCapability("build", "JUNIT Native App automation"); |
| 110 | + capabilities.setCapability("name", "Java JUnit Android Pixel 6"); |
| 111 | + capabilities.setCapability("platformName", "android"); |
| 112 | + capabilities.setCapability("deviceName", "Pixel 6"); //Enter the name of the device here |
| 113 | + capabilities.setCapability("isRealMobile", true); |
| 114 | + capabilities.setCapability("platformVersion","12"); |
| 115 | + capabilities.setCapability("app","YOUR_APP_URL"); //Enter the App ID here |
| 116 | + capabilities.setCapability("deviceOrientation", "PORTRAIT"); |
| 117 | + capabilities.setCapability("console",true); |
| 118 | + capabilities.setCapability("network",true); |
| 119 | + capabilities.setCapability("visual",true); |
36 | 120 | ``` |
37 | 121 |
|
38 | | -Step 3. Before running the Test |
| 122 | +</TabItem> |
| 123 | + |
| 124 | +<TabItem value="ios-config" label="iOS" default> |
39 | 125 |
|
| 126 | +```java |
| 127 | +DesiredCapabilities capabilities = new DesiredCapabilities(); |
| 128 | + |
| 129 | + capabilities.setCapability("build", "JUNIT Native App automation"); |
| 130 | + capabilities.setCapability("name", "Java JUnit iOS iPhone 12"); |
| 131 | + capabilities.setCapability("platformName", "ios"); |
| 132 | + capabilities.setCapability("deviceName", "iPhone 12"); |
| 133 | + capabilities.setCapability("isRealMobile", true); |
| 134 | + capabilities.setCapability("platformVersion","15"); |
| 135 | + capabilities.setCapability("app","YOUR_APP_URL"); //Enter the APP_ID here |
| 136 | + capabilities.setCapability("deviceOrientation", "PORTRAIT"); |
| 137 | + capabilities.setCapability("console",true); |
| 138 | + capabilities.setCapability("network",true); |
| 139 | + capabilities.setCapability("visual",true); |
40 | 140 | ``` |
| 141 | + |
| 142 | +</TabItem> |
| 143 | + |
| 144 | +</Tabs> |
| 145 | + |
| 146 | +**Info Note:** |
| 147 | + |
| 148 | +- You must add the generated **APP_URL** to the `"app"` capability in the config file. |
| 149 | +- You can generate capabilities for your test requirements with the help of our inbuilt **[Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/beta/index.html)**. A more Detailed Capability Guide is available [here](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/). |
| 150 | + |
| 151 | +### Executing The Test |
| 152 | + |
| 153 | +**Step-5:** Execute the following commands to install the required dependencies: |
| 154 | + |
| 155 | +```bash |
41 | 156 | mvn clean |
42 | 157 | ``` |
43 | 158 |
|
44 | | -Step 4. To run your First Test. |
| 159 | +**Step-6:** The tests can be executed in the terminal using the following command: |
45 | 160 |
|
46 | | -``` |
47 | | -mvn test -P single |
| 161 | +<Tabs className="docs__val"> |
| 162 | +<TabItem value="android-exec" label="Android" default> |
| 163 | + |
| 164 | +```bash |
| 165 | +mvn test android.java |
48 | 166 | ``` |
49 | 167 |
|
50 | | -Step 5. To run Parallel Test. |
| 168 | +</TabItem> |
51 | 169 |
|
| 170 | +<TabItem value="ios-exec" label="iOS" default> |
| 171 | + |
| 172 | +```bash |
| 173 | +mvn test ios.java |
52 | 174 | ``` |
53 | | -mvn test -P parallel |
54 | | -``` |
55 | 175 |
|
56 | | -## See the Results |
| 176 | +</TabItem> |
| 177 | +</Tabs> |
| 178 | + |
| 179 | +**Info:** Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on the :link: [LambdaTest App Automation Dashboard](https://appautomation.lambdatest.com/build). |
| 180 | + |
| 181 | +## Additional Links |
| 182 | + |
| 183 | +- [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/) |
| 184 | +- [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) |
| 185 | +- [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/) |
57 | 186 |
|
58 | | -You can see the results of the test on Lambdatest [Automation Dashboard](https://automation.lambdatest.com/build) |
59 | | - |
| 187 | +## LambdaTest Community :busts_in_silhouette: |
60 | 188 |
|
61 | | -## Testing Locally Hosted or Privately Hosted Projects |
| 189 | +The [LambdaTest Community](https://community.lambdatest.com/) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe. |
62 | 190 |
|
63 | | -To help you perform cross browser testing of your locally stored web pages, LambdaTest provides an SSH(Secure Shell) tunnel connection with the name Lambda Tunnel. With Lambda Tunnel, you can test your locally hosted files before you make them live over the internet. You could even perform cross browser testing from different IP addresses belonging to various geographic locations. You can also use LambdaTest Tunnel to test web-apps and websites that are permissible inside your corporate firewall. |
| 191 | +## Documentation & Resources :books: |
| 192 | + |
| 193 | +If you want to learn more about the LambdaTest's features, setup, and usage, visit the [LambdaTest documentation](https://www.lambdatest.com/support/docs/). You can also find in-depth tutorials around test automation, mobile app testing, responsive testing, manual testing on [LambdaTest Blog](https://www.lambdatest.com/blog/) and [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/). |
| 194 | + |
| 195 | + ## About LambdaTest |
64 | 196 |
|
65 | | -- Set tunnel value to True in test capabilities |
66 | | - > OS specific instructions to download and setup tunnel binary can be found at the following links. |
67 | | - > |
68 | | - > - [Windows](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+Windows) |
69 | | - > - [Mac](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+MacOS) |
70 | | - > - [Linux](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+Linux) |
71 | | - > After setting tunnel you can also see the active tunnel in our LambdaTest dashboard: |
72 | | - >  |
| 197 | +[LambdaTest](https://www.lambdatest.com) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs. |
73 | 198 |
|
74 | | -## About LambdaTest |
| 199 | +[<img height="70" src="https://user-images.githubusercontent.com/70570645/169649126-ed61f6de-49b5-4593-80cf-3391ca40d665.PNG">](https://accounts.lambdatest.com/register) |
| 200 | + |
| 201 | +## We are here to help you :headphones: |
75 | 202 |
|
76 | | -[LambdaTest](https://www.lambdatest.com/) is a cloud based selenium grid infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [selenium automation testing](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel. |
| 203 | +* Got a query? we are available 24x7 to help. [Contact Us](mailto:support@lambdatest.com) |
| 204 | +* For more info, visit - https://www.lambdatest.com |
0 commit comments