From 937b25d08fd75c5bb81a2297dac5955005c3fbbb Mon Sep 17 00:00:00 2001 From: Heitor Tashiro Sergent Date: Mon, 5 Aug 2024 11:12:58 -0500 Subject: [PATCH] Fix code example errors (#1681) * Fix code example errors * Fix code samples missing async in default function * Apply to v0.52.x --- .../browsercontext/addinitscript.md | 6 +++--- .../browsercontext/clearpermissions.md | 6 +++--- .../k6-browser/browsercontext/close.md | 6 +++--- .../browsercontext/grantpermissions.md | 2 +- .../k6-browser/browsercontext/pages.md | 6 +++--- .../browsercontext/setgeolocation.md | 2 +- .../next/javascript-api/k6-browser/context.md | 6 +++--- .../k6-browser/elementhandle/textcontent.md | 2 +- .../k6-browser/elementhandle/uncheck.md | 20 +++++++++---------- .../elementhandle/waitforelementstate.md | 8 ++++---- .../k6-browser/locator/clear.md | 12 +++++------ .../k6-browser/locator/textcontent.md | 12 +++++------ .../k6-browser/locator/uncheck.md | 20 +++++++++---------- .../k6-browser/page/waitforloadstate.md | 10 +++++----- .../k6-browser/page/waitfornavigation.md | 14 ++++++------- .../browsercontext/addinitscript.md | 6 +++--- .../browsercontext/clearpermissions.md | 6 +++--- .../k6-browser/browsercontext/close.md | 6 +++--- .../browsercontext/grantpermissions.md | 2 +- .../k6-browser/browsercontext/pages.md | 6 +++--- .../browsercontext/setgeolocation.md | 2 +- .../javascript-api/k6-browser/context.md | 6 +++--- .../k6-browser/elementhandle/textcontent.md | 2 +- .../k6-browser/elementhandle/uncheck.md | 20 +++++++++---------- .../elementhandle/waitforelementstate.md | 8 ++++---- .../k6-browser/locator/clear.md | 12 +++++------ .../k6-browser/locator/textcontent.md | 12 +++++------ .../k6-browser/locator/uncheck.md | 20 +++++++++---------- .../k6-browser/page/waitforloadstate.md | 10 +++++----- .../k6-browser/page/waitfornavigation.md | 14 ++++++------- 30 files changed, 132 insertions(+), 132 deletions(-) diff --git a/docs/sources/next/javascript-api/k6-browser/browsercontext/addinitscript.md b/docs/sources/next/javascript-api/k6-browser/browsercontext/addinitscript.md index 1de9f10de..6684496db 100644 --- a/docs/sources/next/javascript-api/k6-browser/browsercontext/addinitscript.md +++ b/docs/sources/next/javascript-api/k6-browser/browsercontext/addinitscript.md @@ -14,8 +14,8 @@ The script is evaluated after the document is created but before any of its scri ### Returns -| Type | Description | -| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Type | Description | +| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `Promise` | A Promise that fulfills when the script has been added to the [browser context](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext). | ### Example @@ -63,7 +63,7 @@ export default async function () { `); - const text = await p.locator('#random').textContent(); + const text = await page.locator('#random').textContent(); check(page, { zero: () => text == '0', }); diff --git a/docs/sources/next/javascript-api/k6-browser/browsercontext/clearpermissions.md b/docs/sources/next/javascript-api/k6-browser/browsercontext/clearpermissions.md index 3116d2010..b64ef64be 100644 --- a/docs/sources/next/javascript-api/k6-browser/browsercontext/clearpermissions.md +++ b/docs/sources/next/javascript-api/k6-browser/browsercontext/clearpermissions.md @@ -9,8 +9,8 @@ Clears all permission overrides for the [browser context](https://grafana.com/do ### Returns -| Type | Description | -| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Type | Description | +| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `Promise` | A Promise that fulfills when the permissions have been cleared from the [browser context](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext). | ### Example @@ -33,7 +33,7 @@ export const options = { }, }; -export default function () { +export default async function () { const context = await browser.newContext(); await context.grantPermissions(['clipboard-read']); // do stuff ... diff --git a/docs/sources/next/javascript-api/k6-browser/browsercontext/close.md b/docs/sources/next/javascript-api/k6-browser/browsercontext/close.md index 936d80cac..158512c80 100644 --- a/docs/sources/next/javascript-api/k6-browser/browsercontext/close.md +++ b/docs/sources/next/javascript-api/k6-browser/browsercontext/close.md @@ -9,8 +9,8 @@ Close the [browser context](https://grafana.com/docs/k6//javascript- ### Returns -| Type | Description | -| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Type | Description | +| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `Promise` | A Promise that fulfills when the [browser context](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext) and all its [page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/)s have been closed. | ### Example @@ -33,7 +33,7 @@ export const options = { }, }; -export default function () { +export default async function () { const context = await browser.newContext(); await context.newPage(); diff --git a/docs/sources/next/javascript-api/k6-browser/browsercontext/grantpermissions.md b/docs/sources/next/javascript-api/k6-browser/browsercontext/grantpermissions.md index edb5bf159..eff5e170f 100644 --- a/docs/sources/next/javascript-api/k6-browser/browsercontext/grantpermissions.md +++ b/docs/sources/next/javascript-api/k6-browser/browsercontext/grantpermissions.md @@ -43,7 +43,7 @@ export const options = { }, }; -export default function () { +export default async function () { const context = await browser.newContext(); await context.grantPermissions(['clipboard-read', 'clipboard-write'], { origin: 'https://example.com/', diff --git a/docs/sources/next/javascript-api/k6-browser/browsercontext/pages.md b/docs/sources/next/javascript-api/k6-browser/browsercontext/pages.md index 9f3e36d4d..0d2d89b56 100644 --- a/docs/sources/next/javascript-api/k6-browser/browsercontext/pages.md +++ b/docs/sources/next/javascript-api/k6-browser/browsercontext/pages.md @@ -16,8 +16,8 @@ Returns all open [Page](https://grafana.com/docs/k6//javascript-api/ ### Returns -| Type | Description | -| ------------- | ------------------------------------------------------------------------------------------------------------------ | +| Type | Description | +| ------------- | ----------------------------------------------------------------------------------------------------- | | `Array` | An array of [page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/) objects. | ### Example @@ -40,7 +40,7 @@ export const options = { }, }; -export default function () { +export default async function () { const context = await browser.newContext(); await context.newPage(); const pages = context.pages(); diff --git a/docs/sources/next/javascript-api/k6-browser/browsercontext/setgeolocation.md b/docs/sources/next/javascript-api/k6-browser/browsercontext/setgeolocation.md index 0902055af..3bb279287 100644 --- a/docs/sources/next/javascript-api/k6-browser/browsercontext/setgeolocation.md +++ b/docs/sources/next/javascript-api/k6-browser/browsercontext/setgeolocation.md @@ -51,7 +51,7 @@ export const options = { }, }; -export default function () { +export default async function () { const context = await browser.newContext(); await context.setGeolocation({ latitude: 59.95, longitude: 30.31667 }); } diff --git a/docs/sources/next/javascript-api/k6-browser/context.md b/docs/sources/next/javascript-api/k6-browser/context.md index 37ea936d2..88e6fee6a 100644 --- a/docs/sources/next/javascript-api/k6-browser/context.md +++ b/docs/sources/next/javascript-api/k6-browser/context.md @@ -15,8 +15,8 @@ A 1-to-1 mapping between [Browser](https://grafana.com/docs/k6//java ### Returns -| Type | Description | -| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| Type | Description | +| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | object \| null | The current [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) if one has been created, otherwise `null`. | ### Example @@ -37,7 +37,7 @@ export const options = { }, }; -export default function () { +export default async function () { console.log(browser.context()); // null const page1 = await browser.newPage(); // implicitly creates a new browserContext diff --git a/docs/sources/next/javascript-api/k6-browser/elementhandle/textcontent.md b/docs/sources/next/javascript-api/k6-browser/elementhandle/textcontent.md index 9a79806b9..23837a06f 100644 --- a/docs/sources/next/javascript-api/k6-browser/elementhandle/textcontent.md +++ b/docs/sources/next/javascript-api/k6-browser/elementhandle/textcontent.md @@ -40,7 +40,7 @@ export const options = { }; export default async function () { - const page = await newPage(); + const page = await browser.newPage(); await page.goto('https://test.k6.io/browser.php'); const options = await page.$('#checkbox1'); diff --git a/docs/sources/next/javascript-api/k6-browser/elementhandle/uncheck.md b/docs/sources/next/javascript-api/k6-browser/elementhandle/uncheck.md index 9aa44b76b..74cfe648c 100644 --- a/docs/sources/next/javascript-api/k6-browser/elementhandle/uncheck.md +++ b/docs/sources/next/javascript-api/k6-browser/elementhandle/uncheck.md @@ -15,16 +15,16 @@ Unselect the `input` checkbox. -| Parameter | Type | Default | Description | -| ------------------- | ------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| options | object | `null` | | -| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | -| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | -| options.position | object | `null` | A point to use relative to the top left corner of the element. If not supplied, a visible point of the element is used. | -| options.position.x | number | `0` | The x coordinate. | -| options.position.y | number | `0` | The y coordinate. | +| Parameter | Type | Default | Description | +| ------------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | object | `null` | | +| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | +| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | +| options.position | object | `null` | A point to use relative to the top left corner of the element. If not supplied, a visible point of the element is used. | +| options.position.x | number | `0` | The x coordinate. | +| options.position.y | number | `0` | The y coordinate. | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | -| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | +| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | @@ -55,7 +55,7 @@ export const options = { }; export default async function () { - const page = await newPage(); + const page = await browser.newPage(); await page.goto('https://test.k6.io/browser.php'); const checkbox = await page.$('#checkbox1'); diff --git a/docs/sources/next/javascript-api/k6-browser/elementhandle/waitforelementstate.md b/docs/sources/next/javascript-api/k6-browser/elementhandle/waitforelementstate.md index e6cfeaf37..c6879d1c0 100644 --- a/docs/sources/next/javascript-api/k6-browser/elementhandle/waitforelementstate.md +++ b/docs/sources/next/javascript-api/k6-browser/elementhandle/waitforelementstate.md @@ -9,9 +9,9 @@ Waits for the element to reach the specified state. -| Parameter | Type | Default | Description | -| --------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| state | string | | The state to wait for. This can be one of `visible`, `hidden`, `stable`, `enabled`, `disabled`, or `editable`. | +| Parameter | Type | Default | Description | +| --------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| state | string | | The state to wait for. This can be one of `visible`, `hidden`, `stable`, `enabled`, `disabled`, or `editable`. | | timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | @@ -49,7 +49,7 @@ export default async function () { const element = await page.$('#text1'); await element.waitForElementState('visible'); - await close(); + await page.close(); } ``` diff --git a/docs/sources/next/javascript-api/k6-browser/locator/clear.md b/docs/sources/next/javascript-api/k6-browser/locator/clear.md index e30d77c45..53554ab6c 100644 --- a/docs/sources/next/javascript-api/k6-browser/locator/clear.md +++ b/docs/sources/next/javascript-api/k6-browser/locator/clear.md @@ -9,11 +9,11 @@ Clears text boxes and input fields (`input`, `textarea` or `contenteditable` ele -| Parameter | Type | Default | Description | -| ------------------- | ------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| options | object | `null` | | -| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | -| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | +| Parameter | Type | Default | Description | +| ------------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | object | `null` | | +| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | +| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | @@ -59,7 +59,7 @@ export default async function () { // This checks that the element has been filled with text. let value = await login.inputValue(); check(page, { - not_empty: (p) => input != '', + not_empty: (p) => value != '', }); // Now clear the text from the element. diff --git a/docs/sources/next/javascript-api/k6-browser/locator/textcontent.md b/docs/sources/next/javascript-api/k6-browser/locator/textcontent.md index 1e8082095..8c3bcd1f7 100644 --- a/docs/sources/next/javascript-api/k6-browser/locator/textcontent.md +++ b/docs/sources/next/javascript-api/k6-browser/locator/textcontent.md @@ -9,17 +9,17 @@ Returns the `element.textContent`. -| Parameter | Type | Default | Description | -| --------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| options | object | `null` | | +| Parameter | Type | Default | Description | +| --------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | object | `null` | | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | ### Returns -| Type | Description | -| ----------------------- | ------------------------------------------------------------------------ | +| Type | Description | +| ------------------------- | ------------------------------------------------------------------------ | | `Promise` | A Promise that fulfills with the text content of the selector or `null`. | ### Example @@ -43,7 +43,7 @@ export const options = { }; export default async function () { - const page = await newPage(); + const page = await browser.newPage(); await page.goto('https://test.k6.io/browser.php'); const options = page.locator('#checkbox1'); console.log(await options.textContent()); diff --git a/docs/sources/next/javascript-api/k6-browser/locator/uncheck.md b/docs/sources/next/javascript-api/k6-browser/locator/uncheck.md index f5e81d172..e3bf951e0 100644 --- a/docs/sources/next/javascript-api/k6-browser/locator/uncheck.md +++ b/docs/sources/next/javascript-api/k6-browser/locator/uncheck.md @@ -16,16 +16,16 @@ Unselect the `input` checkbox. -| Parameter | Type | Default | Description | -| ------------------- | ------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| options | object | `null` | | -| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | -| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | -| options.position | object | `null` | A point to use relative to the top left corner of the element. If not supplied, a visible point of the element is used. | -| options.position.x | number | `0` | The x coordinate. | -| options.position.y | number | `0` | The y coordinate. | +| Parameter | Type | Default | Description | +| ------------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | object | `null` | | +| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | +| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | +| options.position | object | `null` | A point to use relative to the top left corner of the element. If not supplied, a visible point of the element is used. | +| options.position.x | number | `0` | The x coordinate. | +| options.position.y | number | `0` | The y coordinate. | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | -| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | +| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | @@ -56,7 +56,7 @@ export const options = { }; export default async function () { - const page = await newPage(); + const page = await browser.newPage(); await page.goto('https://test.k6.io/browser.php'); const checkbox = page.locator('#checkbox1'); await checkbox.check(); diff --git a/docs/sources/next/javascript-api/k6-browser/page/waitforloadstate.md b/docs/sources/next/javascript-api/k6-browser/page/waitforloadstate.md index 820941c04..9c52564fa 100644 --- a/docs/sources/next/javascript-api/k6-browser/page/waitforloadstate.md +++ b/docs/sources/next/javascript-api/k6-browser/page/waitforloadstate.md @@ -15,10 +15,10 @@ This waits for the given load state to be reached. It will immediately unblock i -| Parameter | Type | Default | Description | -| --------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| state | string | `load` | Optional load state to wait for. See [Events](#events) for more details. | -| options | object | `null` | | +| Parameter | Type | Default | Description | +| --------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| state | string | `load` | Optional load state to wait for. See [Events](#events) for more details. | +| options | object | `null` | | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | @@ -78,7 +78,7 @@ export default async function () { await page.waitForLoadState(); // waits for the default `load` event - const text = await p.locator('h2').textContent(); + const text = await page.locator('h2').textContent(); check(page, { header: () => text == 'Welcome, admin!', }); diff --git a/docs/sources/next/javascript-api/k6-browser/page/waitfornavigation.md b/docs/sources/next/javascript-api/k6-browser/page/waitfornavigation.md index 46bf91b66..b1bc44c3e 100644 --- a/docs/sources/next/javascript-api/k6-browser/page/waitfornavigation.md +++ b/docs/sources/next/javascript-api/k6-browser/page/waitfornavigation.md @@ -9,11 +9,11 @@ Waits for the given navigation lifecycle event to occur and returns the main res -| Parameter | Type | Default | Description | -| ----------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| options | object | `null` | | +| Parameter | Type | Default | Description | +| ----------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | object | `null` | | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | -| options.waitUntil | string | `load` | When to consider operation to have succeeded. See [Events](#events) for more details. | +| options.waitUntil | string | `load` | When to consider operation to have succeeded. See [Events](#events) for more details. | @@ -33,8 +33,8 @@ Events can be either: ### Returns -| Type | Description | -| ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | +| Type | Description | +| --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | | Promise/javascript-api/k6-browser/response/)> | The `Response` instance associated with the page. Else, it returns `null` | ### Example @@ -71,7 +71,7 @@ export default async function () { await Promise.all([page.waitForNavigation(), submitButton.click()]); - const text = await p.locator('h2').textContent(); + const text = await page.locator('h2').textContent(); check(page, { header: () => text == 'Welcome, admin!', }); diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/addinitscript.md b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/addinitscript.md index 1de9f10de..6684496db 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/addinitscript.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/addinitscript.md @@ -14,8 +14,8 @@ The script is evaluated after the document is created but before any of its scri ### Returns -| Type | Description | -| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Type | Description | +| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `Promise` | A Promise that fulfills when the script has been added to the [browser context](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext). | ### Example @@ -63,7 +63,7 @@ export default async function () { `); - const text = await p.locator('#random').textContent(); + const text = await page.locator('#random').textContent(); check(page, { zero: () => text == '0', }); diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/clearpermissions.md b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/clearpermissions.md index 3116d2010..b64ef64be 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/clearpermissions.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/clearpermissions.md @@ -9,8 +9,8 @@ Clears all permission overrides for the [browser context](https://grafana.com/do ### Returns -| Type | Description | -| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Type | Description | +| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `Promise` | A Promise that fulfills when the permissions have been cleared from the [browser context](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext). | ### Example @@ -33,7 +33,7 @@ export const options = { }, }; -export default function () { +export default async function () { const context = await browser.newContext(); await context.grantPermissions(['clipboard-read']); // do stuff ... diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/close.md b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/close.md index 936d80cac..158512c80 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/close.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/close.md @@ -9,8 +9,8 @@ Close the [browser context](https://grafana.com/docs/k6//javascript- ### Returns -| Type | Description | -| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Type | Description | +| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `Promise` | A Promise that fulfills when the [browser context](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext) and all its [page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/)s have been closed. | ### Example @@ -33,7 +33,7 @@ export const options = { }, }; -export default function () { +export default async function () { const context = await browser.newContext(); await context.newPage(); diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/grantpermissions.md b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/grantpermissions.md index edb5bf159..eff5e170f 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/grantpermissions.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/grantpermissions.md @@ -43,7 +43,7 @@ export const options = { }, }; -export default function () { +export default async function () { const context = await browser.newContext(); await context.grantPermissions(['clipboard-read', 'clipboard-write'], { origin: 'https://example.com/', diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/pages.md b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/pages.md index 9f3e36d4d..0d2d89b56 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/pages.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/pages.md @@ -16,8 +16,8 @@ Returns all open [Page](https://grafana.com/docs/k6//javascript-api/ ### Returns -| Type | Description | -| ------------- | ------------------------------------------------------------------------------------------------------------------ | +| Type | Description | +| ------------- | ----------------------------------------------------------------------------------------------------- | | `Array` | An array of [page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/) objects. | ### Example @@ -40,7 +40,7 @@ export const options = { }, }; -export default function () { +export default async function () { const context = await browser.newContext(); await context.newPage(); const pages = context.pages(); diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/setgeolocation.md b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/setgeolocation.md index 0902055af..3bb279287 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/setgeolocation.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/browsercontext/setgeolocation.md @@ -51,7 +51,7 @@ export const options = { }, }; -export default function () { +export default async function () { const context = await browser.newContext(); await context.setGeolocation({ latitude: 59.95, longitude: 30.31667 }); } diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/context.md b/docs/sources/v0.52.x/javascript-api/k6-browser/context.md index 37ea936d2..88e6fee6a 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/context.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/context.md @@ -15,8 +15,8 @@ A 1-to-1 mapping between [Browser](https://grafana.com/docs/k6//java ### Returns -| Type | Description | -| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| Type | Description | +| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | object \| null | The current [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) if one has been created, otherwise `null`. | ### Example @@ -37,7 +37,7 @@ export const options = { }, }; -export default function () { +export default async function () { console.log(browser.context()); // null const page1 = await browser.newPage(); // implicitly creates a new browserContext diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/textcontent.md b/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/textcontent.md index 9a79806b9..23837a06f 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/textcontent.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/textcontent.md @@ -40,7 +40,7 @@ export const options = { }; export default async function () { - const page = await newPage(); + const page = await browser.newPage(); await page.goto('https://test.k6.io/browser.php'); const options = await page.$('#checkbox1'); diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/uncheck.md b/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/uncheck.md index 9aa44b76b..74cfe648c 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/uncheck.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/uncheck.md @@ -15,16 +15,16 @@ Unselect the `input` checkbox. -| Parameter | Type | Default | Description | -| ------------------- | ------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| options | object | `null` | | -| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | -| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | -| options.position | object | `null` | A point to use relative to the top left corner of the element. If not supplied, a visible point of the element is used. | -| options.position.x | number | `0` | The x coordinate. | -| options.position.y | number | `0` | The y coordinate. | +| Parameter | Type | Default | Description | +| ------------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | object | `null` | | +| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | +| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | +| options.position | object | `null` | A point to use relative to the top left corner of the element. If not supplied, a visible point of the element is used. | +| options.position.x | number | `0` | The x coordinate. | +| options.position.y | number | `0` | The y coordinate. | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | -| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | +| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | @@ -55,7 +55,7 @@ export const options = { }; export default async function () { - const page = await newPage(); + const page = await browser.newPage(); await page.goto('https://test.k6.io/browser.php'); const checkbox = await page.$('#checkbox1'); diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/waitforelementstate.md b/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/waitforelementstate.md index e6cfeaf37..c6879d1c0 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/waitforelementstate.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/elementhandle/waitforelementstate.md @@ -9,9 +9,9 @@ Waits for the element to reach the specified state. -| Parameter | Type | Default | Description | -| --------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| state | string | | The state to wait for. This can be one of `visible`, `hidden`, `stable`, `enabled`, `disabled`, or `editable`. | +| Parameter | Type | Default | Description | +| --------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| state | string | | The state to wait for. This can be one of `visible`, `hidden`, `stable`, `enabled`, `disabled`, or `editable`. | | timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | @@ -49,7 +49,7 @@ export default async function () { const element = await page.$('#text1'); await element.waitForElementState('visible'); - await close(); + await page.close(); } ``` diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/locator/clear.md b/docs/sources/v0.52.x/javascript-api/k6-browser/locator/clear.md index e30d77c45..53554ab6c 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/locator/clear.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/locator/clear.md @@ -9,11 +9,11 @@ Clears text boxes and input fields (`input`, `textarea` or `contenteditable` ele -| Parameter | Type | Default | Description | -| ------------------- | ------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| options | object | `null` | | -| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | -| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | +| Parameter | Type | Default | Description | +| ------------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | object | `null` | | +| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | +| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | @@ -59,7 +59,7 @@ export default async function () { // This checks that the element has been filled with text. let value = await login.inputValue(); check(page, { - not_empty: (p) => input != '', + not_empty: (p) => value != '', }); // Now clear the text from the element. diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/locator/textcontent.md b/docs/sources/v0.52.x/javascript-api/k6-browser/locator/textcontent.md index 1e8082095..8c3bcd1f7 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/locator/textcontent.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/locator/textcontent.md @@ -9,17 +9,17 @@ Returns the `element.textContent`. -| Parameter | Type | Default | Description | -| --------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| options | object | `null` | | +| Parameter | Type | Default | Description | +| --------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | object | `null` | | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | ### Returns -| Type | Description | -| ----------------------- | ------------------------------------------------------------------------ | +| Type | Description | +| ------------------------- | ------------------------------------------------------------------------ | | `Promise` | A Promise that fulfills with the text content of the selector or `null`. | ### Example @@ -43,7 +43,7 @@ export const options = { }; export default async function () { - const page = await newPage(); + const page = await browser.newPage(); await page.goto('https://test.k6.io/browser.php'); const options = page.locator('#checkbox1'); console.log(await options.textContent()); diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/locator/uncheck.md b/docs/sources/v0.52.x/javascript-api/k6-browser/locator/uncheck.md index f5e81d172..e3bf951e0 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/locator/uncheck.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/locator/uncheck.md @@ -16,16 +16,16 @@ Unselect the `input` checkbox. -| Parameter | Type | Default | Description | -| ------------------- | ------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| options | object | `null` | | -| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | -| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | -| options.position | object | `null` | A point to use relative to the top left corner of the element. If not supplied, a visible point of the element is used. | -| options.position.x | number | `0` | The x coordinate. | -| options.position.y | number | `0` | The y coordinate. | +| Parameter | Type | Default | Description | +| ------------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | object | `null` | | +| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | +| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. | +| options.position | object | `null` | A point to use relative to the top left corner of the element. If not supplied, a visible point of the element is used. | +| options.position.x | number | `0` | The x coordinate. | +| options.position.y | number | `0` | The y coordinate. | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | -| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | +| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | @@ -56,7 +56,7 @@ export const options = { }; export default async function () { - const page = await newPage(); + const page = await browser.newPage(); await page.goto('https://test.k6.io/browser.php'); const checkbox = page.locator('#checkbox1'); await checkbox.check(); diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/page/waitforloadstate.md b/docs/sources/v0.52.x/javascript-api/k6-browser/page/waitforloadstate.md index 820941c04..9c52564fa 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/page/waitforloadstate.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/page/waitforloadstate.md @@ -15,10 +15,10 @@ This waits for the given load state to be reached. It will immediately unblock i -| Parameter | Type | Default | Description | -| --------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| state | string | `load` | Optional load state to wait for. See [Events](#events) for more details. | -| options | object | `null` | | +| Parameter | Type | Default | Description | +| --------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| state | string | `load` | Optional load state to wait for. See [Events](#events) for more details. | +| options | object | `null` | | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | @@ -78,7 +78,7 @@ export default async function () { await page.waitForLoadState(); // waits for the default `load` event - const text = await p.locator('h2').textContent(); + const text = await page.locator('h2').textContent(); check(page, { header: () => text == 'Welcome, admin!', }); diff --git a/docs/sources/v0.52.x/javascript-api/k6-browser/page/waitfornavigation.md b/docs/sources/v0.52.x/javascript-api/k6-browser/page/waitfornavigation.md index 46bf91b66..b1bc44c3e 100644 --- a/docs/sources/v0.52.x/javascript-api/k6-browser/page/waitfornavigation.md +++ b/docs/sources/v0.52.x/javascript-api/k6-browser/page/waitfornavigation.md @@ -9,11 +9,11 @@ Waits for the given navigation lifecycle event to occur and returns the main res -| Parameter | Type | Default | Description | -| ----------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| options | object | `null` | | +| Parameter | Type | Default | Description | +| ----------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| options | object | `null` | | | options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](https://grafana.com/docs/k6//javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6//javascript-api/k6-browser/page/). | -| options.waitUntil | string | `load` | When to consider operation to have succeeded. See [Events](#events) for more details. | +| options.waitUntil | string | `load` | When to consider operation to have succeeded. See [Events](#events) for more details. | @@ -33,8 +33,8 @@ Events can be either: ### Returns -| Type | Description | -| ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | +| Type | Description | +| --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | | Promise/javascript-api/k6-browser/response/)> | The `Response` instance associated with the page. Else, it returns `null` | ### Example @@ -71,7 +71,7 @@ export default async function () { await Promise.all([page.waitForNavigation(), submitButton.click()]); - const text = await p.locator('h2').textContent(); + const text = await page.locator('h2').textContent(); check(page, { header: () => text == 'Welcome, admin!', });