Skip to content

Commit 937b25d

Browse files
Fix code example errors (#1681)
* Fix code example errors * Fix code samples missing async in default function * Apply to v0.52.x
1 parent 4110f5d commit 937b25d

30 files changed

+132
-132
lines changed

docs/sources/next/javascript-api/k6-browser/browsercontext/addinitscript.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ The script is evaluated after the document is created but before any of its scri
1414

1515
### Returns
1616

17-
| Type | Description |
18-
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17+
| Type | Description |
18+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1919
| `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). |
2020

2121
### Example
@@ -63,7 +63,7 @@ export default async function () {
6363
</script>
6464
</html>`);
6565

66-
const text = await p.locator('#random').textContent();
66+
const text = await page.locator('#random').textContent();
6767
check(page, {
6868
zero: () => text == '0',
6969
});

docs/sources/next/javascript-api/k6-browser/browsercontext/clearpermissions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Clears all permission overrides for the [browser context](https://grafana.com/do
99

1010
### Returns
1111

12-
| Type | Description |
13-
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
12+
| Type | Description |
13+
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1414
| `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). |
1515

1616
### Example
@@ -33,7 +33,7 @@ export const options = {
3333
},
3434
};
3535

36-
export default function () {
36+
export default async function () {
3737
const context = await browser.newContext();
3838
await context.grantPermissions(['clipboard-read']);
3939
// do stuff ...

docs/sources/next/javascript-api/k6-browser/browsercontext/close.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Close the [browser context](https://grafana.com/docs/k6/<K6_VERSION>/javascript-
99

1010
### Returns
1111

12-
| Type | Description |
13-
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
12+
| Type | Description |
13+
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1414
| `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. |
1515

1616
### Example
@@ -33,7 +33,7 @@ export const options = {
3333
},
3434
};
3535

36-
export default function () {
36+
export default async function () {
3737
const context = await browser.newContext();
3838
await context.newPage();
3939

docs/sources/next/javascript-api/k6-browser/browsercontext/grantpermissions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const options = {
4343
},
4444
};
4545

46-
export default function () {
46+
export default async function () {
4747
const context = await browser.newContext();
4848
await context.grantPermissions(['clipboard-read', 'clipboard-write'], {
4949
origin: 'https://example.com/',

docs/sources/next/javascript-api/k6-browser/browsercontext/pages.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Returns all open [Page](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/
1616

1717
### Returns
1818

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

2323
### Example
@@ -40,7 +40,7 @@ export const options = {
4040
},
4141
};
4242

43-
export default function () {
43+
export default async function () {
4444
const context = await browser.newContext();
4545
await context.newPage();
4646
const pages = context.pages();

docs/sources/next/javascript-api/k6-browser/browsercontext/setgeolocation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const options = {
5151
},
5252
};
5353

54-
export default function () {
54+
export default async function () {
5555
const context = await browser.newContext();
5656
await context.setGeolocation({ latitude: 59.95, longitude: 30.31667 });
5757
}

docs/sources/next/javascript-api/k6-browser/context.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ A 1-to-1 mapping between [Browser](https://grafana.com/docs/k6/<K6_VERSION>/java
1515

1616
### Returns
1717

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

2222
### Example
@@ -37,7 +37,7 @@ export const options = {
3737
},
3838
};
3939

40-
export default function () {
40+
export default async function () {
4141
console.log(browser.context()); // null
4242

4343
const page1 = await browser.newPage(); // implicitly creates a new browserContext

docs/sources/next/javascript-api/k6-browser/elementhandle/textcontent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const options = {
4040
};
4141

4242
export default async function () {
43-
const page = await newPage();
43+
const page = await browser.newPage();
4444
await page.goto('https://test.k6.io/browser.php');
4545

4646
const options = await page.$('#checkbox1');

docs/sources/next/javascript-api/k6-browser/elementhandle/uncheck.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ Unselect the `input` checkbox.
1515

1616
<TableWithNestedRows>
1717

18-
| Parameter | Type | Default | Description |
19-
| ------------------- | ------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20-
| options | object | `null` | |
21-
| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). |
22-
| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. |
23-
| 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. |
24-
| options.position.x | number | `0` | The x coordinate. |
25-
| options.position.y | number | `0` | The y coordinate. |
18+
| Parameter | Type | Default | Description |
19+
| ------------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20+
| options | object | `null` | |
21+
| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). |
22+
| options.noWaitAfter | boolean | `false` | If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. |
23+
| 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. |
24+
| options.position.x | number | `0` | The x coordinate. |
25+
| options.position.y | number | `0` | The y coordinate. |
2626
| 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/). |
27-
| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. |
27+
| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. |
2828

2929
</TableWithNestedRows>
3030

@@ -55,7 +55,7 @@ export const options = {
5555
};
5656

5757
export default async function () {
58-
const page = await newPage();
58+
const page = await browser.newPage();
5959
await page.goto('https://test.k6.io/browser.php');
6060

6161
const checkbox = await page.$('#checkbox1');

docs/sources/next/javascript-api/k6-browser/elementhandle/waitforelementstate.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Waits for the element to reach the specified state.
99

1010
<TableWithNestedRows>
1111

12-
| Parameter | Type | Default | Description |
13-
| --------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
14-
| state | string | | The state to wait for. This can be one of `visible`, `hidden`, `stable`, `enabled`, `disabled`, or `editable`. |
12+
| Parameter | Type | Default | Description |
13+
| --------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
14+
| state | string | | The state to wait for. This can be one of `visible`, `hidden`, `stable`, `enabled`, `disabled`, or `editable`. |
1515
| 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/). |
1616

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

52-
await close();
52+
await page.close();
5353
}
5454
```
5555

0 commit comments

Comments
 (0)