The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

 

Extended Debugging Required

This feature is only available for customers that are executing their tests on Chrome with Extended Debugging enabled. Click here to learn more

Custom Commands are in beta.

The feature is currently in beta and some commands might not work as expected. Please at your own risk.

As part of our effort to help our customers improve the quality and coverage of their tests, we have released a series new custom commads. 

Intercepting Network Requests

Allows modifying any request made by the browser. The customer can blacklist, modify or redirect these for testing needs.

Usecases 

  • Blacklist requests to 3rd party vendors
  • Modify requests to REST API (Mock REST API response)
  • Redirect certail parts of the app 
  • Insert/change headers
JavaScript ExecutorSample
sauce:throttle
Python example
driver.execute_script('sauce:intercept', {
    "url": "https://saucelabs.com",
    "redirect": "https://browserstack.com"
})
  • Request Parameters

    • url: string that matches outgoing request url, wildcards are supported, e.g. https://saucelabs.com/rest/v1/* would match all v1 rest API requests
    • redirect | respond: action on request
      • redirect: string representing an absolute url that the original request gets redirected to
      • respond:object containing:
      • statusCode: number representing the request status
        headers: list of key/value pairs that is set as header variables
        rawResponse: actual response payload as string

Example

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

Throttle Network Capabilities

MethodPath TemplateJavaScript Executor
POST/session/{session id}/sauce/ondemand/throttlesauce:throttle

Network conditioning allows the customer to test his site on a variety of network connections, including Edge, 3G, and even offline. It throttles the maximum download and upload throughput (rate of data transfer). Latency manipulation enforces a minimum delay in connection round-trip time (RTT).

  • URL Variables
    • session id
  • Request Parameters
    • condition: can be a string or object representing the network condition of the browser
      • if a string is detected: the customer is choosing one of the predefined profiles, e.g.



        where the columns in this order specify the profile name, download speed in kb/s, upload speed in kb/s and delay in connection round-trip time (RTT)
      • if an object is detected: the customer is defining a custom profile, the object requires to be the following format:
        • upload
        • download
        • latency
  • Response Value
    • null
  • Example

    Python example
    driver.execute_script('sauce:throttle', {
    	"condition": "GPRS"
    })
    # or
    driver.execute_script('sauce:throttle', {
    	"condition": {
    		"download": 1000,
    		"upload": 500,
    		"latency": 40
        }
    })

Network Timing

MethodPath Template
POST/session/{session id}/log

By using a custom sauce log type called "timing" a user can receive page metrics on network timings defined by the PerformanceTiming. All timings are relative to "navigationStart" for simplification purposes (absolute timings as described in the API are useless for the cusomer for testing purposes).

  • URL Variables
    • session id
  • Request Parameters
    • type: string - value has to be "sauce:timing"
  • Response Value
    • Object with the format of the following sample response:

      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

MethodPath Template
POST/session/{session id}/log

By using a custom sauce log type called "metrics" a user can receive application related metrics. All timings metrics are similar to the timings log relative to the page load time.

  • URL Variables
    • session id
  • Request Parameters
    • type: string - value has to be "sauce:metrics"
  • Response Value
    • Object with the format of the following sample response:

      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
      }

 

  • No labels