|
| 1 | +--- |
| 2 | +id: accessibility-web-runtime-control |
| 3 | +title: Accessibility Testing with Runtime Control |
| 4 | +sidebar_label: Web Runtime Control |
| 5 | +description: Dynamically control accessibility scanning during test execution with LambdaTest's Lambda Hook for Selenium and Playwright frameworks. |
| 6 | +keywords: |
| 7 | + - LambdaTest |
| 8 | + - Accessibility |
| 9 | + - Testing |
| 10 | + - Automation |
| 11 | + - Runtime Control |
| 12 | + - Lambda Hook |
| 13 | + - Selenium Accessibility |
| 14 | + - Playwright Accessibility |
| 15 | + - WCAG |
| 16 | +url: https://www.lambdatest.com/support/docs/accessibility-web-runtime-control/ |
| 17 | +site_name: LambdaTest |
| 18 | +slug: accessibility-web-runtime-control/ |
| 19 | +--- |
| 20 | + |
| 21 | +import CodeBlock from '@theme/CodeBlock'; |
| 22 | +import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/component/keys"; |
| 23 | +import Tabs from '@theme/Tabs'; |
| 24 | +import TabItem from '@theme/TabItem'; |
| 25 | + |
| 26 | +<script type="application/ld+json" |
| 27 | + dangerouslySetInnerHTML={{ __html: JSON.stringify({ |
| 28 | + "@context": "https://schema.org", |
| 29 | + "@type": "BreadcrumbList", |
| 30 | + "itemListElement": [{ |
| 31 | + "@type": "ListItem", |
| 32 | + "position": 1, |
| 33 | + "name": "Home", |
| 34 | + "item": "https://www.lambdatest.com" |
| 35 | + },{ |
| 36 | + "@type": "ListItem", |
| 37 | + "position": 2, |
| 38 | + "name": "Support", |
| 39 | + "item": "https://www.lambdatest.com/support/docs/" |
| 40 | + },{ |
| 41 | + "@type": "ListItem", |
| 42 | + "position": 3, |
| 43 | + "name": "Accessibility Web Runtime Control", |
| 44 | + "item": "https://www.lambdatest.com/support/docs/accessibility-web-runtime-control/" |
| 45 | + }] |
| 46 | + }) |
| 47 | + }} |
| 48 | +></script> |
| 49 | + |
| 50 | +LambdaTest's accessibility testing feature enables automated accessibility scanning during test execution. This documentation covers both the continuous scanning approach and the new runtime control capability that provides granular control over when accessibility scans are performed. |
| 51 | + |
| 52 | +The latest update introduces **runtime control** for accessibility scanning through a Lambda Hook. This enhancement allows developers to dynamically enable or disable accessibility scans during test execution, providing precise control over which portions of the application are scanned. |
| 53 | + |
| 54 | +### Key Benefits |
| 55 | + |
| 56 | +- Toggle accessibility scanning on/off at any point during test execution |
| 57 | +- Scan specific user flows or application sections |
| 58 | +- Optimize test performance by scanning only critical paths |
| 59 | + |
| 60 | +## Implementation Methods |
| 61 | + |
| 62 | +### Method 1: Continuous Scanning |
| 63 | + |
| 64 | +Enable continuous accessibility scanning throughout the entire test suite by adding the `accessibility` capability to the test configuration. |
| 65 | + |
| 66 | +#### Configuration |
| 67 | + |
| 68 | +```python |
| 69 | +"accessibility": true |
| 70 | +``` |
| 71 | + |
| 72 | +**Use Case:** Ideal when comprehensive accessibility testing is required across the entire functional test suite without selective scanning. |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +### Method 2: Runtime Control with Lambda Hook |
| 77 | + |
| 78 | +The Lambda Hook provides programmatic control over accessibility scanning during test execution. This method provides fine-grained control, allowing developers to enable or disable scanning for specific test scenarios or application sections. |
| 79 | + |
| 80 | +**Use Case:** Ideal for testing specific user flows, critical paths, or high-priority features where targeted accessibility analysis is needed without scanning the entire application. This approach optimizes test performance and provides granular control over scan coverage. |
| 81 | + |
| 82 | + |
| 83 | +### Selenium Implementation |
| 84 | + |
| 85 | +#### Syntax |
| 86 | + |
| 87 | +<Tabs className="docs__val"> |
| 88 | +<TabItem value="python" label="Python" default> |
| 89 | +<div className="lambdatest__codeblock"> |
| 90 | +<CodeBlock className="language-python"> |
| 91 | +{`driver.execute_script('lambda-executor: { |
| 92 | + "action": "lambda-accessibility-scan", |
| 93 | + "arguments": { |
| 94 | + "scan": "true" # or "false" to disable |
| 95 | + } |
| 96 | +}')`} |
| 97 | +</CodeBlock> |
| 98 | +</div> |
| 99 | +</TabItem> |
| 100 | + |
| 101 | +<TabItem value="java" label="Java"> |
| 102 | +<div className="lambdatest__codeblock"> |
| 103 | +<CodeBlock className="language-java"> |
| 104 | +{`driver.executeScript("lambda-executor: {" + |
| 105 | + "\\"action\\": \\"lambda-accessibility-scan\\"," + |
| 106 | + "\\"arguments\\": { \\"scan\\": \\"true\\" }" + // or "false" to disable |
| 107 | +"}");`} |
| 108 | +</CodeBlock> |
| 109 | +</div> |
| 110 | +</TabItem> |
| 111 | + |
| 112 | +<TabItem value="javascript" label="JavaScript"> |
| 113 | +<div className="lambdatest__codeblock"> |
| 114 | +<CodeBlock className="language-javascript"> |
| 115 | +{`await driver.executeScript('lambda-executor: { |
| 116 | + "action": "lambda-accessibility-scan", |
| 117 | + "arguments": { |
| 118 | + "scan": "true" // or "false" to disable |
| 119 | + } |
| 120 | +}');`} |
| 121 | +</CodeBlock> |
| 122 | +</div> |
| 123 | +</TabItem> |
| 124 | + |
| 125 | +<TabItem value="csharp" label="C#"> |
| 126 | +<div className="lambdatest__codeblock"> |
| 127 | +<CodeBlock className="language-csharp"> |
| 128 | +{`driver.ExecuteScript("lambda-executor: {" + |
| 129 | + "\\\\"action\\\\": \\\\"lambda-accessibility-scan\\\\"," + |
| 130 | + "\\\\"arguments\\\\": { \\\\"scan\\\\": \\\\"true\\\\" }" + // or "false" to disable |
| 131 | +"}");`} |
| 132 | +</CodeBlock> |
| 133 | +</div> |
| 134 | +</TabItem> |
| 135 | +</Tabs> |
| 136 | + |
| 137 | +#### Code Examples |
| 138 | + |
| 139 | +<Tabs className="docs__val"> |
| 140 | +<TabItem value="python" label="Python" default> |
| 141 | +<div className="lambdatest__codeblock"> |
| 142 | +<CodeBlock className="language-python"> |
| 143 | +{`# Enable accessibility scanning |
| 144 | +driver.execute_script('lambda-executor: { |
| 145 | + "action": "lambda-accessibility-scan", |
| 146 | + "arguments": { "scan": "true" } |
| 147 | +}') |
| 148 | + |
| 149 | +# Test steps |
| 150 | +driver.find_element(By.ID, "checkout").click() |
| 151 | + |
| 152 | +# Disable accessibility scanning |
| 153 | +driver.execute_script('lambda-executor: { |
| 154 | + "action": "lambda-accessibility-scan", |
| 155 | + "arguments": { "scan": "false" } |
| 156 | +}')`} |
| 157 | +</CodeBlock> |
| 158 | +</div> |
| 159 | +</TabItem> |
| 160 | + |
| 161 | +<TabItem value="java" label="Java"> |
| 162 | +<div className="lambdatest__codeblock"> |
| 163 | +<CodeBlock className="language-java"> |
| 164 | +{`// Enable accessibility scanning |
| 165 | +driver.executeScript("lambda-executor: {" + |
| 166 | + "\\"action\\": \\"lambda-accessibility-scan\\"," + |
| 167 | + "\\"arguments\\": { \\"scan\\": \\"true\\" }" + |
| 168 | +"}"); |
| 169 | + |
| 170 | +// Test steps |
| 171 | +driver.findElement(By.id("checkout")).click(); |
| 172 | + |
| 173 | +// Disable accessibility scanning |
| 174 | +driver.executeScript("lambda-executor: {" + |
| 175 | + "\\"action\\": \\"lambda-accessibility-scan\\"," + |
| 176 | + "\\"arguments\\": { \\"scan\\": \\"false\\" }" + |
| 177 | +"}");`} |
| 178 | +</CodeBlock> |
| 179 | +</div> |
| 180 | +</TabItem> |
| 181 | + |
| 182 | +<TabItem value="javascript" label="JavaScript"> |
| 183 | +<div className="lambdatest__codeblock"> |
| 184 | +<CodeBlock className="language-javascript"> |
| 185 | +{`// Enable accessibility scanning |
| 186 | +await driver.executeScript('lambda-executor: { |
| 187 | + "action": "lambda-accessibility-scan", |
| 188 | + "arguments": { "scan": "true" } |
| 189 | +}'); |
| 190 | + |
| 191 | +// Test steps |
| 192 | +await driver.findElement(By.id("checkout")).click(); |
| 193 | + |
| 194 | +// Disable accessibility scanning |
| 195 | +await driver.executeScript('lambda-executor: { |
| 196 | + "action": "lambda-accessibility-scan", |
| 197 | + "arguments": { "scan": "false" } |
| 198 | +}');`} |
| 199 | +</CodeBlock> |
| 200 | +</div> |
| 201 | +</TabItem> |
| 202 | + |
| 203 | +<TabItem value="csharp" label="C#"> |
| 204 | +<div className="lambdatest__codeblock"> |
| 205 | +<CodeBlock className="language-csharp"> |
| 206 | +{`// Enable accessibility scanning |
| 207 | +driver.ExecuteScript("lambda-executor: {" + |
| 208 | + "\\\\"action\\\\": \\\\"lambda-accessibility-scan\\\\"," + |
| 209 | + "\\\\"arguments\\\\": { \\\\"scan\\\\": \\\\"true\\\\" }" + |
| 210 | +"}"); |
| 211 | + |
| 212 | +// Test steps |
| 213 | +driver.FindElement(By.Id("checkout")).Click(); |
| 214 | + |
| 215 | +// Disable accessibility scanning |
| 216 | +driver.ExecuteScript("lambda-executor: {" + |
| 217 | + "\\\\"action\\\\": \\\\"lambda-accessibility-scan\\\\"," + |
| 218 | + "\\\\"arguments\\\\": { \\\\"scan\\\\": \\\\"false\\\\" }" + |
| 219 | +"}");`} |
| 220 | +</CodeBlock> |
| 221 | +</div> |
| 222 | +</TabItem> |
| 223 | +</Tabs> |
| 224 | + |
| 225 | +--- |
| 226 | + |
| 227 | +### Playwright Implementation |
| 228 | + |
| 229 | +#### Syntax |
| 230 | + |
| 231 | +<Tabs className="docs__val"> |
| 232 | +<TabItem value="javascript" label="JavaScript/TypeScript" default> |
| 233 | +<div className="lambdatest__codeblock"> |
| 234 | +<CodeBlock className="language-javascript"> |
| 235 | +{`await page.evaluate( |
| 236 | + (hook) => null, |
| 237 | + \`lambdatest_action:\${JSON.stringify({ |
| 238 | + action: "lambda-accessibility-scan", |
| 239 | + arguments: { scan: "true" } // or "false" to disable |
| 240 | + })}\` |
| 241 | +);`} |
| 242 | +</CodeBlock> |
| 243 | +</div> |
| 244 | +</TabItem> |
| 245 | + |
| 246 | +<TabItem value="python" label="Python"> |
| 247 | +<div className="lambdatest__codeblock"> |
| 248 | +<CodeBlock className="language-python"> |
| 249 | +{`await page.evaluate( |
| 250 | + f'lambdatest_action:{json.dumps({ |
| 251 | + "action": "lambda-accessibility-scan", |
| 252 | + "arguments": {"scan": "true"} # or "false" to disable |
| 253 | + })}' |
| 254 | +)`} |
| 255 | +</CodeBlock> |
| 256 | +</div> |
| 257 | +</TabItem> |
| 258 | +</Tabs> |
| 259 | + |
| 260 | +#### Code Examples |
| 261 | + |
| 262 | +<Tabs className="docs__val"> |
| 263 | +<TabItem value="javascript" label="JavaScript/TypeScript" default> |
| 264 | +<div className="lambdatest__codeblock"> |
| 265 | +<CodeBlock className="language-javascript"> |
| 266 | +{`// Enable accessibility scanning |
| 267 | +await page.evaluate( |
| 268 | + (hook) => null, |
| 269 | + \`lambdatest_action:\${JSON.stringify({ |
| 270 | + action: "lambda-accessibility-scan", |
| 271 | + arguments: { scan: "true" } |
| 272 | + })}\` |
| 273 | +); |
| 274 | + |
| 275 | +// Test steps |
| 276 | +await page.click('#checkout'); |
| 277 | + |
| 278 | +// Disable accessibility scanning |
| 279 | +await page.evaluate( |
| 280 | + (hook) => null, |
| 281 | + \`lambdatest_action:\${JSON.stringify({ |
| 282 | + action: "lambda-accessibility-scan", |
| 283 | + arguments: { scan: "false" } |
| 284 | + })}\` |
| 285 | +);`} |
| 286 | +</CodeBlock> |
| 287 | +</div> |
| 288 | +</TabItem> |
| 289 | + |
| 290 | +<TabItem value="python" label="Python"> |
| 291 | +<div className="lambdatest__codeblock"> |
| 292 | +<CodeBlock className="language-python"> |
| 293 | +{`# Enable accessibility scanning |
| 294 | +await page.evaluate( |
| 295 | + f'lambdatest_action:{json.dumps({ |
| 296 | + "action": "lambda-accessibility-scan", |
| 297 | + "arguments": {"scan": "true"} |
| 298 | + })}' |
| 299 | +) |
| 300 | + |
| 301 | +# Test steps |
| 302 | +await page.click('#checkout') |
| 303 | + |
| 304 | +# Disable accessibility scanning |
| 305 | +await page.evaluate( |
| 306 | + f'lambdatest_action:{json.dumps({ |
| 307 | + "action": "lambda-accessibility-scan", |
| 308 | + "arguments": {"scan": "false"} |
| 309 | + })}' |
| 310 | +)`} |
| 311 | +</CodeBlock> |
| 312 | +</div> |
| 313 | +</TabItem> |
| 314 | +</Tabs> |
| 315 | + |
| 316 | +--- |
| 317 | + |
| 318 | +## Important Notes |
| 319 | + |
| 320 | +### Scan Scope |
| 321 | + |
| 322 | +When using runtime control, only the application states and pages traversed **between enabling (`scan: "true"`) and disabling (`scan: "false"`)** the scan will be analyzed for accessibility issues. All navigation and interactions outside this range will be excluded from accessibility analysis. |
| 323 | + |
| 324 | +Both implementation methods can coexist in the testing infrastructure. The approach that best fits the testing requirements can be chosen on a per-suite or per-test basis. |
| 325 | + |
| 326 | +### Framework Support |
| 327 | + |
| 328 | +Runtime control via Lambda Hook is currently supported for **Selenium** and **Playwright** frameworks across all supported programming languages. |
| 329 | + |
| 330 | +### Reporting |
| 331 | + |
| 332 | +Accessibility scan results are accessible through the LambdaTest dashboard. The reporting interface and data structure remain consistent regardless of whether continuous scanning or runtime control is used. |
| 333 | + |
| 334 | +--- |
| 335 | + |
| 336 | + |
| 337 | +:::info |
| 338 | +For comprehensive accessibility reports and detailed issue breakdowns, visit the [LambdaTest Accessibility Dashboard](https://accessibility.lambdatest.com/automation). |
| 339 | +::: |
0 commit comments