# Sauce Labs

All commands are only supported on Chrome using Sauce Labs [Extended Debugging](https://docs.saucelabs.com/insights/debug/#enabling-extended-debugging) capabilities. You can enable these by setting the following Sauce options:

```
{
    browserName: 'Chrome',
    browserVersion: 'latest',
    platformName: 'Windows 10',
    'sauce:options': {
        extendedDebugging: true
    }
}
```

***

## getPageLogs[​](#getpagelogs "Direct link to getPageLogs")

Get webpage specific log information based on the last page load.<br /><br />Sauce Labs command. More details can be found in the [official protocol docs](https://docs.saucelabs.com/insights/debug/#network-logs).

### Usage[​](#usage "Direct link to Usage")

```
await browser.getPageLogs(type)
```

### Parameters[​](#parameters "Direct link to Parameters")

| Name   | Type     | Details                                                                             |
| ------ | -------- | ----------------------------------------------------------------------------------- |
| `type` | `string` | log type (e.g. sauce<!-- -->:network<!-- -->', 'sauce<!-- -->:performance<!-- -->') |

### Examples[​](#examples "Direct link to Examples")

```
// Get Network Logs
console.log(browser.getPageLogs('sauce:network'));
/**
 * outputs:
 * [{
 *   "url": "https://app.saucelabs.com/dashboard",
 *   "statusCode": 200,
 *   "method": "GET",
 *   "requestHeaders": {
 *     ...
 *   },
 *   "responseHeaders": {
 *     ...
 *   },
 *   "timing": {
 *     ...
 *   }
 * }, {,
 *   ...
 * }]
 */
```

```
// Get Performance Logs (needs capturePerformance capability see: https://docs.saucelabs.com/performance/transitions/#setting-performance-capabilities
console.log(browser.getPageLogs('sauce:performance'));
/**
 * outputs:
 * {
 *   "speedIndex": 1472.023,
 *   "timeToFirstInteractive": 1243.214,
 *   "firstMeaningfulPaint": 892.643,
 *   ...
 * }
 */
```

### Returns[​](#returns "Direct link to Returns")

* **\<object>** **`log`:** log output of desired type (see example)

***

## sauceThrottleNetwork[​](#saucethrottlenetwork "Direct link to sauceThrottleNetwork")

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).<br /><br />Sauce Labs command. More details can be found in the [official protocol docs](https://docs.saucelabs.com/insights/debug/#saucethrottlenetwork).

### Usage[​](#usage-1 "Direct link to Usage")

```
await browser.sauceThrottleNetwork(condition)
```

### Parameters[​](#parameters-1 "Direct link to Parameters")

| Name        | Type             | Details                                                                                                                                    |
| ----------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `condition` | `string, object` | network condition to set (e.g. 'online', 'offline', 'GPRS', 'Regular 2G', 'Good 2G', 'Regular 3G', 'Good 3G', 'Regular 4G', 'DSL', 'Wifi') |

### Examples[​](#examples-1 "Direct link to Examples")

```
// predefined network condition
browser.sauceThrottleNetwork('offline')
```

```
// custom network condition
browser.sauceThrottleNetwork({
  download: 1000,
  upload: 500,
  latency: 40'
})
```

***

## throttleCPU[​](#throttlecpu "Direct link to throttleCPU")

You can throttle the CPU in DevTools to understand how your page performs under that constraint.<br /><br />Sauce Labs command. More details can be found in the [official protocol docs](https://docs.saucelabs.com/insights/debug/#saucethrottlecpu).

### Usage[​](#usage-2 "Direct link to Usage")

```
await browser.throttleCPU(rate)
```

### Parameters[​](#parameters-2 "Direct link to Parameters")

| Name   | Type     | Details                                        |
| ------ | -------- | ---------------------------------------------- |
| `rate` | `number` | Rate on how much the CPU should get throttled. |

### Examples[​](#examples-2 "Direct link to Examples")

```
// throttle CPU and make it run 4x slower
browser.throttleCPU(4)
```

```
// reset CPU throttling
browser.throttleCPU(0)
```

***

## interceptRequest[​](#interceptrequest "Direct link to interceptRequest")

Allows modifying any request made by the browser. You can blacklist, modify, or redirect these as required for your tests.<br /><br />Sauce Labs command. More details can be found in the [official protocol docs](https://docs.saucelabs.com/insights/debug/#intercept-network-requests).

### Usage[​](#usage-3 "Direct link to Usage")

```
await browser.interceptRequest(rule)
```

### Parameters[​](#parameters-3 "Direct link to Parameters")

| Name   | Type     | Details                                     |
| ------ | -------- | ------------------------------------------- |
| `rule` | `object` | A rule describing the request interception. |

### Examples[​](#examples-3 "Direct link to Examples")

```
// redirect a request
browser.interceptRequest({
  url: 'https://saucelabs.com',
  redirect: 'https://google.com'
})
```

```
// Blacklist requests to 3rd party vendors
browser.interceptRequest({
  url: 'https://api.segment.io/v1/p',
  error: 'Failed'
})
```

```
// Modify requests to REST API (Mock REST API response)
browser.interceptRequest({
  url: 'http://sampleapp.appspot.com/api/todos',
  response: {
    headers: {
      'x-custom-headers': 'foobar'
    },
    body: [{
      title: 'My custom todo',
      order: 1,
      completed: false,
      url: 'http://todo-backend-express.herokuapp.com/15727'
    }]
  }
})
```

***

## assertPerformance[​](#assertperformance "Direct link to assertPerformance")

Assert against the performance baseline of your app.<br /><br />Sauce Labs command. More details can be found in the [official protocol docs](https://docs.saucelabs.com/performance/transitions/#setting-performance-capabilities).

### Usage[​](#usage-4 "Direct link to Usage")

```
await browser.assertPerformance(name, metrics)
```

### Parameters[​](#parameters-4 "Direct link to Parameters")

| Name                      | Type       | Details                                                  |
| ------------------------- | ---------- | -------------------------------------------------------- |
| `name`                    | `string`   | Name of the job you created your baseline with.          |
| `metrics`<br />*optional* | `string[]` | Name of metrics you want to assert against the baseline. |

### Example[​](#example "Direct link to Example")

```
// test performance for a page
browser.url('https://webdriver.io')
const hasRegression = browser.assertPerformance({
  name: 'my performance test', // make sure that the name is also set in the sauce options in your capabilities
  metrics: ['score', 'firstPaint']
})
```

### Returns[​](#returns-1 "Direct link to Returns")

* **\<object>** **`hasRegression`:** An object containing the result as well as metrics about the result.

***

## jankinessCheck[​](#jankinesscheck "Direct link to jankinessCheck")

Perform a scroll test that evaluates the jankiness of the application.<br /><br />Sauce Labs command. More details can be found in the [official protocol docs](https://docs.saucelabs.com/performance/motion/#implementing-the-jankiness-custom-command).

### Usage[​](#usage-5 "Direct link to Usage")

```
await browser.jankinessCheck()
```

### Example[​](#example-1 "Direct link to Example")

```
// test performance for a page
browser.url('https://webdriver.io')
browser.jankinessCheck()
```

### Returns[​](#returns-2 "Direct link to Returns")

* **\<object>** **`testResults`:** An object containing the score as well as metrics around how smooth the UX of the page was during the test.

***

## mockRequest[​](#mockrequest "Direct link to mockRequest")

Mocks a network resource.<br /><br />Sauce Labs command. More details can be found in the [official protocol docs](https://docs.saucelabs.com/).

### Usage[​](#usage-6 "Direct link to Usage")

```
await browser.mockRequest(url, filterOptions)
```

### Parameters[​](#parameters-5 "Direct link to Parameters")

| Name                            | Type     | Details                                                           |
| ------------------------------- | -------- | ----------------------------------------------------------------- |
| `url`                           | `string` | URL glob to match url to mock.                                    |
| `filterOptions`<br />*optional* | `object` | Additional filter options for url to mock (e.g. headers, method). |

### Returns[​](#returns-3 "Direct link to Returns")

* **\<object>** **`mockId`:** An object containing the id of a mock resource.

***

## getMockCalls[​](#getmockcalls "Direct link to getMockCalls")

Receive request information about requests that match the mocked resource.<br /><br />Sauce Labs command. More details can be found in the [official protocol docs](https://docs.saucelabs.com/).

### Usage[​](#usage-7 "Direct link to Usage")

```
await browser.getMockCalls(mockId)
```

### Parameters[​](#parameters-6 "Direct link to Parameters")

| Name     | Type     | Details          |
| -------- | -------- | ---------------- |
| `mockId` | `String` | the id of a mock |

### Returns[​](#returns-4 "Direct link to Returns")

* **\<object>** **`requests`:** A list of request information.

***

## clearMockCalls[​](#clearmockcalls "Direct link to clearMockCalls")

Clear list of mock calls.<br /><br />Sauce Labs command. More details can be found in the [official protocol docs](https://docs.saucelabs.com/).

### Usage[​](#usage-8 "Direct link to Usage")

```
await browser.clearMockCalls(mockId, restore)
```

### Parameters[​](#parameters-7 "Direct link to Parameters")

| Name                      | Type      | Details                                         |
| ------------------------- | --------- | ----------------------------------------------- |
| `mockId`                  | `String`  | the id of a mock                                |
| `restore`<br />*optional* | `boolean` | Set to true if mock should be restored as well. |

***

## respondMock[​](#respondmock "Direct link to respondMock")

Respond if mock matches a specific resource.<br /><br />Sauce Labs command. More details can be found in the [official protocol docs](https://docs.saucelabs.com/).

### Usage[​](#usage-9 "Direct link to Usage")

```
await browser.respondMock(mockId, payload)
```

### Parameters[​](#parameters-8 "Direct link to Parameters")

| Name                      | Type     | Details                       |
| ------------------------- | -------- | ----------------------------- |
| `mockId`                  | `String` | the id of a mock              |
| `payload`<br />*optional* | `object` | Information on mock response. |
