|
| 1 | +--- |
| 2 | +id: hyperexecute-appium-virtual-device |
| 3 | +title: Appium Testing - Virtual Device On HyperExecute |
| 4 | +sidebar_label: Appium - Virtual Device |
| 5 | +description: Maximize Appium test execution with HyperExecute – Explore LambdaTest's support documentation for seamless automation testing. |
| 6 | +keywords: |
| 7 | + - appium |
| 8 | + - java |
| 9 | + - lambdatest java |
| 10 | + - framework on lambdatest |
| 11 | + - testng |
| 12 | + - app testing |
| 13 | + - virtual devices |
| 14 | +image: /assets/images/og-images/appium-testing-og-image.jpg |
| 15 | +url: https://www.lambdatest.com/support/docs/hyperexecute-appium-virtual-device/ |
| 16 | +site_name: LambdaTest |
| 17 | +slug: hyperexecute-appium-virtual-device/ |
| 18 | +--- |
| 19 | + |
| 20 | +import CodeBlock from '@theme/CodeBlock'; |
| 21 | +import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/component/keys"; |
| 22 | +import Tabs from '@theme/Tabs'; |
| 23 | +import TabItem from '@theme/TabItem'; |
| 24 | + |
| 25 | +<script type="application/ld+json" |
| 26 | + dangerouslySetInnerHTML={{ __html: JSON.stringify({ |
| 27 | + "@context": "https://schema.org", |
| 28 | + "@type": "BreadcrumbList", |
| 29 | + "itemListElement": [{ |
| 30 | + "@type": "ListItem", |
| 31 | + "position": 1, |
| 32 | + "name": "Home", |
| 33 | + "item": "https://www.lambdatest.com" |
| 34 | + },{ |
| 35 | + "@type": "ListItem", |
| 36 | + "position": 2, |
| 37 | + "name": "Support", |
| 38 | + "item": "https://www.lambdatest.com/support/docs/" |
| 39 | + },{ |
| 40 | + "@type": "ListItem", |
| 41 | + "position": 3, |
| 42 | + "name": "Getting Started With Appium Testing on LambdaTest", |
| 43 | + "item": "https://www.lambdatest.com/support/docs/hyperexecute-appium-virtual-device/" |
| 44 | + }] |
| 45 | + }) |
| 46 | + }} |
| 47 | +></script> |
| 48 | +This page outlines how to execute your Appium tests on HyperExecute using TestNG with YAML 0.2 |
| 49 | +> HyperExecute uses [YAML 0.2](/support/docs/hyperexecute-yaml-version0.2/) to perform the tests using Appium. |
| 50 | +
|
| 51 | +## Prerequisites |
| 52 | + |
| 53 | +To run the Tests on HyperExecute from your Local System, you are required: |
| 54 | + |
| 55 | +- [HyperExecute YAML](/support/docs/hyperexecute-yaml-version0.2/) file which contains all the necessary instructions. |
| 56 | +- [HyperExecute CLI](/support/docs/hyperexecute-cli-run-tests-on-hyperexecute-grid/) in order to initiate a test execution Job . |
| 57 | +- Your lambdatest [Username and Access key](/support/docs/hyperexecute-how-to-get-my-username-and-access-key/) |
| 58 | +- Setup the Environmental Variable |
| 59 | +- Ensure you have Appium’s [Java client library](https://github.com/appium/java-client) installed. |
| 60 | +- Access to an **Android** app (.apk or .aab file) |
| 61 | + |
| 62 | +:::tip Sample repo |
| 63 | +All the code samples in this documentation can be found on **LambdaTest's Github Repository**. You can either download or clone the repository to quickly run your tests. <a href="https://github.com/LambdaTest/hyperexecute-appium-testng/tree/android-emulator" className="github__anchor"><img loading="lazy" src={require('../assets/images/icons/github.png').default} alt="Image" className="doc_img"/> View on GitHub</a> |
| 64 | +::: |
| 65 | +> If you do not have any **.apk** 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) |
| 66 | +
|
| 67 | +### Download HyperExecute CLI |
| 68 | + |
| 69 | +The *HyperExecute CLI* is used for triggering tests on HyperExecute. It is recommend to download the HyperExecute CLI binary on the host system to perform the tests on HyperExecute. The CLI download site for various platforms is displayed below: |
| 70 | + |
| 71 | +| Platform | HyperExecute CLI download location | |
| 72 | +| ---------| --------------------------- | |
| 73 | +| Windows | https://downloads.lambdatest.com/hyperexecute/windows/hyperexecute.exe | |
| 74 | +| macOS | https://downloads.lambdatest.com/hyperexecute/darwin/hyperexecute | |
| 75 | +| Linux | https://downloads.lambdatest.com/hyperexecute/linux/hyperexecute | |
| 76 | + |
| 77 | +### Setup Environment Variable |
| 78 | +Export the environment variables *LT_USERNAME* and *LT_ACCESS_KEY* that are available in the [LambdaTest Profile page](https://accounts.lambdatest.com/detail/profile). |
| 79 | +Run the below mentioned commands in the terminal to setup the CLI and the environment variables. |
| 80 | + |
| 81 | +<Tabs className="docs__val"> |
| 82 | + |
| 83 | +<TabItem value="bash" label="Linux / MacOS" default> |
| 84 | + |
| 85 | + <div className="lambdatest__codeblock"> |
| 86 | + <CodeBlock className="language-bash"> |
| 87 | + {`export LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" |
| 88 | +export LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`} |
| 89 | + </CodeBlock> |
| 90 | +</div> |
| 91 | + |
| 92 | +</TabItem> |
| 93 | + |
| 94 | +<TabItem value="powershell" label="Windows" default> |
| 95 | + |
| 96 | + <div className="lambdatest__codeblock"> |
| 97 | + <CodeBlock className="language-powershell"> |
| 98 | + {`set LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" |
| 99 | +set LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`} |
| 100 | + </CodeBlock> |
| 101 | +</div> |
| 102 | + |
| 103 | +</TabItem> |
| 104 | +</Tabs> |
| 105 | + |
| 106 | +## Steps to Run Your Test |
| 107 | + |
| 108 | +### Step 1: Upload your Application |
| 109 | +Upload your <b>_android_</b> application (.apk file) to the LambdaTest servers using our <b>REST API</b>. You need to provide your <b>Username</b> and <b>AccessKey</b> in the format `Username:AccessKey` in the <b>cURL</b> command for authentication. Make sure to add the path of the <b>appFile</b> in the cURL request. Here is an example cURL request to upload your app using our REST API: |
| 110 | + |
| 111 | +<Tabs className="docs__val"> |
| 112 | + <TabItem value="file" label="App file" default> |
| 113 | + |
| 114 | +<Tabs className="docs__val"> |
| 115 | +<TabItem value="macos-file" label="Linux / MacOS" default> |
| 116 | + |
| 117 | +<div className="lambdatest__codeblock"> |
| 118 | +<CodeBlock className="language-bash"> |
| 119 | +{`curl -u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}" --location --request POST 'https://manual-api.lambdatest.com/app/upload/virtualDevice' --form 'name="Android_App"' --form 'appFile=@"<RELATIVE_PATH_OF_YOUR_APP>"' |
| 120 | +`} |
| 121 | +</CodeBlock> |
| 122 | +</div> |
| 123 | + |
| 124 | +</TabItem> |
| 125 | + |
| 126 | +<TabItem value="windows-file" label="Windows" default> |
| 127 | +<div className="lambdatest__codeblock"> |
| 128 | +<CodeBlock className="language-powershell"> |
| 129 | +{`curl -u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}" -X POST "https://manual-api.lambdatest.com/app/upload/virtualDevice" -F "appFile=@"<RELATIVE_PATH_OF_YOUR_APP>"" |
| 130 | +`} |
| 131 | +</CodeBlock> |
| 132 | +</div> |
| 133 | +</TabItem> |
| 134 | +</Tabs> |
| 135 | + |
| 136 | + </TabItem> |
| 137 | + <TabItem value="url" label="App URL" default> |
| 138 | + |
| 139 | +<Tabs className="docs__val"> |
| 140 | +<TabItem value="macos-url" label="Linux / MacOS" default> |
| 141 | + |
| 142 | +<div className="lambdatest__codeblock"> |
| 143 | +<CodeBlock className="language-bash"> |
| 144 | +{`curl -u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}" \\ |
| 145 | +--location --request POST 'https://manual-api.lambdatest.com/app/upload/virtualDevice' \\ |
| 146 | +--form 'name="Android_App"' \\ |
| 147 | +--form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"'`} |
| 148 | +</CodeBlock> |
| 149 | +</div> |
| 150 | + |
| 151 | +</TabItem> |
| 152 | + |
| 153 | +<TabItem value="windows-url" label="Windows" default> |
| 154 | +<div className="lambdatest__codeblock"> |
| 155 | +<CodeBlock className="language-powershell"> |
| 156 | +{`curl -u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}" --location --request POST "https://manual-api.lambdatest.com/app/upload/virtualDevice" --header "Content-Type: application/x-www-form-urlencoded" --data-urlencode "url=:https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk" --data-urlencode "name=Proverbial_App"`} |
| 157 | +</CodeBlock> |
| 158 | +</div> |
| 159 | +</TabItem> |
| 160 | +</Tabs> |
| 161 | + |
| 162 | + </TabItem> |
| 163 | +</Tabs> |
| 164 | + |
| 165 | +> 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. |
| 166 | +
|
| 167 | +### Step 2: Configure your Test Script |
| 168 | +Write Your Automation Script in the client language of your choice from the ones supported by Appium. An automation script for the sample applications have been provided below. |
| 169 | + |
| 170 | +Here is a sample automation script in Java for the sample app downloaded above. Ensure to update the `app_url`, `username` and `accesskey` in the below code. |
| 171 | + |
| 172 | +```java reference title="AndroidEmulator.java" |
| 173 | +https://github.com/LambdaTest/hyperexecute-appium-testng/blob/android-emulator/src/main/java/AndroidEmulator.java |
| 174 | +``` |
| 175 | + |
| 176 | +### Step 3: Update your XML file |
| 177 | +Create `.XML` file in order to run your test and define device capabilities. Please find sample code below for the same. |
| 178 | + |
| 179 | +```xml reference title="android-emulator.xml" |
| 180 | +https://github.com/LambdaTest/hyperexecute-appium-testng/blob/android-emulator/src/test/java/android-emulator.xml |
| 181 | +``` |
| 182 | + |
| 183 | +### Step 4: Configure YAML and Execute your Script |
| 184 | +```yaml reference title="android-emulator.yaml" |
| 185 | +https://github.com/LambdaTest/hyperexecute-appium-testng/blob/android-emulator/yaml/hyp-android-emulator.yaml |
| 186 | +``` |
| 187 | + |
| 188 | +<!-- > The ```region``` parameter specifies the region or location where the Appium tests will be executed. Our platform supports the following three regions: |
| 189 | +- ap (Asia-Pacific) |
| 190 | +- us (United States) |
| 191 | +- eu (European Union) --> |
| 192 | + |
| 193 | +### Step 5: Execute your Test Suite |
| 194 | +> **NOTE :** In case of MacOS, if you get a permission denied warning while executing CLI, simply run **`chmod u+x ./hyperexecute`** to allow permission. In case you get a security popup, allow it from your **System Preferences** → **Security & Privacy** → **General tab**. |
| 195 | +
|
| 196 | +Run the below command in your terminal at the root folder of the project: |
| 197 | + |
| 198 | +```bash |
| 199 | +./hyperexecute --config RELATIVE_PATH_OF_YOUR_YAML_FILE |
| 200 | +``` |
| 201 | + |
| 202 | +OR use this command if you have not exported your username and access key in the step 2. |
| 203 | + |
| 204 | +<div className="lambdatest__codeblock"> |
| 205 | + <CodeBlock className="language-bash"> |
| 206 | + {`./hyperexecute --user ${ YOUR_LAMBDATEST_USERNAME()} --key ${ YOUR_LAMBDATEST_ACCESS_KEY()} --config RELATIVE_PATH_OF_YOUR_YAML_FILE `} |
| 207 | + </CodeBlock> |
| 208 | +</div> |
0 commit comments