From ba99cadac67c687829b84d8e65741063c5973514 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Tue, 14 Nov 2023 14:32:01 +0000 Subject: [PATCH] Add browser module page.throttleCPU documentation --- .../k6-experimental/browser/page/_index.md | 1 + .../browser/page/throttlecpu.md | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 docs/sources/next/javascript-api/k6-experimental/browser/page/throttlecpu.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 0eccbdab1c..a430502bfa 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 @@ -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//javascript-api/k6-experimental/browser/page/setviewportsize) | Updates the `page`'s width and height. | | [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.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/throttlecpu.md b/docs/sources/next/javascript-api/k6-experimental/browser/page/throttlecpu.md new file mode 100644 index 0000000000..1f5cfcada8 --- /dev/null +++ b/docs/sources/next/javascript-api/k6-experimental/browser/page/throttlecpu.md @@ -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 >}}