Skip to content

Commit 2fcc436

Browse files
authored
Merge pull request #1169 from grafana/page-api-docs
k6 browser page api docs
2 parents f7ede57 + 3ad2f60 commit 2fcc436

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2585
-116
lines changed

.vale/Vocab/docs/accept.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,6 @@ webvital
205205
variadic
206206
shm
207207
srgb
208-
kwallet
208+
kwallet
209+
referer
210+
scrollable

src/data/markdown/docs/02 javascript api/07 k6-experimental/01 browser/01 Browser class/newcontext--options--.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Creates and returns a new [BrowserContext](/javascript-api/k6-experimental/brows
2828
| options.locale | string | system | Specifies the user's locale, such as `'en-US'`, `'tr-TR'`, etc. |
2929
| options.offline | boolean | `false` | Whether to emulate an offline network. |
3030
| options.permissions | Array | `null` | Permissions to grant for the context's pages. See [browserContext.grantPermissions()](/javascript-api/k6-experimental/browser/browsercontext/#browsercontext-grantpermissions-permissions-options) for the options. |
31-
| options.reducedMotion | string | `'no-preference'` | Minimizes the amount of motion by emulating the 'prefers-reduced-motion' media feature. It can be one of `'reduce'` and `'no-preference'`. See [page.emulateMedia()](/javascript-api/k6-experimental/browser/page/#page-emulatemedia-options) for the options. |
31+
| options.reducedMotion | string | `'no-preference'` | Minimizes the amount of motion by emulating the 'prefers-reduced-motion' media feature. It can be one of `'reduce'` and `'no-preference'`. See [page.emulateMedia()](/javascript-api/k6-experimental/browser/page/emulatemedia) for the options. |
3232
| options.screen | object | `{'width': 1280, 'height': 720}` | Sets a window screen size for all pages in the context. It can only be used when the viewport is set. |
3333
| options.screen.width | number | `1280` | Page width in pixels. |
3434
| options.screen.height | number | `720` | Page height in pixels. |

src/data/markdown/docs/02 javascript api/07 k6-experimental/01 browser/01 Browser class/newpage--options--.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Creates a new [Page](/javascript-api/k6-experimental/browser/page/) in a new [Br
2828
| options.locale | string | system | Specifies the user's locale, such as `'en-US'`, `'tr-TR'`, etc. |
2929
| options.offline | boolean | `false` | Whether to emulate an offline network. |
3030
| options.permissions | Array | `null` | Permissions to grant for the context's pages. See [browserContext.grantPermissions()](/javascript-api/k6-experimental/browser/browsercontext/#browsercontext-grantpermissions-permissions-options) for the options. |
31-
| options.reducedMotion | string | `'no-preference'` | Minimizes the amount of motion by emulating the 'prefers-reduced-motion' media feature. It can be one of `'reduce'` and `'no-preference'`. See [page.emulateMedia()](/javascript-api/k6-experimental/browser/page/#page-emulatemedia-options) for the options. |
31+
| options.reducedMotion | string | `'no-preference'` | Minimizes the amount of motion by emulating the 'prefers-reduced-motion' media feature. It can be one of `'reduce'` and `'no-preference'`. See [page.emulateMedia()](/javascript-api/k6-experimental/browser/page/emulatemedia) for the options. |
3232
| options.screen | object | `{'width': 1280, 'height': 720}` | Sets a window screen size for all pages in the context. It can only be used when the viewport is set. |
3333
| options.screen.width | number | `1280` | Page width in pixels. |
3434
| options.screen.height | number | `720` | Page height in pixels. |

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>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: "Page"
3+
excerpt: "Browser module: Page Class"
4+
---
5+
6+
Page provides methods to interact with a single tab in a running web browser. A single [BrowserContext](https://k6.io/docs/javascript-api/k6-experimental/browser/browsercontext/) can have many `pages`.
7+
8+
| Method | Description |
9+
|---------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
10+
| [page.bringToFront()](/javascript-api/k6-experimental/browser/page/bringtofront/) | Activates a browser tab. |
11+
| [page.check(selector[, options])](/javascript-api/k6-experimental/browser/page/check/) | Select the input checkbox. |
12+
| [page.click(selector[, options])](/javascript-api/k6-experimental/browser/page/click/) | Clicks on an element matching a `selector`. |
13+
| [page.close()](/javascript-api/k6-experimental/browser/page/close/) | Closes a tab that the `page` is associated with. |
14+
| [page.content()](/javascript-api/k6-experimental/browser/page/content/) | Gets the HTML contents of the page. |
15+
| [page.context()](/javascript-api/k6-experimental/browser/page/context/) | Gets the [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/) that the page belongs to. |
16+
| [page.dblclick(selector[, options])](/javascript-api/k6-experimental/browser/page/dblclick/) | With the [Mouse](https://k6.io/docs/javascript-api/k6-experimental/browser/mouse/), double click on an element matching the provided `selector`. |
17+
| [page.dispatchEvent(selector, type, eventInit[, options])](/javascript-api/k6-experimental/browser/page/dispatchevent/) | Dispatches HTML DOM event types e.g. `'click'` |
18+
| [page.$(selector)](/javascript-api/k6-experimental/browser/page/page-$/) | Finds an element matching the specified `selector` within the page. |
19+
| [page.$$(selector)](/javascript-api/k6-experimental/browser/page/page-$$/) | Finds all elements matching the specified `selector` within the page. |
20+
| [page.emulateMedia([options])](/javascript-api/k6-experimental/browser/page/emulatemedia/) | Changes the CSS media type and the color scheme feature. |
21+
| [page.emulateVisionDeficiency(type)](/javascript-api/k6-experimental/browser/page/emulatevisiondeficiency/) | Emulates your website with the specified vision deficiency `type`. |
22+
| [page.evaluate(pageFunction[, arg])](/javascript-api/k6-experimental/browser/page/evaluate/) | Returns the value of the `pageFunction` invocation. |
23+
| [page.evaluateHandle(pageFunction[, arg])](/javascript-api/k6-experimental/browser/page/evaluate/) | Returns the value of the `pageFunction` invocation as a [JSHandle](javascript-api/k6-experimental/browser/jshandle/). |
24+
| [page.fill(selector, value[, options])](/javascript-api/k6-experimental/browser/page/fill/) | Fill an `input`, `textarea` or `contenteditable` element with the provided value. |
25+
| [page.focus(selector[, options])](/javascript-api/k6-experimental/browser/page/focus/) | Fetches an element with `selector` and focuses on it. |
26+
| [page.frames()](/javascript-api/k6-experimental/browser/page/frames/) | Returns an array of frames on the page. |
27+
| [page.getAttribute(selector, name[, options])](/javascript-api/k6-experimental/browser/page/getattribute/) | Returns the element attribute value for the given attribute name. |
28+
| [page.goto(url[, options])](/javascript-api/k6-experimental/browser/page/goto/) | Navigates to the specified `url`. |
29+
| [page.hover(selector[, options])](/javascript-api/k6-experimental/browser/page/hover/) | Hovers over an element matching `selector`. |
30+
| [page.innerHTML(selector[, options])](/javascript-api/k6-experimental/browser/page/innerhtml/) | Returns the `element.innerHTML`. |
31+
| [page.innerText(selector[, options])](/javascript-api/k6-experimental/browser/page/innertext/) | Returns the `element.innerText`. |
32+
| [page.inputValue(selector[, options])](/javascript-api/k6-experimental/browser/page/inputvalue/) | Returns `input.value` for the selected `input`, `textarea` or `select` element. |
33+
| [page.isChecked(selector[, options])](/javascript-api/k6-experimental/browser/page/ischecked/) | Checks to see if the `checkbox` `input` type is selected or not. |
34+
| [page.isClosed()](/javascript-api/k6-experimental/browser/page/isclosed/) <BWIPT id="878"/> | Checks if the page has been closed. |
35+
| [page.isDisabled(selector[, options])](/javascript-api/k6-experimental/browser/page/isdisabled/) | Checks if the element is `disabled`. |
36+
| [page.isEditable(selector[, options])](/javascript-api/k6-experimental/browser/page/iseditable/) | Checks if the element is `editable`. |
37+
| [page.isEnabled(selector[, options])](/javascript-api/k6-experimental/browser/page/isenabbled/) | Checks if the element is `enabled`. |
38+
| [page.isHidden(selector[, options])](/javascript-api/k6-experimental/browser/page/ishidden/) | Checks if the element is `hidden`. |
39+
| [page.isVisible(selector[, options])](/javascript-api/k6-experimental/browser/page/isvisible/) | Checks if the element is `visible`. |
40+
| [page.keyboard](/javascript-api/k6-experimental/browser/page/keyboard/) | Returns the [Keyboard](javascript-api/k6-experimental/browser/keyboard/) instance to interact with a virtual keyboard on the page. |
41+
| [page.locator(selector)](/javascript-api/k6-experimental/browser/page/locator/) | Returns a [Locator](/javascript-api/k6-experimental/browser/locator/) for the given `selector`. |
42+
| [page.mainFrame()](/javascript-api/k6-experimental/browser/page/mainframe/) | Returns the page's main [Frame](https://k6.io/docs/javascript-api/k6-experimental/browser/frame/). |
43+
| [page.mouse](/javascript-api/k6-experimental/browser/page/mouse/) | Returns the [Mouse](javascript-api/k6-experimental/browser/mouse/) instance to interact with a virtual mouse on the page. |
44+
| [page.opener()](/javascript-api/k6-experimental/browser/page/opener/) | Returns the `page` that opened the current `page`. |
45+
| [page.press(selector, key[, options])](/javascript-api/k6-experimental/browser/page/press/) | Focuses the element, and then presses the given `key` on the [Keyboard](https://k6.io/docs/javascript-api/k6-experimental/browser/keyboard/). |
46+
| [page.reload([options])](/javascript-api/k6-experimental/browser/page/reload/) | Reloads the current page. |
47+
| [page.screenshot([options])](/javascript-api/k6-experimental/browser/page/screenshot/) | Returns a buffer with the captured screenshot from the web browser. |
48+
| [page.selectOption(selector, values[, options])](/javascript-api/k6-experimental/browser/page/selectoption/) | Selects one or more options which match the values from a `<select>` element. |
49+
| [page.setContent(html[, options])](/javascript-api/k6-experimental/browser/page/setcontent/) | Sets the supplied HTML string to the current page. |
50+
| [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/) |
51+
| [page.setDefaultTimeout(timeout)](/javascript-api/k6-experimental/browser/page/setdefaulttimeout/) | Changes the timeout for all the methods accepting a `timeout` option. |
52+
| [page.setExtraHTTPHeaders(headers)](/javascript-api/k6-experimental/browser/page/setextrahttpheaders/) | Sets extra HTTP headers which will be sent with subsequent HTTP requests. |
53+
| [page.setViewportSize(viewportSize)](/javascript-api/k6-experimental/browser/page/setviewportsize/) | Updates the `page`'s width and height. |
54+
| [page.tap(selector[, options])](/javascript-api/k6-experimental/browser/page/tap/) | Taps the first element that matches the `selector`. |
55+
| [page.textContent(selector[, options])](/javascript-api/k6-experimental/browser/page/textcontent/) | Returns the `element.textContent`. |
56+
| [page.title()](/javascript-api/k6-experimental/browser/page/title/) | Returns the `page`'s title. |
57+
| [page.type(selector, text[, options])](/javascript-api/k6-experimental/browser/page/type/) | Types the `text` in the first element found that matches the `selector`. |
58+
| [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. |
59+
| [page.uncheck(selector[, options])](/javascript-api/k6-experimental/browser/page/uncheck/) | Unselects an input `checkbox` element. |
60+
| [page.url()](/javascript-api/k6-experimental/browser/page/url/) | Returns the `page`'s URL. |
61+
| [page.viewportSize()](/javascript-api/k6-experimental/browser/page/viewportsize/) | Returns the `page`'s size (width and height). |
62+
| [page.waitForFunction(pageFunction, arg[, options])](/javascript-api/k6-experimental/browser/page/waitforfunction/) | Returns when the `pageFunction` returns a truthy value. |
63+
| [page.waitForLoadState(state[, options])](/javascript-api/k6-experimental/browser/page/waitforloadstate/) <BWIPT id="880"/> | Waits for the given load `state` to be reached. |
64+
| [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. |
65+
| [page.waitForSelector(selector[, options])](/javascript-api/k6-experimental/browser/page/waitforselector/) | Returns when element specified by selector satisfies `state` option. |
66+
| [page.waitForTimeout(timeout)](/javascript-api/k6-experimental/browser/page/waitfortimeout/) | Waits for the given `timeout` in milliseconds. |
67+
| [page.workers()](/javascript-api/k6-experimental/browser/page/workers/) | Returns an array of the dedicated [WebWorkers](https://k6.io/docs/javascript-api/k6-experimental/browser/worker/) associated with the page. |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: 'bringToFront()'
3+
excerpt: 'Browser module: page.bringToFront method'
4+
---
5+
6+
Activates the browser tab which brings the page in focus to allow actions to be performed onto it.
7+
8+
9+
### Example
10+
11+
<CodeGroup labels={[]}>
12+
13+
```javascript
14+
import { chromium } from 'k6/experimental/browser';
15+
16+
export default async function () {
17+
const browser = chromium.launch();
18+
const page = browser.newPage();
19+
20+
await page.goto('https://test.k6.io/browser.php');
21+
22+
// perform other actions that might open up a different tab, taking focus away from the initial page.
23+
24+
page.bringToFront();
25+
}
26+
```
27+
28+
</CodeGroup>

0 commit comments

Comments
 (0)