From 6e654dbcaaa0f8cb89286915d5ce4c7351e64716 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Tue, 14 Nov 2023 14:40:39 +0000 Subject: [PATCH] Add browser module page. throttleNetwork doc --- .../k6-experimental/browser/page/_index.md | 1 + .../browser/page/throttlenetwork.md | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 docs/sources/next/javascript-api/k6-experimental/browser/page/throttlenetwork.md diff --git a/docs/sources/next/javascript-api/k6-experimental/browser/page/_index.md b/docs/sources/next/javascript-api/k6-experimental/browser/page/_index.md index a430502bfa..ded6fe7e5a 100644 --- a/docs/sources/next/javascript-api/k6-experimental/browser/page/_index.md +++ b/docs/sources/next/javascript-api/k6-experimental/browser/page/_index.md @@ -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//javascript-api/k6-experimental/browser/page/tap/) | Taps the first element that matches the `selector`. | | [page.textContent(selector[, options])](https://grafana.com/docs/k6//javascript-api/k6-experimental/browser/page/textcontent/) | Returns the `element.textContent`. | | [page.throttleCPU(cpuProfile)](https://grafana.com/docs/k6//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//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//javascript-api/k6-experimental/browser/page/title) | Returns the `page`'s title. | | [page.type(selector, text[, options])](https://grafana.com/docs/k6//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//javascript-api/k6-experimental/browser/page/touchscreen) | Returns the [Touchscreen](https://grafana.com/docs/k6//javascript-api/k6-experimental/browser/touchscreen) instance to interact with a virtual touchscreen on the page. | diff --git a/docs/sources/next/javascript-api/k6-experimental/browser/page/throttlenetwork.md b/docs/sources/next/javascript-api/k6-experimental/browser/page/throttlenetwork.md new file mode 100644 index 0000000000..00540202a0 --- /dev/null +++ b/docs/sources/next/javascript-api/k6-experimental/browser/page/throttlenetwork.md @@ -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 >}}