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

Fix code example errors #1681

Merged
merged 3 commits into from
Aug 5, 2024
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 @@ -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<void>` | A Promise that fulfills when the script has been added to the [browser context](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/browsercontext). |

### Example
Expand Down Expand Up @@ -63,7 +63,7 @@ export default async function () {
</script>
</html>`);

const text = await p.locator('#random').textContent();
const text = await page.locator('#random').textContent();
check(page, {
zero: () => text == '0',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Clears all permission overrides for the [browser context](https://grafana.com/do

### Returns

| Type | Description |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Type | Description |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Promise<void>` | A Promise that fulfills when the permissions have been cleared from the [browser context](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/browsercontext). |

### Example
Expand All @@ -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 ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Close the [browser context](https://grafana.com/docs/k6/<K6_VERSION>/javascript-

### Returns

| Type | Description |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Type | Description |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Promise<void>` | A Promise that fulfills when the [browser context](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/browsercontext) and all its [page](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/)s have been closed. |

### Example
Expand All @@ -33,7 +33,7 @@ export const options = {
},
};

export default function () {
export default async function () {
const context = await browser.newContext();
await context.newPage();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Returns all open [Page](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/

### Returns

| Type | Description |
| ------------- | ------------------------------------------------------------------------------------------------------------------ |
| Type | Description |
| ------------- | ----------------------------------------------------------------------------------------------------- |
| `Array<Page>` | An array of [page](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/) objects. |

### Example
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
6 changes: 3 additions & 3 deletions docs/sources/next/javascript-api/k6-browser/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ A 1-to-1 mapping between [Browser](https://grafana.com/docs/k6/<K6_VERSION>/java

### Returns

| Type | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Type | Description |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| object \| null | The current [BrowserContext](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/browsercontext/) if one has been created, otherwise `null`. |

### Example
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ Unselect the `input` checkbox.

<TableWithNestedRows>

| 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/<K6_VERSION>/javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6/<K6_VERSION>/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. |

</TableWithNestedRows>

Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Waits for the element to reach the specified state.

<TableWithNestedRows>

| 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/<K6_VERSION>/javascript-api/k6-browser/browsercontext/) or [Page](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/page/). |

</TableWithNestedRows>
Expand Down Expand Up @@ -49,7 +49,7 @@ export default async function () {
const element = await page.$('#text1');
await element.waitForElementState('visible');

await close();
await page.close();
}
```

Expand Down
Loading
Loading