To enable networking capabilities for tests and generate custom log files, use these Sauce Labs options for the Selenium JavaScript Executor and our extended debugging features. You can find more examples of this feature written in Node.js, Python, and Java on GitHub.
What You'll Need
- Google Chrome (no older than 3 versions from latest) as the test browser
- Enabled
extendedDebugging
capability in your test config
const sauceOptions = { 'sauce:options': { extendedDebugging: true, } }
See the following sections for more information:
Test Environment Tools
Test Environment Tools simulate network conditions and manipulate network requests to analyze and improve test performance.
Intercept Network Requests
Allows modification of requests made by the browser. You can alter these as your tests require:
- Prohibit requests to 3rd party vendors
- Modify requests to REST API (Mock REST API response)
- Redirect certain parts of the app
- Insert or change headers
JavaScript Executor Command | Request Parameters | Sample Code |
---|---|---|
|
| driver.execute_script('sauce:intercept', { "url": "https://saucelabs.com", "redirect": "https://google.com" }) WDIO browser.interceptRequest({ "url": "https://saucelabs.com/", "redirect": "https://google.com" }) |
|
| driver.execute_script("sauce:intercept", { "url": "http://sampleapp.appspot.com/api/todos", "response": { "headers": { "x-custom-header": "foobar" }, "body": [{ "title": "Hello", "order": 1, "completed": false, "url": "http://todo-backend-express.herokuapp.com/15727" }] } }) WDIO browser.interceptRequest({ "url": "http://sampleapp.appspot.com/api/todos", "response": { "headers": { "x-custom-header": "foobar" }, "body": [{ "title": "Hello", "order": 1, "completed": false, "url": "http://todo-backend-express.herokuapp.com/15727" }] } }) |
sauce:intercept+ error |
| driver.execute_script("sauce:intercept", { "url": "https://saucecon.com/wp-content/uploads/2017/07/SauceCon-hero-img-100-2.jpg", error: "Failed"} WDIO browser.interceptRequest({ "url": "https://saucecon.com/wp-content/uploads/2017/07/SauceCon-hero-img-100-2.jpg", error: "Failed"}) |
Throttle CPU Capabilities
Mobile devices have less CPU power than most desktops and laptops (or a VM's default configuration). You can use CPU Throttling to simulate how your app will run on slower systems, helping you identify possible performance issues.
JavaScript Executor Command | Request Parameters | Examples |
---|---|---|
sauce:throttleCPU |
| driver.execute_script('sauce:throttleCPU', { browser.throttleCPU(4) |
Throttle Network Capabilities
With network conditioning you can test your site on a variety of network connections, including Edge, 3G, and even offline. You can throttle the data throughput, including the maximum download and upload throughput, and use latency manipulation to enforce a minimum delay in connection round-trip time (RTT).
JavaScript Executor Command | Request Parameters | Examples |
---|---|---|
sauce:throttleNetwork |
| driver.execute_script('sauce:throttleNetwork', { browser.throttleNetwork("GPRS") |
Strings
Profile Name | Download Speed (kb/s) | Upload Speed (kb/s) | Round Trip Time (ms) |
---|---|---|---|
offline | 0 | 0 | 0 |
GPRS | 50 | 20 | 500 |
Regular 2G | 250 | 50 | 300 |
Good 2G | 450 | 150 | 150 |
Regular 3G | 750 | 250 | 100 |
Good 3G | 1Mb/s | 750 | 40 |
Regular 4G | 4Mb/s | 3Mb/s | 20ms |
DSL | 2Mb/s | 1Mb/s | 5ms |
Wifi | 30Mb/s | 15Mb/s | 2ms |
online | No Restrictions | No Restrictions | No Restrictions |
Custom objects
You can create custom network conditions with objects. You must define the download speed (in bytes/second), upload speed (in bytes/second), and latency (in milliseconds) for the custom condition, as shown in the example.
Extended Debugging Tools
Extended Debugging Tools provide additional logs to analyze test results.
See Measure Page Load Performance Using Test Automation for information about performance logging tools.
Network Log
The Sauce Labs network log records all network requests being made by the page currently open in the browser. To retrieve the network log output, use:
driver.execute('sauce:log', { type: 'sauce:network' }):
Log Type | Response |
---|---|
sauce:network | Sample response [{ "url": "http://saucelabs.com/beta/dashboard", "statusCode": 200, "method": "GET", "requestHeaders": { ... }, "responseHeaders": { ... }, "timing": { "blocked": -1, "connect": -1, "dns": -1, "receive": 0, "send": 0, "ssl": -1, "wait": 0 } }, { ... }] |