Skip to content

Commit d277269

Browse files
committed
docs: more page API documentation
1 parent d999fdd commit d277269

21 files changed

+735
-33
lines changed

src/data/markdown/docs/02 javascript api/07 k6-experimental/01 browser/08 Locator/textcontent--options--.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,8 @@ export default async function () {
3333

3434
await page.goto('https://test.k6.io/browser.php');
3535
const options = page.locator("#checkbox1");
36-
console.log(options.textContent()); /* Zero
37-
One
38-
Two
39-
Three
40-
Four
41-
Five */
42-
}
36+
console.log(options.textContent());
37+
}
4338
```
4439

4540
</CodeGroup>

src/data/markdown/docs/02 javascript api/07 k6-experimental/01 browser/10 Page.md

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,21 @@ Page provides methods to interact with a single tab in a running web browser ins
4747
| [page.setContent(html, [options])](/javascript-api/k6-experimental/browser/page/setcontent/) | Sets the supplied html string to the current page. |
4848
| [page.setDefaultNavigationTimeout(timeout)](/javascript-api/k6-experimental/browser/page/setdefaultnavigationtimeout/) | Changes the navigation timeout for [page.goto(url, [options])](/javascript-api/k6-experimental/browser/page/goto/), [page.reload([options])](/javascript-api/k6-experimental/browser/page/reload/), [page.setContent(html, [options])](/javascript-api/k6-experimental/browser/page/setcontent/), and [page.waitForNavigation([options])](/javascript-api/k6-experimental/browser/page/waitfornavigation/) |
4949
| [page.setDefaultTimeout(timeout)](/javascript-api/k6-experimental/browser/page/setdefaulttimeout/) | Changes the timeout for all the methods accepting a `timeout` option. |
50-
51-
52-
53-
54-
55-
56-
<!--
57-
| <a href="https://playwright.dev/docs/api/class-page#page-set-extra-http-headers" target="_blank" >page.setExtraHTTPHeaders(headers)</a> | - | - |
58-
| <a href="https://playwright.dev/docs/api/class-page#page-set-input-files" target="_blank" >page.setInputFiles(selector, files[, options])</a> | - | - |
59-
| <a href="https://playwright.dev/docs/api/class-page#page-set-viewport-size" target="_blank" >page.setViewportSize(viewportSize)</a> | - | - |
60-
| <a href="https://playwright.dev/docs/api/class-page#page-tap" target="_blank" >page.tap(selector[, options])</a> | - | - |
61-
| <a href="https://playwright.dev/docs/api/class-page#page-text-content" target="_blank" >page.textContent(selector[, options])</a> | - | - |
62-
| <a href="https://playwright.dev/docs/api/class-page#page-title" target="_blank" >page.title()</a> | - | - |
63-
| <a href="https://playwright.dev/docs/api/class-page#page-type" target="_blank" >page.type(selector, text[, options])</a> | - | - |
64-
| <a href="https://playwright.dev/docs/api/class-page#page-uncheck" target="_blank" >page.uncheck(selector[, options])</a> | - | - |
65-
| <a href="https://playwright.dev/docs/api/class-page#page-unroute" target="_blank" >page.unroute(url[, handler])</a> | - | - |
66-
| <a href="https://playwright.dev/docs/api/class-page#page-url" target="_blank" >page.url()</a> | - | - |
67-
| <a href="https://playwright.dev/docs/api/class-page#page-viewport-size" target="_blank" >page.viewportSize()</a> | - | - |
68-
| <a href="https://playwright.dev/docs/api/class-page#page-wait-for-function" target="_blank" >page.waitForFunction(pageFunction[, arg, options])</a> | - | - |
69-
| <a href="https://playwright.dev/docs/api/class-page#page-wait-for-load-state" target="_blank" >page.waitForLoadState([state, options])</a> | - | - |
70-
| <a href="https://playwright.dev/docs/api/class-page#page-wait-for-navigation" target="_blank" >page.waitForNavigation([options])</a> | - | - |
71-
| <a href="https://playwright.dev/docs/api/class-page#page-wait-for-request" target="_blank" >page.waitForRequest(urlOrPredicate[, options])</a> | - | - |
72-
| <a href="https://playwright.dev/docs/api/class-page#page-wait-for-response" target="_blank" >page.waitForResponse(urlOrPredicate[, options])</a> | - | - |
73-
| <a href="https://playwright.dev/docs/api/class-page#page-wait-for-selector" target="_blank" >page.waitForSelector(selector[, options])</a> | - | - |
74-
| <a href="https://playwright.dev/docs/api/class-page#page-wait-for-timeout" target="_blank" >page.waitForTimeout(timeout)</a> | - | - |
75-
| <a href="https://playwright.dev/docs/api/class-page#page-touchscreen" target="_blank" >touchscreen</a> | - | - | -->
50+
| [page.setExtraHTTPHeaders(headers)](/javascript-api/k6-experimental/browser/page/setextrahttpheaders/) | Sets extra HTTP headers which will be sent with subsequent HTTP requests. |
51+
| [page.setViewportSize(viewportSize)](/javascript-api/k6-experimental/browser/page/setviewportsize/) | Updates the page's width and height. |
52+
| [page.tap(selector, [options])](/javascript-api/k6-experimental/browser/page/tap/) | Taps the first element that matches the selector. |
53+
| [page.textContent(selector, [options])](/javascript-api/k6-experimental/browser/page/textcontent/) | Returns the `element.textContent`. |
54+
| [page.title()](/javascript-api/k6-experimental/browser/page/title/) | Returns the page's title. |
55+
| [page.type(selector, text, [options])](/javascript-api/k6-experimental/browser/page/type/) | Types the `text` in the first element found that matches the selector. |
56+
| [page.touchScreen()](/javascript-api/k6-experimental/browser/page/touchscreen/) | Returns the [Touchscreen](/javascript-api/k6-experimental/browser/touchscreen/) instance to interact with a virtual touchscreen on the page. |
57+
| [page.uncheck(selector, [options])](/javascript-api/k6-experimental/browser/page/uncheck/) | Unselects an input checkbox. |
58+
| [page.url()](/javascript-api/k6-experimental/browser/page/url/) | Returns the page's URL. |
59+
| [page.viewportSize()](/javascript-api/k6-experimental/browser/page/viewportsize/) | Returns the page's size (width and height). |
60+
| [page.waitForFunction(pageFunction, arg, [options])](/javascript-api/k6-experimental/browser/page/waitforfunction/) | Returns when the `pageFunction` returns a truthy value. |
61+
| [page.waitForLoadState(state, [options])](/javascript-api/k6-experimental/browser/page/waitforloadstate/) | Waits for the given load state to be reached. |
62+
| [page.waitForNavigation([options])](/javascript-api/k6-experimental/browser/page/waitfornavigation/) | Waits for the given navigation lifecycle event to occur and returns the main resource response. |
63+
| [page.waitForSelector(selector, [options])](/javascript-api/k6-experimental/browser/page/waitforselector/) | Returns when element specified by selector satisfies `state` option. |
64+
| [page.waitForTimeout(timeout)](/javascript-api/k6-experimental/browser/page/waitfortimeout/) | Waits for the given `timeout` in milliseconds. |
65+
| [page.workers()](/javascript-api/k6-experimental/browser/page/workers/) | Returns an array of the dedicated WebWorkers associated with the page. |
66+
| [page.$(selector)](/javascript-api/k6-experimental/browser/page/$/) | Finds an element matching the specified selector within the page. |
67+
| [page.$$(selector)](/javascript-api/k6-experimental/browser/page/$$/) | Finds all elements matching the specified selector within the page. |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: '$$(selector)'
3+
excerpt: 'Browser module: page.$$(selector) method'
4+
---
5+
6+
<Blockquote mod="note" title="">
7+
8+
Use locator-based [`page.locator(selector)`](/javascript-api/k6-experimental/browser/page/locator/) instead.
9+
10+
</Blockquote>
11+
12+
The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to `[]`.
13+
14+
### Example
15+
16+
<CodeGroup labels={[]}>
17+
18+
```javascript
19+
import { chromium } from 'k6/experimental/browser';
20+
21+
export default async function () {
22+
const browser = chromium.launch();
23+
const page = browser.newPage();
24+
25+
await page.goto('https://test.k6.io/browser.php');
26+
page.$$('#text1')[0].type('hello world');
27+
}
28+
```
29+
30+
</CodeGroup>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: '$(selector)'
3+
excerpt: 'Browser module: page.$(selector) method'
4+
---
5+
6+
<Blockquote mod="note" title="">
7+
8+
Use locator-based [`page.locator(selector)`](/javascript-api/k6-experimental/browser/page/locator/) instead.
9+
10+
</Blockquote>
11+
12+
The method finds an element matching the specified selector within the page. If no elements match the selector, the return value resolves to `null`. To wait for an element on the page, use [locator.waitFor([options])](/javascript-api/k6-experimental/browser/locator/waitfor/).
13+
14+
### Example
15+
16+
<CodeGroup labels={[]}>
17+
18+
```javascript
19+
import { chromium } from 'k6/experimental/browser';
20+
21+
export default async function () {
22+
const browser = chromium.launch();
23+
const page = browser.newPage();
24+
25+
await page.goto('https://test.k6.io/browser.php');
26+
page.$('#text1').type('hello world');
27+
}
28+
```
29+
30+
</CodeGroup>

src/data/markdown/docs/02 javascript api/07 k6-experimental/01 browser/10 Page/isclosed--options--.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ title: 'isClosed()'
33
excerpt: 'Browser module: page.isClosed() method'
44
---
55

6+
<Blockquote mod="attention">
7+
8+
This method has **known issues**. For details, refer to [#878](https://github.com/grafana/xk6-browser/issues/878).
9+
10+
</Blockquote>
11+
612
Checks if the page has been closed.
713

814
### Example
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: 'setExtraHTTPHeaders(headers)'
3+
excerpt: 'Browser module: page.setExtraHTTPHeaders(headers) method'
4+
---
5+
6+
This sets extra HTTP headers which will be sent with subsequent HTTP requests.
7+
8+
| Parameter | Type | Default | Description |
9+
|-----------------|--------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
10+
| headers | Object<string, string> | | An object containing the additional HTTP headers. All header values must be strings. |
11+
12+
### Example
13+
14+
<CodeGroup labels={[]}>
15+
16+
```javascript
17+
import { chromium } from 'k6/experimental/browser';
18+
19+
export default async function () {
20+
const browser = chromium.launch();
21+
const page = browser.newPage();
22+
23+
page.setExtraHTTPHeaders({ 'foo': 'bar' });
24+
const url = await page.goto('https://test.k6.io/browser.php');
25+
26+
console.log(url.request().headers().foo) // prints bar
27+
}
28+
```
29+
30+
</CodeGroup>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: 'setViewportSize(viewportSize)'
3+
excerpt: 'Browser module: page.setViewportSize(viewportSize) method'
4+
---
5+
6+
This will update the page's width and height.
7+
8+
<TableWithNestedRows>
9+
10+
| Parameter | Type | Default | Description |
11+
|-----------------|--------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
12+
| viewportSize | Object | | An object containing the additional HTTP headers. All header values must be strings. |
13+
| viewportSize.width | number | | Page width in pixels. |
14+
| viewportSize.height | number | | Page height in pixels. |
15+
16+
</TableWithNestedRows>
17+
18+
### Example
19+
20+
<CodeGroup labels={[]}>
21+
22+
```javascript
23+
import { chromium } from 'k6/experimental/browser';
24+
25+
export default async function () {
26+
const browser = chromium.launch();
27+
const page = browser.newPage();
28+
29+
page.setViewportSize({
30+
width: 640,
31+
height: 480,
32+
});
33+
await page.goto('https://test.k6.io/browser.php');
34+
}
35+
```
36+
37+
</CodeGroup>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: 'tap(selector, [options])'
3+
excerpt: 'Browser module: locator.tap(selector, [options]) method'
4+
---
5+
6+
<Blockquote mod="note" title="">
7+
8+
Use locator-based [`locator.tap([options])`](/javascript-api/k6-experimental/browser/locator/tap/) instead.
9+
10+
</Blockquote>
11+
12+
Tap the first element that matches the selector.
13+
14+
<TableWithNestedRows>
15+
16+
| Parameter | Type | Default | Description |
17+
|---------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
18+
| selector | string | `''` | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. |
19+
| options | object | `null` | |
20+
| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). |
21+
| options.modifiers | string[] | `null` | `Alt`, `Control`, `Meta` or `Shift` modifiers keys pressed during the action. If not specified, currently pressed modifiers are used. |
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. |
26+
| options.strict | boolean| `false` | When `true`, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception. |
27+
| options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/) or [Page](/javascript-api/k6-experimental/browser/page/). |
28+
| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. |
29+
30+
</TableWithNestedRows>
31+
32+
### Example
33+
34+
<CodeGroup labels={[]}>
35+
36+
```javascript
37+
import { chromium } from 'k6/experimental/browser';
38+
39+
export default async function () {
40+
const browser = chromium.launch();
41+
const page = browser.newPage();
42+
43+
await page.goto('https://test.k6.io/browser.php');
44+
page.tap('#numbers-options');
45+
}
46+
```
47+
48+
</CodeGroup>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: 'textContent(selector, [options])'
3+
excerpt: 'Browser module: locator.textContent(selector, [options]) method'
4+
---
5+
6+
<Blockquote mod="note" title="">
7+
8+
Use locator-based [`locator.textContent([options])`](/javascript-api/k6-experimental/browser/locator/textcontent/) instead.
9+
10+
</Blockquote>
11+
12+
Returns the `element.textContent`.
13+
14+
<TableWithNestedRows>
15+
16+
| Parameter | Type | Default | Description |
17+
|-----------------|--------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
18+
| selector | string | `''` | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. |
19+
| options | object | `null` | |
20+
| options.strict | boolean| `false` | When `true`, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception. |
21+
| options.timeout | number | `30000` | Maximum time in milliseconds. Pass `0` to disable the timeout. Default is overridden by the `setDefaultTimeout` option on [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/) or [Page](/javascript-api/k6-experimental/browser/page/). |
22+
23+
</TableWithNestedRows>
24+
25+
### Returns
26+
27+
| Type | Description |
28+
|--------|-------------------------------------------|
29+
| string | The text content of the selector or null. |
30+
31+
### Example
32+
33+
<CodeGroup labels={[]}>
34+
35+
```javascript
36+
import { chromium } from 'k6/experimental/browser';
37+
38+
export default async function () {
39+
const browser = chromium.launch();
40+
const page = browser.newPage();
41+
42+
await page.goto('https://test.k6.io/browser.php');
43+
console.log(page.textContent('#checkbox1'));
44+
}
45+
```
46+
47+
</CodeGroup>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: 'title()'
3+
excerpt: 'Browser module: page.title() method'
4+
---
5+
6+
Returns the page's title.
7+
8+
### Example
9+
10+
<CodeGroup labels={[]}>
11+
12+
```javascript
13+
import { chromium } from 'k6/experimental/browser';
14+
15+
export default async function () {
16+
const browser = chromium.launch();
17+
const page = browser.newPage();
18+
19+
await page.goto('https://test.k6.io/browser.php');
20+
console.log(page.title());
21+
}
22+
```
23+
24+
</CodeGroup>

0 commit comments

Comments
 (0)