Skip to content

Commit

Permalink
Add browser module page.throttleCPU documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Nov 14, 2023
1 parent 672a21f commit ba99cad
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ 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.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 >}}

0 comments on commit ba99cad

Please sign in to comment.