|
| 1 | +--- |
| 2 | +id: hyperexecute-smart-ui-sdk-maestro |
| 3 | +title: UI Testing with Maestro using HyperExecute and SmartUI SDK |
| 4 | +hide_title: false |
| 5 | +sidebar_label: Maestro |
| 6 | +description: Use the Maestro framework to run visual tests on Android apps via HyperExecute and SmartUI. Capture screenshots for visual comparison in mobile test automation. |
| 7 | +keywords: |
| 8 | + - smartui mobile testing |
| 9 | + - hyperexecute android tests |
| 10 | + - maestro visual regression |
| 11 | + - appium alternative |
| 12 | + - visual testing android emulator |
| 13 | + - smartui app screenshots |
| 14 | + - hyperexecute yaml mobile |
| 15 | +url: https://www.lambdatest.com/support/docs/hyperexecute-smart-ui-sdk-maestro/ |
| 16 | +site_name: LambdaTest |
| 17 | +slug: hyperexecute-smart-ui-sdk-maestro/ |
| 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": "LambdaTest", |
| 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": "UI Testing with Maestro", |
| 43 | + "item": "https://www.lambdatest.com/support/docs/hyperexecute-smart-ui-maestro/" |
| 44 | + }] |
| 45 | + }) |
| 46 | + }} |
| 47 | +></script> |
| 48 | + |
| 49 | +This document guides you on how to perform visual regression testing for your Android applications by running your Maestro tests on the HyperExecute platform and capturing screenshots with the SmartUI SDK. |
| 50 | + |
| 51 | +## Prerequisites |
| 52 | + |
| 53 | +Before you begin, ensure you have the following prerequisites in place: |
| 54 | + |
| 55 | +* Your LambdaTest Username and Access Key. You can find these on your dashboard -> left side bar -> credentials. |
| 56 | +* The [HyperExecute CLI](/support/docs/hyperexecute-cli-run-tests-on-hyperexecute-grid/) downloaded to your local machine. |
| 57 | +* An existing Android application file (`.apk`). |
| 58 | +* Node.js and npm installed on your system. |
| 59 | + |
| 60 | +## Step 1: Create a SmartUI Project |
| 61 | + |
| 62 | +First, you need to create a project in SmartUI. All your visual regression test builds for this project will be grouped here. |
| 63 | + |
| 64 | +1. Navigate to the [SmartUI Projects page](https://smartui.lambdatest.com/). |
| 65 | +2. Click on **New Project**. |
| 66 | +3. Select **CLI** as the platform. |
| 67 | +4. Provide a **Project Name**, select approvers, and add any relevant tags. |
| 68 | +5. Click **Submit**. |
| 69 | + |
| 70 | +:::info |
| 71 | +Once the project is created, you will get a unique `PROJECT_TOKEN`. Copy this token as it is required in the HyperExecute YAML configuration file later. |
| 72 | +::: |
| 73 | + |
| 74 | +## Step 2: Clone The Sample Repository |
| 75 | + |
| 76 | +You can configure your own existing Maestro project or get started quickly by cloning our sample repository. |
| 77 | + |
| 78 | +```bash |
| 79 | +git clone https://github.com/LambdaTest/smartui-maestro-sample |
| 80 | +cd smartui-maestro-sample |
| 81 | +``` |
| 82 | + |
| 83 | +:::tip Sample Repo |
| 84 | +You can find the complete code for this example in the following LambdaTest GitHub repository. |
| 85 | + |
| 86 | +<a href="https://github.com/LambdaTest/smartui-maestro-sample" className="github__anchor"><img loading="lazy" src={require('../assets/images/icons/github.png').default} alt="Image" className="doc_img"/> View on GitHub</a> |
| 87 | + |
| 88 | +::: |
| 89 | + |
| 90 | +## Step 3: Upload Your Application |
| 91 | + |
| 92 | +To run your tests on LambdaTest real devices or emulators, you need to upload your Android app (`.apk`) and get an `appId`. |
| 93 | + |
| 94 | +Run the following `cURL` command in your terminal. Ensure you have set your `LT_USERNAME` and `LT_ACCESS_KEY` as environment variables. |
| 95 | + |
| 96 | + |
| 97 | +<div className="lambdatest__codeblock"> |
| 98 | +<CodeBlock className="language-bash"> |
| 99 | +{`curl -u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "appFile=@"<YOUR_LOCAL_APP_PATH>"" -F "name="sampleApp"" |
| 100 | +`} |
| 101 | +</CodeBlock> |
| 102 | +</div> |
| 103 | + |
| 104 | +From the JSON response, copy the value of `app_url`. It will be in the format `lt://...`. This is your `appId`. |
| 105 | + |
| 106 | +## Step 4: Configure Your Test Suite |
| 107 | + |
| 108 | +Now, let's set up the test suite to integrate with SmartUI. |
| 109 | + |
| 110 | +#### 4.1. Install SmartUI CLI |
| 111 | + |
| 112 | +The SmartUI CLI is required to capture and upload screenshots. Install it in your project directory: |
| 113 | + |
| 114 | +```bash |
| 115 | +npm i @lambdatest/smartui-cli |
| 116 | +``` |
| 117 | + |
| 118 | +#### 4.2. Add SmartUI Screenshots to Your Maestro Flow |
| 119 | + |
| 120 | +In your Maestro test YAML files (e.g., `maestro-test/test.yaml`), add the `takeScreenshot` command wherever you want to capture a visual checkpoint. The `path` specified will be used to name the screenshot in the SmartUI dashboard. |
| 121 | + |
| 122 | +```yaml |
| 123 | +- launchApp |
| 124 | +- takeScreenshot: |
| 125 | + path: ./screenshots/home-screen |
| 126 | +- tapOn: "Login" |
| 127 | +- takeScreenshot: |
| 128 | + path: ./screenshots/login-page |
| 129 | +``` |
| 130 | +
|
| 131 | +#### 4.3. Set Up Environment Variables |
| 132 | +
|
| 133 | +Now, you need to export your environment variables *LT_USERNAME* and *LT_ACCESS_KEY* that are available in the [LambdaTest Username and Access Key Page](https://accounts.lambdatest.com/security/username-accesskey). |
| 134 | +
|
| 135 | +Run the below mentioned commands in your terminal to setup the CLI and the environment variables. |
| 136 | +
|
| 137 | +<Tabs className="docs__val"> |
| 138 | +<TabItem value="bash" label="Linux / MacOS" default> |
| 139 | +
|
| 140 | + <div className="lambdatest__codeblock"> |
| 141 | + <CodeBlock className="language-bash"> |
| 142 | + {`export LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" |
| 143 | +export LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`} |
| 144 | + </CodeBlock> |
| 145 | +</div> |
| 146 | + |
| 147 | +</TabItem> |
| 148 | + |
| 149 | +<TabItem value="powershell" label="Windows" default> |
| 150 | + |
| 151 | + <div className="lambdatest__codeblock"> |
| 152 | + <CodeBlock className="language-powershell"> |
| 153 | + {`set LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" |
| 154 | +set LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`} |
| 155 | + </CodeBlock> |
| 156 | +</div> |
| 157 | + |
| 158 | +</TabItem> |
| 159 | +</Tabs> |
| 160 | + |
| 161 | + |
| 162 | +## Step 5: Configure the HyperExecute YAML |
| 163 | + |
| 164 | +The HyperExecute YAML file is the blueprint for your test execution. It tells HyperExecute how to set up the environment and run your tests. |
| 165 | + |
| 166 | +You need to add your `PROJECT_TOKEN` (from Step 1) and your `appId` (from Step 3) to the YAML file. Below are example configurations for running Maestro tests on Emulators and Real Devices. |
| 167 | + |
| 168 | +<Tabs className="docs__val"> |
| 169 | +<TabItem value="android-rd" label="Android-Real Device" default> |
| 170 | + |
| 171 | +```yaml reference title="maestro_Real_Devices.yaml" |
| 172 | +https://github.com/LambdaTest/smartui-maestro-sample/blob/main/yaml/maestro_Real_Devices.yaml |
| 173 | +``` |
| 174 | +</TabItem> |
| 175 | + |
| 176 | +<TabItem value="android-emu" label="Android-Emulator" default> |
| 177 | + |
| 178 | +> To enable this for your organizaton, connect with us through our <span className="doc\_\_lt" onClick={() => window.openLTChatWidget()}>**24/7 chat support**</span> or drop us an email to [[email protected]](mailto:[email protected]). |
| 179 | + |
| 180 | +```yaml reference title="maestro_Emulator_HyperEx.yaml" |
| 181 | +https://github.com/LambdaTest/smartui-maestro-sample/blob/main/yaml/maestro_Emulator_HyperEx.yaml |
| 182 | +``` |
| 183 | +</TabItem> |
| 184 | + |
| 185 | +</Tabs> |
| 186 | + |
| 187 | + |
| 188 | +:::info |
| 189 | +In the real device configuration, the `testDiscovery` and `testRunnerCommand` are handled internally by the `maestro` framework integration on HyperExecute. You just need to specify the `framework` block. |
| 190 | +::: |
| 191 | + |
| 192 | +## Step 6: Execute Your Test Suite |
| 193 | + |
| 194 | +Run the below command in your terminal at the root folder of the project: |
| 195 | + |
| 196 | +```bash |
| 197 | +./hyperexecute --config RELATIVE_PATH_OF_YOUR_YAML_FILE |
| 198 | +``` |
| 199 | + |
| 200 | +OR use this command if you have not exported your username and access key in the step 2. |
| 201 | + |
| 202 | +<div className="lambdatest__codeblock"> |
| 203 | + <CodeBlock className="language-bash"> |
| 204 | + {`./hyperexecute --user ${ YOUR_LAMBDATEST_USERNAME()} --key ${ YOUR_LAMBDATEST_ACCESS_KEY()} --config RELATIVE_PATH_OF_YOUR_YAML_FILE `} |
| 205 | + </CodeBlock> |
| 206 | +</div> |
| 207 | + |
| 208 | +<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/maestro/1.png').default} alt="JUnit HyperExecute Terminal Logs" width="1920" height="868" className="doc_img"/> |
| 209 | + |
| 210 | + |
| 211 | +## Step 7: View Your Visual Test Results on SmartUI |
| 212 | + |
| 213 | +After the HyperExecute job is finished, all screenshots captured using the `takeScreenshot` command will be available in your SmartUI project for review. |
| 214 | + |
| 215 | +<img loading="lazy" src={require('../assets/images/smart-visual-testing/smartui-sdk-results-primer.webp').default} alt="SmartUI Results" width="768" height="373" className="doc_img"/> |
| 216 | + |
| 217 | +1. Navigate to the [SmartUI Dashboard](https://smartui.lambdatest.com/). |
| 218 | +2. Select your project and the most recent build. |
| 219 | +3. Here, you can compare screenshots against the baseline, highlight differences, and approve or reject changes. You can use features like Smart Ignore to mask dynamic areas for more stable comparisons. |
| 220 | + |
| 221 | + |
| 222 | +<nav aria-label="breadcrumbs"> |
| 223 | + <ul className="breadcrumbs"> |
| 224 | + <li className="breadcrumbs__item"> |
| 225 | + <a className="breadcrumbs__link" target="_self" href="https://www.lambdatest.com"> |
| 226 | + Home |
| 227 | + </a> |
| 228 | + </li> |
| 229 | + <li className="breadcrumbs__item"> |
| 230 | + <a className="breadcrumbs__link" target="_self" href="https://www.lambdatest.com/support/docs/"> |
| 231 | + Support |
| 232 | + </a> |
| 233 | + </li> |
| 234 | + <li className="breadcrumbs__item breadcrumbs__item--active"> |
| 235 | + <span className="breadcrumbs__link">SmartUI App SDK</span> |
| 236 | + </li> |
| 237 | + </ul> |
| 238 | +</nav> |
0 commit comments