Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add page.throttleCPU and page.throttleNetwork docs #1415

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Page provides methods to interact with a single tab in a running web browser. A
| [page.setViewportSize(viewportSize)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/setviewportsize) | Updates the `page`'s width and height. |
| [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,49 @@
---
title: 'throttleCPU(cpuProfile)'
excerpt: 'Browser module: page.throttleCPU(cpuProfile) method'
---

# throttleCPU(cpuProfile)

Throttles the CPU in Chrome/Chromium to slow it down by the specified `rate` in `cpuProfile`.

| Parameter | Type | Default | Description |
|-----------------|------------|---------|----------------------------------------------------------------------|
| cpuProfile | CPUProfile | `null` | This is a mandatory parameter. |
| cpuProfile.rate | number | `1` | rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc). |

### Example

{{< code >}}

```javascript
import { browser } from 'k6/experimental/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.throttleCPU({ rate: 4 });

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

{{< /code >}}
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. |
ka3de marked this conversation as resolved.
Show resolved Hide resolved

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 >}}
Loading