|
| 1 | +--- |
| 2 | +id: extended-debugging-options |
| 3 | +title: Extended Debugging Options for Selenium Testing |
| 4 | +hide_title: false |
| 5 | +sidebar_label: Extended Debugging Options |
| 6 | +description: Learn how to use Extended Debugging Options on LambdaTest to intercept network requests, throttle CPU and network conditions, and download HAR files for advanced test debugging and performance analysis. |
| 7 | +keywords: |
| 8 | +- extended debugging options |
| 9 | +- selenium debugging |
| 10 | +- intercept network requests |
| 11 | +- throttle cpu selenium |
| 12 | +- throttle network selenium |
| 13 | +- har file download |
| 14 | +url: https://www.lambdatest.com/support/docs/extended-debugging-options/ |
| 15 | +site_name: LambdaTest |
| 16 | +slug: extended-debugging-options/ |
| 17 | +--- |
| 18 | + |
| 19 | +LambdaTest's Extended Debugging Options provide powerful capabilities to debug and optimize your Selenium tests by giving you granular control over network behavior and system performance. These advanced debugging features allow you to intercept and modify network requests, simulate various CPU and network conditions, and download comprehensive network analysis files—all within your test automation workflow. |
| 20 | + |
| 21 | +With Extended Debugging Options, you can replicate real-world scenarios such as slow networks, resource-constrained devices, API failures, and connectivity issues, ensuring your application delivers a robust user experience across diverse conditions and environments. |
| 22 | + |
| 23 | +## How can Extended Debugging Options help you? |
| 24 | + |
| 25 | +Extended Debugging Options on LambdaTest provide comprehensive capabilities for advanced testing and debugging scenarios: |
| 26 | + |
| 27 | +- **Network Request Control**: Intercept and modify outgoing requests to test API failures, redirects, and mock responses without setting up complex backend infrastructure. |
| 28 | +- **Performance Testing**: Simulate various CPU and network throttling conditions to understand how your application performs on low-end devices or poor network connections. |
| 29 | +- **Network Analysis**: Download HAR (HTTP Archive) files to perform detailed analysis of network traffic, load times, and resource optimization. |
| 30 | +- **Realistic Test Scenarios**: Create test conditions that mirror real-world user experiences, including offline modes, slow connections, and server errors. |
| 31 | + |
| 32 | +## Available Extended Debugging Methods |
| 33 | + |
| 34 | +LambdaTest supports the following extended debugging methods: |
| 35 | + |
| 36 | +| Method | Description | |
| 37 | +|--------|-------------| |
| 38 | +| `lt:intercept:redirect` | Redirect network requests to different URLs | |
| 39 | +| `lt:intercept:response` | Mock responses for intercepted requests | |
| 40 | +| `lt:intercept:error` | Simulate error responses for requests | |
| 41 | +| `lt:throttle:cpu` | Simulate different CPU performance levels | |
| 42 | +| `lambda-throttle-network` | Configure and simulate network conditions | |
| 43 | +| `lt:downloadHAR` | Download HTTP Archive files for analysis | |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## 1. Intercept Network Requests |
| 48 | + |
| 49 | +LambdaTest provides three specialized methods to intercept and modify network requests, enabling you to test how your application behaves under different network conditions, mock API responses, and simulate error scenarios. |
| 50 | + |
| 51 | +### Method 1: Redirect Requests (`lt:intercept:redirect`) |
| 52 | + |
| 53 | +Redirect outgoing requests to a different URL using the `lt:intercept:redirect` command. |
| 54 | + |
| 55 | +#### Parameters |
| 56 | + |
| 57 | +| Parameter | Type | Required | Description | |
| 58 | +|-----------|------|----------|-------------| |
| 59 | +| `url` | String | Yes | URL pattern to intercept. | |
| 60 | +| `redirectUrl` | String | Yes | Target URL to redirect the request to. | |
| 61 | + |
| 62 | +#### Example Usage |
| 63 | + |
| 64 | +**Python:** |
| 65 | +```python |
| 66 | +driver.execute_script("lt:intercept:redirect", { |
| 67 | + "url": "https://www.google.com", |
| 68 | + "redirectUrl": "https://www.bing.com" |
| 69 | +}) |
| 70 | +driver.get("https://www.google.com") |
| 71 | +``` |
| 72 | + |
| 73 | +**Node.js:** |
| 74 | +```javascript |
| 75 | +await driver.executeScript("lt:intercept:redirect", { |
| 76 | + url: "https://www.google.com", |
| 77 | + redirectUrl: "https://www.bing.com" |
| 78 | +}); |
| 79 | +await driver.get("https://www.google.com"); |
| 80 | +``` |
| 81 | + |
| 82 | +**Response:** |
| 83 | +```json |
| 84 | +{ |
| 85 | + "status": "success", |
| 86 | + "message": "Requests to 'https://www.google.com' will be redirected to 'https://www.bing.com'" |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +### Method 2: Mock Response (`lt:intercept:response`) |
| 93 | + |
| 94 | +Mock a custom response for the intercepted URL using the `lt:intercept:response` command. |
| 95 | + |
| 96 | +#### Parameters |
| 97 | + |
| 98 | +| Parameter | Type | Required | Description | |
| 99 | +|-----------|------|----------|-------------| |
| 100 | +| `url` | String | Yes | URL pattern to intercept. | |
| 101 | +| `response` | Object | Yes | Response object containing status, headers, and body. | |
| 102 | +| `response.status` | Integer | No | HTTP status code (default: 200). | |
| 103 | +| `response.headers` | Object | No | Custom response headers as key-value pairs. | |
| 104 | +| `response.body` | String | No | Response body content (use JSON string for JSON responses). | |
| 105 | + |
| 106 | +#### Example Usage |
| 107 | + |
| 108 | +**Python:** |
| 109 | +```python |
| 110 | +driver.execute_script("lt:intercept:response", { |
| 111 | + "url": "https://www.amazon.com", |
| 112 | + "response": { |
| 113 | + "status": 200, |
| 114 | + "headers": { |
| 115 | + "Content-Type": "application/json", |
| 116 | + "keyheader": "valueheader" |
| 117 | + }, |
| 118 | + "body": "{\"keybody\":\"valuebody\"}" |
| 119 | + } |
| 120 | +}) |
| 121 | +driver.get("https://www.amazon.com") |
| 122 | +``` |
| 123 | + |
| 124 | +**Node.js:** |
| 125 | +```javascript |
| 126 | +await driver.executeScript("lt:intercept:response", { |
| 127 | + url: "https://jsonplaceholder.typicode.com/todos/1", |
| 128 | + response: { |
| 129 | + status: 200, |
| 130 | + headers: { |
| 131 | + "Content-Type": "application/json" |
| 132 | + }, |
| 133 | + body: JSON.stringify({ |
| 134 | + id: 999, |
| 135 | + title: "Custom mocked response", |
| 136 | + completed: true |
| 137 | + }) |
| 138 | + } |
| 139 | +}); |
| 140 | +await driver.get("https://jsonplaceholder.typicode.com/todos/1"); |
| 141 | +``` |
| 142 | + |
| 143 | +**Response:** |
| 144 | +```json |
| 145 | +{ |
| 146 | + "status": "success", |
| 147 | + "message": "Mock response configured for the specified URL" |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +### Method 3: Simulate Error Response (`lt:intercept:error`) |
| 154 | + |
| 155 | +Inject error responses to test how your application handles failures using the `lt:intercept:error` command. |
| 156 | + |
| 157 | +#### Parameters |
| 158 | + |
| 159 | +| Parameter | Type | Required | Description | |
| 160 | +|-----------|------|----------|-------------| |
| 161 | +| `url` | String | Yes | URL pattern to intercept. | |
| 162 | +| `error` | String | Yes | Error type to simulate. See supported error types below. | |
| 163 | + |
| 164 | +#### Example Usage |
| 165 | + |
| 166 | +**Python:** |
| 167 | +```python |
| 168 | +driver.execute_script("lt:intercept:error", { |
| 169 | + "url": "https://www.lambdatest.com", |
| 170 | + "error": "TimedOut" |
| 171 | +}) |
| 172 | +driver.get("https://www.lambdatest.com") |
| 173 | +``` |
| 174 | + |
| 175 | +**Node.js:** |
| 176 | +```javascript |
| 177 | +await driver.executeScript("lt:intercept:error", { |
| 178 | + url: "https://example.com/images/*", |
| 179 | + error: "Failed" |
| 180 | +}); |
| 181 | +await driver.get("https://example.com/images/photo.jpg"); |
| 182 | +``` |
| 183 | + |
| 184 | +**Response:** |
| 185 | +```json |
| 186 | +{ |
| 187 | + "status": "success", |
| 188 | + "message": "Error 'TimedOut' configured for the specified URL" |
| 189 | +} |
| 190 | +``` |
| 191 | + |
| 192 | +#### Supported Error Types |
| 193 | + |
| 194 | +| Error Type | Description | |
| 195 | +|------------|-------------| |
| 196 | +| `Failed` | Generic network failure | |
| 197 | +| `Aborted` | Request was aborted | |
| 198 | +| `TimedOut` | Request timed out | |
| 199 | +| `AccessDenied` | Access to resource denied | |
| 200 | +| `ConnectionClosed` | Connection closed unexpectedly | |
| 201 | +| `ConnectionReset` | Connection reset by peer | |
| 202 | +| `ConnectionRefused` | Connection refused by server | |
| 203 | +| `ConnectionAborted` | Connection aborted | |
| 204 | +| `ConnectionFailed` | Connection failed to establish | |
| 205 | +| `NameNotResolved` | DNS name resolution failed | |
| 206 | +| `InternetDisconnected` | Internet connection lost | |
| 207 | +| `AddressUnreachable` | Network address unreachable | |
| 208 | + |
| 209 | +--- |
| 210 | + |
| 211 | +## 2. Throttle CPU Performance |
| 212 | + |
| 213 | +The `lt:throttle:cpu` method simulates lower or higher CPU usage on the testing device, allowing you to measure your application's performance under resource constraints. |
| 214 | + |
| 215 | +### Parameters |
| 216 | + |
| 217 | +| Parameter | Type | Required | Description | |
| 218 | +|-----------|------|----------|-------------| |
| 219 | +| `rate` | Integer | Yes | Rate of slowdown. Example: `2` equals 2x slowdown, `4` equals 4x slowdown. | |
| 220 | + |
| 221 | +### Example Usage |
| 222 | + |
| 223 | +**Python:** |
| 224 | +```python |
| 225 | +driver.execute_script("lt:throttle:cpu", {"rate": 4}) |
| 226 | +driver.get("https://lambdatest.com") |
| 227 | +``` |
| 228 | + |
| 229 | +**Node.js:** |
| 230 | +```javascript |
| 231 | +await driver.executeScript("lt:throttle:cpu", { rate: 4 }); |
| 232 | +await driver.get("https://www.wikipedia.org"); |
| 233 | +``` |
| 234 | + |
| 235 | +**Response:** |
| 236 | +```json |
| 237 | +{ |
| 238 | + "status": "success", |
| 239 | + "message": "CPU throttled to 4x slowdown." |
| 240 | +} |
| 241 | +``` |
| 242 | + |
| 243 | +:::info CPU Throttling Rates |
| 244 | +- A rate of `1` means no throttling (normal CPU performance) |
| 245 | +- A rate of `2` means 2x slower than normal |
| 246 | +- A rate of `4` means 4x slower than normal |
| 247 | +- Higher values simulate lower-end devices or heavy CPU load scenarios |
| 248 | +::: |
| 249 | + |
| 250 | +--- |
| 251 | + |
| 252 | +## 3. Throttle Network Conditions |
| 253 | + |
| 254 | +The `lambda-throttle-network` method enables you to simulate various network conditions including slower speeds, high latency, and offline modes. This helps ensure your application performs well across different connection types. |
| 255 | + |
| 256 | +### Parameters |
| 257 | + |
| 258 | +| Parameter | Type | Required | Description | |
| 259 | +|-----------|------|----------|-------------| |
| 260 | +| `download` | Integer | Conditional | Download speed in kb/s (required for custom configuration). | |
| 261 | +| `upload` | Integer | Conditional | Upload speed in kb/s (required for custom configuration). | |
| 262 | +| `latency` | Integer | Conditional | Round Trip Time (RTT) in milliseconds (required for custom configuration). | |
| 263 | + |
| 264 | +Alternatively, you can pass a predefined network profile name as a string (e.g., `"Regular 3G"`, `"Offline"`). |
| 265 | + |
| 266 | +### Custom Network Configuration |
| 267 | + |
| 268 | +**Python:** |
| 269 | +```python |
| 270 | +driver.execute_script("lambda-throttle-network", { |
| 271 | + "download": 1000, |
| 272 | + "upload": 750, |
| 273 | + "latency": 20 |
| 274 | +}) |
| 275 | +driver.get("https://lambdatest.com") |
| 276 | +``` |
| 277 | + |
| 278 | +**Node.js:** |
| 279 | +```javascript |
| 280 | +await driver.executeScript("lambda-throttle-network", { |
| 281 | + download: 1000, |
| 282 | + upload: 500, |
| 283 | + latency: 40 |
| 284 | +}); |
| 285 | +await driver.get("https://www.cnn.com"); |
| 286 | +``` |
| 287 | + |
| 288 | +**Response:** |
| 289 | +```json |
| 290 | +{ |
| 291 | + "status": "success", |
| 292 | + "message": "Network conditions set with 1000 kb/s download, 750 kb/s upload, and 20 ms latency." |
| 293 | +} |
| 294 | +``` |
| 295 | + |
| 296 | +### Using Predefined Network Profiles |
| 297 | + |
| 298 | +**Python:** |
| 299 | +```python |
| 300 | +driver.execute_script("lambda-throttle-network", "Offline") |
| 301 | +driver.get("https://lambdatest.com") |
| 302 | +``` |
| 303 | + |
| 304 | +**Node.js:** |
| 305 | +```javascript |
| 306 | +await driver.executeScript("lambda-throttle-network", "Regular 3G"); |
| 307 | +await driver.get("https://www.nytimes.com"); |
| 308 | +``` |
| 309 | + |
| 310 | +### Predefined Network Profiles |
| 311 | + |
| 312 | +LambdaTest provides predefined network profiles for quick testing across common connection types: |
| 313 | + |
| 314 | +| Profile | Download Speed | Upload Speed | Latency (ms) | |
| 315 | +|---------|----------------|--------------|--------------| |
| 316 | +| `offline` | 0 kb/s | 0 kb/s | 0 | |
| 317 | +| `GPRS` | 50 kb/s | 20 kb/s | 500 | |
| 318 | +| `Regular 2G` | 250 kb/s | 50 kb/s | 300 | |
| 319 | +| `Good 2G` | 450 kb/s | 150 kb/s | 150 | |
| 320 | +| `Regular 3G` | 750 kb/s | 250 kb/s | 100 | |
| 321 | +| `Good 3G` | 1 Mb/s | 750 kb/s | 40 | |
| 322 | +| `Regular 4G` | 4 Mb/s | 3 Mb/s | 20 | |
| 323 | +| `DSL` | 2 Mb/s | 1 Mb/s | 5 | |
| 324 | +| `WiFi` | 30 Mb/s | 15 Mb/s | 2 | |
| 325 | +| `online` | No Restrictions | No Restrictions | No Restrictions | |
| 326 | + |
| 327 | +--- |
| 328 | + |
| 329 | +--- |
| 330 | + |
| 331 | +## 4. Download HAR File |
| 332 | + |
| 333 | +The `lt:downloadHAR` method downloads network activity data in HAR (HTTP Archive) format, enabling detailed analysis of network performance, resource loading times, and HTTP transactions. |
| 334 | + |
| 335 | +### Parameters |
| 336 | + |
| 337 | +| Parameter | Type | Required | Description | |
| 338 | +|-----------|------|----------|-------------| |
| 339 | +| `job_id` | String | Yes | Unique job identifier for the test session. | |
| 340 | +| `output_file` | String | Yes | Filename to save the HAR file. | |
| 341 | + |
| 342 | +### Example Usage |
| 343 | + |
| 344 | +**Python:** |
| 345 | +```python |
| 346 | +driver.execute_script("lt:downloadHAR", { |
| 347 | + "job_id": "123456", |
| 348 | + "output_file": "network.har" |
| 349 | +}) |
| 350 | +``` |
| 351 | + |
| 352 | +**Node.js:** |
| 353 | +```javascript |
| 354 | +await driver.executeScript("lt:downloadHAR", { |
| 355 | + job_id: "123456", |
| 356 | + output_file: "network.har" |
| 357 | +}); |
| 358 | +``` |
| 359 | + |
| 360 | +**Response:** |
| 361 | +```json |
| 362 | +{ |
| 363 | + "status": "success", |
| 364 | + "message": "HAR file downloaded as 'network.har'." |
| 365 | +} |
| 366 | +``` |
| 367 | + |
| 368 | +:::info HAR File Analysis |
| 369 | +HAR files can be analyzed using tools like: |
| 370 | +- Chrome DevTools (Network tab → right-click → "Save all as HAR") |
| 371 | +- Online HAR analyzers |
| 372 | +- Performance monitoring tools |
| 373 | + |
| 374 | +These files contain detailed information about request/response headers, timing data, cookies, and more. |
| 375 | +::: |
| 376 | + |
| 377 | +--- |
| 378 | + |
| 379 | +## Best Practices |
| 380 | + |
| 381 | +When using Extended Debugging Options on LambdaTest, consider the following best practices: |
| 382 | + |
| 383 | +- **Use Wildcards Wisely**: When intercepting requests, use specific URL patterns to avoid unintended interceptions. |
| 384 | +- **Test Incrementally**: Start with mild throttling conditions and gradually increase constraints to identify performance breaking points. |
| 385 | +- **Combine Methods**: Use multiple methods together (e.g., network throttling + CPU throttling) to simulate realistic low-end device scenarios. |
| 386 | +- **Analyze HAR Files**: Download HAR files for failed tests to identify network-related issues and performance bottlenecks. |
| 387 | + |
| 388 | +By leveraging these Extended Debugging Options, you can create comprehensive test scenarios that validate your application's behavior under diverse real-world conditions, ensuring a robust and reliable user experience. |
0 commit comments