Skip to content

Commit

Permalink
Add browser module page. throttleNetwork doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Nov 14, 2023
1 parent ba99cad commit 11932d2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Page provides methods to interact with a single tab in a running web browser. A
| [page.tap(selector[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/tap/) | Taps the first element that matches the `selector`. |
| [page.textContent(selector[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/textcontent/) | Returns the `element.textContent`. |
| [page.throttleCPU(cpuProfile)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/throttlecpu) | Throttles the CPU in Chrome/Chromium to slow it down by the specified `rate` in the `cpuProfile` object. |
| [page.throttleNetwork(networkProfile)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/throttlenetwork) | Throttles the network in Chrome/Chromium to slow it down by the specified fields in the `networkProfile` object. |
| [page.title()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/title) | Returns the `page`'s title. |
| [page.type(selector, text[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/type/) | Types the `text` in the first element found that matches the `selector`. |
| [page.touchScreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/touchscreen) | Returns the [Touchscreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/touchscreen) instance to interact with a virtual touchscreen on the page. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: 'throttleNetwork(networkProfile)'
excerpt: 'Browser module: page.throttleNetwork(networkProfile) method'
---

# throttleNetwork(networkProfile)

Throttles the network in Chrome/Chromium to slow it down by the specified fields in the `networkProfile` object.

| Parameter | Type | Default | Description |
|-------------------------|----------------|---------|----------------------------------------------------------------------------------------|
| networkProfile | NetworkProfile | `null` | This is a mandatory parameter. |
| networkProfile.latency | number | `0` | Minimum latency from request sent to response headers received (ms). |
| networkProfile.download | number | `-1` | Maximal aggregated download throughput (bytes/sec). `-1` disables download throttling. |
| networkProfile.upload | number | `-1` | Maximal aggregated upload throughput (bytes/sec). `-1` disables upload throttling. |

To work with the most commonly tested network profiles, import `networkProfiles` from the browser module. There are three profiles available:

| Name | Notes |
|-------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `'No Throttling'` | No throttling, which is the default before applying any network throttling. This can be used to remove the network throttling. |
| `'Fast 3G'` | Emulates a typical fast 3G connection |
| `'Slow 3G'` | Emulates a typical slow 3G connection |

### Example

{{< code >}}

```javascript
import { browser, networkProfiles } from 'k6/x/browser';

export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};

export default async function () {
const context = browser.newContext();
const page = context.newPage();

try {
page.throttleNetwork(networkProfiles['Slow 3G']);

await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
} finally {
page.close();
}
}
```

{{< /code >}}

0 comments on commit 11932d2

Please sign in to comment.