Skip to content

Commit 789fbff

Browse files
authored
Merge pull request LambdaTest#1671 from amanchopra1905/stage
Accessibility App Automation
2 parents 8ec7b66 + 2209959 commit 789fbff

16 files changed

+302
-98
lines changed
100 KB
Loading
101 KB
Loading
100 KB
Loading
98.7 KB
Loading
96.5 KB
Loading
Binary file not shown.
97.9 KB
Loading
Binary file not shown.
Binary file not shown.

docs/accessibility-android-automation-test.md

Lines changed: 124 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -42,114 +42,165 @@ import TabItem from '@theme/TabItem';
4242
})
4343
}}
4444
></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.
4546

46-
This guide walks you through automating accessibility testing of a native Android app using **LambdaTest's Accessibility Automation Tool (Beta) via Appium**. You'll run an automated accessibility scan on a real Android device hosted on LambdaTest’s real device cloud infrastructure.
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).
4748

4849
## Prerequisites
50+
Before getting started, ensure the following:
4951

50-
- Your [LambdaTest Username and Access key](/support/docs/using-environment-variables-for-authentication-credentials/)
51-
- Python 3.x or Java JDK 8+ installed
52-
- Appium Python Client or Java Client Library
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).
5358

54-
## Step-by-Step Guide to Trigger Your Test
59+
> This will work for both Android and iOS applications.
5560
56-
### Step 1: Setup Your Test Suite
61+
## Step 1: Setup the Environment Variables
5762

58-
You can use your own project to configure and test it. For demo purposes, we are using the sample repository.
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.
5964

60-
:::tip sample repo
61-
Download or Clone the code sample from the LambdaTest GitHub repository to run your tests.
62-
63-
<a href="https://github.com/LambdaTest/lambdatest-accessibility-selenium" 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+
<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>
6583

66-
If you are using your own project, make sure you update the **Hub endpoint** in your tests file. By setting up the Hub endpoint, you establish the communication channel between your tests and the browser nodes, enabling effective test distribution and execution.
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.
6786

68-
Configure the desired capabilities based on your test requirements. For example:
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:
6988

7089
<Tabs className="docs__val">
7190

72-
<TabItem value="python" label="Python" default>
73-
91+
<TabItem value="bash" label="App File" default>
7492
<div className="lambdatest__codeblock">
75-
76-
```python
77-
desired_cap = {
78-
"platform": "android",
79-
"isRealMobile": True,
80-
"app": "lt://APP", # Replace with your LambdaTest App URL
81-
"accessibility": True,
82-
"buildName": "Accessibility-lambda",
83-
"idleTimeout": 1800,
84-
"build": "NewAppiumBuild",
85-
"name": "MyTest",
86-
"devicelog": True
87-
}
88-
```
89-
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>
9096
</div>
91-
9297
</TabItem>
9398

94-
<TabItem value="java" label="Java" default>
95-
99+
<TabItem value="powershell" label="App URL" default>
96100
<div className="lambdatest__codeblock">
97-
```java
98-
DesiredCapabilities caps = new DesiredCapabilities();
99-
caps.setCapability("platform", "android");
100-
caps.setCapability("isRealMobile", true);
101-
caps.setCapability("app", "lt://APPID"); // Replace with your App ID
102-
caps.setCapability("accessibility", true);
103-
caps.setCapability("idleTimeout", 1800);
104-
caps.setCapability("build", "AccessibilityScanBuild");
105-
caps.setCapability("name", "MyTest");
106-
caps.setCapability("devicelog", true);
107-
```
108-
</div>
109-
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>
110105
</TabItem>
106+
111107
</Tabs>
112108

109+
:::tip
113110

114-
> You can generate capabilities for your test requirements with the help of our inbuilt 🔗 [Capabilities Generator Tool](https://www.lambdatest.com/capabilities-generator/).
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).
115112

116-
### Step 2: Establish User Authentication
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
117114

118-
Now, you need to export your environment variables *LT_USERNAME* and *LT_ACCESS_KEY* that are available in the [LambdaTest Profile page](https://accounts.lambdatest.com/detail/profile).
115+
:::
119116

120-
Run the below mentioned commands in your terminal to setup the CLI and the environment variables.
117+
## Step 3: Configure required Capabilities
118+
To enable accessibility testing, the following two configurations are mandatory:
121119

122-
<Tabs className="docs__val">
120+
- Enable accessibility in capabilities:
121+
```python
122+
"accessibility": True
123+
```
123124

124-
<TabItem value="bash" label="Linux / MacOS" default>
125+
- Invoke scan via script:
126+
```python
127+
driver.execute_script("lambda-accessibility-scan")
128+
```
125129

126-
<div className="lambdatest__codeblock">
127-
<CodeBlock className="language-bash">
128-
{`export LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}"
129-
export LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`}
130-
</CodeBlock>
131-
</div>
130+
You may call `lambda-accessibility-scan` multiple times to scan different app screens or flows.
132131

133-
</TabItem>
134132

135-
<TabItem value="powershell" label="Windows" default>
133+
:::info
136134

137-
<div className="lambdatest__codeblock">
138-
<CodeBlock className="language-powershell">
139-
{`set LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}"
140-
set LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`}
141-
</CodeBlock>
142-
</div>
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/).
143137

144-
</TabItem>
145-
</Tabs>
138+
:::
146139

147-
### Step 3: Execute and Monitor your Test
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+
```
148194

149-
Now execute your tests and visit the [Automation Dashboard](https://accounts.lambdatest.com/dashboard). Click on the Accessibility tab and check the report generated.
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.
150197

151198
```bash
152-
mvn test
199+
python3 test.py
153200
```
154201

155-
<img loading="lazy" src={require('../assets/images/accessibility-testing/accessibility-automation.png').default} alt="automation-dashboard" className="doc_img"/>
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

Comments
 (0)