|
| 1 | +--- |
| 2 | +id: accessibility-android-automation-test |
| 3 | +title: Automation Tests with Accessibility Tool using Android |
| 4 | +sidebar_label: Automation |
| 5 | +description: Use LambdaTest Accessibility DevTools to detect and report accessibility issues with automation, following WCAG guidelines. |
| 6 | +keywords: |
| 7 | + - LambdaTest |
| 8 | + - Accessibility |
| 9 | + - Testing |
| 10 | + - Automation |
| 11 | + - Accessibility Testing Settings |
| 12 | +url: https://www.lambdatest.com/support/docs/accessibility-android-automation-test/ |
| 13 | +site_name: LambdaTest |
| 14 | +slug: accessibility-android-automation-test/ |
| 15 | +--- |
| 16 | + |
| 17 | +import CodeBlock from '@theme/CodeBlock'; |
| 18 | +import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/component/keys"; |
| 19 | +import Tabs from '@theme/Tabs'; |
| 20 | +import TabItem from '@theme/TabItem'; |
| 21 | + |
| 22 | +<script type="application/ld+json" |
| 23 | + dangerouslySetInnerHTML={{ __html: JSON.stringify({ |
| 24 | + "@context": "https://schema.org", |
| 25 | + "@type": "BreadcrumbList", |
| 26 | + "itemListElement": [{ |
| 27 | + "@type": "ListItem", |
| 28 | + "position": 1, |
| 29 | + "name": "Home", |
| 30 | + "item": "https://www.lambdatest.com" |
| 31 | + },{ |
| 32 | + "@type": "ListItem", |
| 33 | + "position": 2, |
| 34 | + "name": "Support", |
| 35 | + "item": "https://www.lambdatest.com/support/docs/" |
| 36 | + },{ |
| 37 | + "@type": "ListItem", |
| 38 | + "position": 3, |
| 39 | + "name": "Accessibility Android Test", |
| 40 | + "item": "https://www.lambdatest.com/support/docs/accessibility-android-automation-test/" |
| 41 | + }] |
| 42 | + }) |
| 43 | + }} |
| 44 | +></script> |
| 45 | +LambdaTest now enables native Accessibility Automation Testing for Android apps using HyperExecute and Appium. This feature helps developers and QA teams to validate the accessibility of their mobile apps programmatically by leveraging LambdaTest's device cloud. |
| 46 | + |
| 47 | +With built-in support for `lambda-accessibility-scan`, this integration ensures that your apps are tested for compliance with accessibility standards and best practices like WCAG (Web Content Accessibility Guidelines). |
| 48 | + |
| 49 | +## Prerequisites |
| 50 | +Before getting started, ensure the following: |
| 51 | + |
| 52 | +- You have a LambdaTest account. |
| 53 | +- LambdaTest credentials (username & access key). |
| 54 | +- Android app uploaded to LambdaTest App Storage (lt://APP_ID). |
| 55 | +- Python 3 installed locally. |
| 56 | +- Appium-Python-Client installed |
| 57 | +- Access to a valid Android device on LambdaTest (real or virtual). |
| 58 | + |
| 59 | +> This will work for both Android and iOS applications. |
| 60 | +
|
| 61 | +## Step 1: Setup the Environment Variables |
| 62 | + |
| 63 | +You need to export your environment variables *LT_USERNAME* and *LT_ACCESS_KEY* that are available in your [LambdaTest Profile page](https://accounts.lambdatest.com/security). Run the below mentioned commands in your terminal to setup the environment variables. |
| 64 | + |
| 65 | +<Tabs className="docs__val"> |
| 66 | +<TabItem value="bash" label="Linux / MacOS" default> |
| 67 | + <div className="lambdatest__codeblock"> |
| 68 | + <CodeBlock className="language-bash"> |
| 69 | + {`export LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" |
| 70 | +export LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`} |
| 71 | + </CodeBlock> |
| 72 | +</div> |
| 73 | +</TabItem> |
| 74 | +<TabItem value="powershell" label="Windows" default> |
| 75 | + <div className="lambdatest__codeblock"> |
| 76 | + <CodeBlock className="language-powershell"> |
| 77 | + {`set LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" |
| 78 | +set LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`} |
| 79 | + </CodeBlock> |
| 80 | +</div> |
| 81 | +</TabItem> |
| 82 | +</Tabs> |
| 83 | + |
| 84 | +## Step 2: Upload your Application |
| 85 | +Upload your **_iOS_** application (.ipa file) or **_android_** application (.apk or .aab 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. |
| 86 | + |
| 87 | +Make sure to add the path of the **appFile** in the cURL request. Below is an example cURL request to upload your app using our REST API: |
| 88 | + |
| 89 | +<Tabs className="docs__val"> |
| 90 | + |
| 91 | +<TabItem value="bash" label="App File" default> |
| 92 | + <div className="lambdatest__codeblock"> |
| 93 | + <CodeBlock className="language-bash"> |
| 94 | + {`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"" -F "name="proverbial_app""`} |
| 95 | + </CodeBlock> |
| 96 | + </div> |
| 97 | +</TabItem> |
| 98 | + |
| 99 | +<TabItem value="powershell" label="App URL" default> |
| 100 | + <div className="lambdatest__codeblock"> |
| 101 | + <CodeBlock className="language-bash"> |
| 102 | + {`curl -u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "url=:https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk" -F "name=Proverbial_App"`} |
| 103 | + </CodeBlock> |
| 104 | + </div> |
| 105 | +</TabItem> |
| 106 | + |
| 107 | +</Tabs> |
| 108 | + |
| 109 | +:::tip |
| 110 | + |
| 111 | +- If you do not have any **.apk** or **.ipa** file, you can run your sample tests on LambdaTest by using our sample apps, :link: [Android app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk) or :link: [iOS app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_ios.ipa). |
| 112 | + |
| 113 | +- 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 |
| 114 | + |
| 115 | +::: |
| 116 | + |
| 117 | +## Step 3: Configure required Capabilities |
| 118 | +To enable accessibility testing, the following two configurations are mandatory: |
| 119 | + |
| 120 | +- Enable accessibility in capabilities: |
| 121 | +```python |
| 122 | +"accessibility": True |
| 123 | +``` |
| 124 | + |
| 125 | +- Invoke scan via script: |
| 126 | +```python |
| 127 | +driver.execute_script("lambda-accessibility-scan") |
| 128 | +``` |
| 129 | + |
| 130 | +You may call `lambda-accessibility-scan` multiple times to scan different app screens or flows. |
| 131 | + |
| 132 | + |
| 133 | +:::info |
| 134 | + |
| 135 | +- You must add the generated **APP_URL** to the `app` capability in the config file. |
| 136 | +- You can generate capabilities for your test requirements with the help of our inbuilt [**Capabilities Generator tool**](https://www.lambdatest.com/capabilities-generator/).For more details, please refer to our guide on [**Desired Capabilities in Appium**](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/). |
| 137 | + |
| 138 | +::: |
| 139 | + |
| 140 | +### Sample Script |
| 141 | + |
| 142 | +```python |
| 143 | +from curses import flash |
| 144 | +import time |
| 145 | +# import requests |
| 146 | +from appium import webdriver |
| 147 | +from selenium.webdriver.support.ui import WebDriverWait |
| 148 | +from selenium.webdriver.support import expected_conditions as EC |
| 149 | +import unittest |
| 150 | +import os |
| 151 | +from appium import webdriver |
| 152 | +from appium.options.android import UiAutomator2Options |
| 153 | +import sys |
| 154 | +from selenium.webdriver.common.by import By |
| 155 | +from appium.webdriver.client_config import AppiumClientConfig |
| 156 | + |
| 157 | + |
| 158 | +options = UiAutomator2Options() |
| 159 | +options.load_capabilities({ |
| 160 | + "platform": "android", |
| 161 | + "platformVersion": "14", |
| 162 | + "deviceName": "Galaxy S23 Ultra", |
| 163 | + "isRealMobile": True, |
| 164 | + "app" : "lt://YOUR_APP_ID", |
| 165 | + "accessibility": True, |
| 166 | + "buildName": "Accessibility-lambda", |
| 167 | + "idleTimeout": 1800, |
| 168 | + "build": "Accessibility Native App", |
| 169 | + "name": "Android App Accessibility", |
| 170 | + "devicelog": True, |
| 171 | + "visual": True, |
| 172 | +}) |
| 173 | +url = "https://YOUR_LT_USERNAME:[email protected]/wd/hub" |
| 174 | + |
| 175 | +client_config = AppiumClientConfig( |
| 176 | + remote_server_addr=url, |
| 177 | + ignore_certificates=True, |
| 178 | + direct_connection=True |
| 179 | +) |
| 180 | + |
| 181 | +driver = webdriver.Remote(client_config.remote_server_addr, options = options, client_config=client_config) |
| 182 | +driver.implicitly_wait(2) |
| 183 | + |
| 184 | +time.sleep(10) |
| 185 | + |
| 186 | +time.sleep(10) |
| 187 | +driver.execute_script("lambda-accessibility-scan") |
| 188 | +time.sleep(10) |
| 189 | +driver.find_element(By.CSS_SELECTOR, '#username').send_keys("Pbtest1") # Example CSS selector |
| 190 | +driver.execute_script("lambda-accessibility-scan") |
| 191 | + |
| 192 | +driver.quit() |
| 193 | +``` |
| 194 | + |
| 195 | +## Step 4: Execute and Monitor your Tests |
| 196 | +Run the following command in the directory where your project has been saved to execute your build. |
| 197 | + |
| 198 | +```bash |
| 199 | +python3 test.py |
| 200 | +``` |
| 201 | + |
| 202 | +## Accessibility Dashboard and Reporting |
| 203 | +You can check the complete detailed report on the [Accessibility Dashboard](https://accessibility.lambdatest.com/automation) |
| 204 | + |
| 205 | +<img loading="lazy" src={require('../assets/images/accessibility-testing/app-automation/6.png').default} alt="automation-dashboard" className="doc_img"/> |
| 206 | + |
0 commit comments