Skip to end of metadata
Go to start of metadata

You can use these custom Sauce Labs options with the Selenium JavaScript Executor, in conjunction with the Extended debugging feature, to control networking capabilities for your tests, and to generate custom logs for extended debugging.

Extended Debugging Required

You must have Extended Debugging enabled and run your tests on Chrome browsers to use these commands.

For Chrome Only

This feature is only available for testing on Chrome browsers versions 62 and above.

Demo examples

You can find more examples of this feature written in Node.js, Python, and Java at https://github.com/saucelabs/extended_debugging_demo

Test Environment Tools

The Test Environment Tools let you simulate network conditions and manipulate network requests to understand and improve the performance of your tests. 

Intercept Network Requests

Allows modifying any request made by the browser. You can blacklist, modify, or redirect these as required for your tests. For example, you can:

  • Blacklist requests to 3rd party vendors
  • Modify requests to REST API (Mock REST API response)
  • Redirect certain parts of the app 
  • Insert/change headers
JavaScript Executor CommandRequest ParametersSample Code

sauce:intercept + redirect

url: a string that matches an outgoing request URL. Wildcards are supported, for example https://saucelabs.com/rest/v1/* would match all v1 rest API requests.

redirect is a string representing an absolute URL where the original request is redirected. In the example, this is "https://google.com"

driver.execute_script('sauce:intercept', {
    "url": "https://saucelabs.com",
    "redirect": "https://google.com"
})

sauce:intercept + response

url: a string that matches an outgoing request URL. Wildcards are supported, for example https://saucelabs.com/rest/v1/* would match all v1 rest API requests.

response: an object that represents the response to send when the requested URL is intercepted. There are three options:

    • statusCode: number representing the request status (200)
    • headers: list of key/value pairs that is set as header variables, for example Cookie: "foo=bar"
    • rawResponse: actual response payload as a string
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"
            }]
        }
    })
sauce:intercept+ error

url: a string that matches an outgoing request URL. Wildcards are supported, for example https://saucelabs.com/rest/v1/* would match all v1 rest API requests.

error: error values are:

  • 'Failed'
  • 'Aborted'
  • 'TimedOut'
  • 'AccessDenied'
  • 'ConnectionClosed'
  • 'ConnectionReset' 
  • 'ConnectionRefused'
  • 'ConnectionAborted'
  • 'ConnectionFailed'
  • 'NameNotResolved'
  • 'InternetDisconnected'
  • 'AddressUnreachable'
driver.execute_script("sauce:intercept", {
	"url": "https://saucecon.com/wp-content/uploads/2017/07/SauceCon-hero-img-100-2.jpg",
    error: "Failed"}


Example

Python example
driver.execute_script('sauce:intercept', {
    "url": "https://saucelabs.com",
    "redirect": "https://google.com"
})
# or
driver.execute_script('sauce:intercept', {
    "url": "https://saucelabs.com/res7/v1/build/32hmv4j32v4j2j3v4j24v232vj4j",
    "response": {
        "statusCode": 200,
        "headers": {
            "etag": 3244224432,
            "Cookie: "foo=bar",
            ...
        },
        "rawResponse": "{\"username\":\"..."
    }
})

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 CommandRequest ParametersExample
sauce:throttle

conditioncan be a string or object representing the network condition of the browser.

string

Strings should correspond to the predefined profile names in this table.

Profile NameDownload Speed (kb/s)Upload Speed (kb/s)Round Trip Time (ms)
offline000
GPRS5020500
Regular 2G25050300
Good 2G450150150
Regular 3G750250100
Good 3G1Mb/s75040
Regular 4G4Mb/s3Mb/s20ms
DSL2Mb/s1Mb/s5ms
WiFi30Mb/s15Mb/s2ms
online
No Restrictions
No Restrictions
No Restrictions
objectWith objects you can create custom network conditions. You must define the download speed, upload speed, and latency for the custom condition, as shown in the example.
driver.execute_script('sauce:throttle', {
	"condition": "GPRS"
})
# or
driver.execute_script('sauce:throttle', {
	"condition": {
		"download": 1000,
		"upload": 500,
		"latency": 40
    }
})

Extended Debugging Tools

The Extended Debugging Tools provide you with additional logs to analyze your test performance. 

Network Timing Log

The Sauce Labs timing log receives page metrics for network timings as defined by the PerformanceTiming property. All timings are relative to navigationStart, since the absolute timings described for the property are not useful for testing purposes.


Log TypeResponse
sauce:timing
Sample response
{
    "navigationStart": 0
    "unloadEventStart": -1
    "unloadEventEnd": -1
    "redirectStart": 0
    "redirectEnd": 312
    "fetchStart": 312
    "domainLookupStart": 312
    "domainLookupEnd": 312
    "connectStart": 312
    "connectEnd": 312
    "secureConnectionStart": -1
    "requestStart": 39
    "responseStart": 309
    "responseEnd": 312
    "domLoading": 316
    "domInteractive": 359
    "domContentLoadedEventStart": 560
    "domContentLoadedEventEnd": 560
    "domComplete": 622
    "loadEventStart": 622
    "loadEventEnd": 622
}

Application Metrics Log

The Sauce Labs metric log receives application-related metrics. As with the timing log, all metrics are relative to the page load time.

Log TypeResponse
sauce:metrics
(Chrome 64 and higher)
Sample response
{
    "timestamp": 35037.202627,
    "audioHandlers": 0,
    "documents": 3,
    "frames": 2,
    "jsEventListeners": 63,
    "layoutObjects": 435,
    "nodes": 506,
    "resources": 11,
    "layoutCount": 2,
    "recalcStyleCount": 5,
    "layoutDuration": 0.0860430000029737,
    "recalcStyleDuration": 0.00374899999587797,
    "scriptDuration": 0.0770069999925909,
    "taskDuration": 0.297364000020025,
    "jsHeapUsedSize": 6295344,
    "jsHeapTotalSize": 10891264,
    "firstMeaningfulPaint": 35036.03356,
    "domContentLoaded": 35036.122972,
    "navigationStart": 35035.833805,
	"pausableObjects": 23,
    "mediaKeySessions": 0,
    "uaCSSResources": 0,
    "scriptPromises": 0,
    "workerGlobalScopes": 1,
    "mediaKeys": 0,
    "v8PerContextDatas": 1
}
sauce:metrics
(on Chrome 63)

The properties are the same as on Chrome 64, but instead of pausableObjects the property is called suspendableObjects.

suspendableObjects property
{
	...
	"suspendableObjects": 23,
	...
}
sauce:metrics
(on Chrome 62)

The properties are named differently when using this command on Chrome 62, as shown in this example response:

Sample Response (Chrome 62)
{
    "timestamp": 75.518,
    "audioHandlerCount": 0,
    "documentCount": 4,
    "frameCount": 2,
    "jsEventListenerCount": 17,
    "layoutObjectCount": 47,
    "nodeCount": 291,
    "resourceCount": 32,
    "layoutCount": 3,
    "recalcStyleCount": 4,
    "layoutDuration": 0.120999999999981,
    "recalcStyleDuration": 0.0130000000000194,
    "scriptDuration": 0.576000000000022,
    "taskDuration": 1.26199999999999,
    "jsHeapUsedSize": 3835180,
    "jsHeapTotalSize": 6995968,
    "firstMeaningfulPaint": 74.729,
    "domContentLoaded": 74.077,
    "navigationStart": 68.32,
    "suspendableObjectCount": 31,
    "mediaKeySessionCount": 0,
    "scriptPromiseCount": 0,
    "workerGlobalScopeCount": 1,
    "mediaKeysCount": 0,
    "v8PerContextDataCount": 1
}

Network Log

The Sauce Labs network log receives comprehensive information on all network requests being made by the page currently open in the browser.

Log TypeResponse
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
    }
}, {
    ...
}]

Performance Log (coming soon)

The Sauce Labs performance log receives performance-related metrics

Log TypeResponse
sauce:performance
Sample response
{  
   "load":992,
   "speedIndex":472.27000000000004,
   "pageWeight":1094729,
   "firstMeaningfulPaint":808,
   "firstPaint":376,
   "timeToFirstByte":16,
   "timeToFirstInteractive":None,
   "firstContentfulPaint":407,
   "perceptualSpeedIndex":691.980326135068,
   "domContentLoaded":352
}

 

 

 

  • No labels