diff --git a/gatsby-node.js b/gatsby-node.js index d3507b9bed..c75cd65162 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1479,6 +1479,8 @@ const createRedirects = ({ actions }) => { '/javascript-api/xk6-browser/jshandle/', '/javascript-api/k6-x-browser/keyboard/': '/javascript-api/xk6-browser/keyboard/', + '/javascript-api/k6-x-browser/locator/': + '/javascript-api/xk6-browser/locator/', '/javascript-api/k6-x-browser/mouse/': '/javascript-api/xk6-browser/mouse/', '/javascript-api/k6-x-browser/page/': '/javascript-api/xk6-browser/page/', '/javascript-api/k6-x-browser/request/': @@ -1487,8 +1489,6 @@ const createRedirects = ({ actions }) => { '/javascript-api/xk6-browser/response/', '/javascript-api/k6-x-browser/touchscreen/': '/javascript-api/xk6-browser/touchscreen/', - '/javascript-api/k6-x-browser/launcher/': - '/javascript-api/xk6-browser/launcher/', ...newJavascriptURLsRedirects, }; diff --git a/src/components/shared/browser-class-list/browser-class-list.view.js b/src/components/shared/browser-class-list/browser-class-list.view.js index c3f29f73a1..dc85e4c96b 100644 --- a/src/components/shared/browser-class-list/browser-class-list.view.js +++ b/src/components/shared/browser-class-list/browser-class-list.view.js @@ -32,6 +32,10 @@ const links = [ title: 'Keyboard', url: '/javascript-api/xk6-browser/keyboard', }, + { + title: 'Locator', + url: '/javascript-api/xk6-browser/locator', + }, { title: 'Mouse', url: '/javascript-api/xk6-browser/mouse/', diff --git a/src/components/shared/browser-compatibility/browser-compatibility.view.js b/src/components/shared/browser-compatibility/browser-compatibility.view.js deleted file mode 100644 index fc28937df1..0000000000 --- a/src/components/shared/browser-compatibility/browser-compatibility.view.js +++ /dev/null @@ -1,18 +0,0 @@ -import Blockquote from 'components/shared/blockquote'; -import { Link } from 'gatsby'; -import React from 'react'; - -const BrowserCompatibility = () => ( -
-

- xk6-browser aims for rough - compatibility with the{' '} - - Playwright API for NodeJS - - . -

-

Note that k6 APIs are synchronous.

-
-); -export default BrowserCompatibility; diff --git a/src/components/shared/browser-compatibility/index.js b/src/components/shared/browser-compatibility/index.js deleted file mode 100644 index 52bfe4beb1..0000000000 --- a/src/components/shared/browser-compatibility/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import BrowserCompatibility from './browser-compatibility.view'; - -export default BrowserCompatibility; diff --git a/src/components/shared/browser-docs-wip/browser-docs-wip.view.js b/src/components/shared/browser-docs-wip/browser-docs-wip.view.js new file mode 100644 index 0000000000..98135b345b --- /dev/null +++ b/src/components/shared/browser-docs-wip/browser-docs-wip.view.js @@ -0,0 +1,12 @@ +import Blockquote from 'components/shared/blockquote'; +import React from 'react'; + +const BrowserDocsWIP = () => ( +
+

+ This documentation is a work in progress, and some of the functionality + that is listed below may not behave as expected. +

+
+); +export default BrowserDocsWIP; diff --git a/src/components/shared/browser-docs-wip/index.js b/src/components/shared/browser-docs-wip/index.js new file mode 100644 index 0000000000..540e24e038 --- /dev/null +++ b/src/components/shared/browser-docs-wip/index.js @@ -0,0 +1,3 @@ +import BrowserDocsWIP from './browser-docs-wip.view'; + +export default BrowserDocsWIP; diff --git a/src/components/shared/table-wrapper/table-wrapper.module.scss b/src/components/shared/table-wrapper/table-wrapper.module.scss index cf4314c991..8c456f8e26 100644 --- a/src/components/shared/table-wrapper/table-wrapper.module.scss +++ b/src/components/shared/table-wrapper/table-wrapper.module.scss @@ -1,15 +1,13 @@ .table-wrapper { width: 100%; overflow: auto; - table { - td:nth-child(1) { - white-space: nowrap; - } - @include sm-down { - tr td:nth-of-type(3) { - width: 100%; - min-width: 230px; //usually 3rd column contains text which is being squished - } + td:nth-child(1) { + white-space: nowrap; + } + @include sm-down { + tr td:nth-of-type(3) { + width: 100%; + min-width: 230px; //usually 3rd column contains text which is being squished } } } diff --git a/src/components/templates/doc-page/doc-page-content/doc-page-content.view.js b/src/components/templates/doc-page/doc-page-content/doc-page-content.view.js index 38ee19b9fb..acae73ea47 100644 --- a/src/components/templates/doc-page/doc-page-content/doc-page-content.view.js +++ b/src/components/templates/doc-page/doc-page-content/doc-page-content.view.js @@ -4,7 +4,7 @@ import Glossary from 'components/pages/doc-page/glossary'; import TableOfContents from 'components/pages/doc-page/table-of-contents'; import Blockquote from 'components/shared/blockquote'; import BrowserClassList from 'components/shared/browser-class-list'; -import BrowserCompatibility from 'components/shared/browser-compatibility'; +import BrowserDocsWIP from 'components/shared/browser-docs-wip'; import BrowserWIP from 'components/shared/browser-wip'; import { Code, CodeInline, CodeGroup } from 'components/shared/code'; import Collapsible from 'components/shared/collapsible'; @@ -34,7 +34,7 @@ const componentsForNativeReplacement = { CodeGroup, Collapsible, CodeInline, - BrowserCompatibility, + BrowserDocsWIP, BrowserClassList, BrowserWIP, InstallationInstructions, diff --git a/src/data/markdown/docs/02 javascript api/alternative main modules/30 k6-x-browser.md b/src/data/markdown/docs/02 javascript api/alternative main modules/30 k6-x-browser.md index cb58dff15e..94f21cb3f4 100644 --- a/src/data/markdown/docs/02 javascript api/alternative main modules/30 k6-x-browser.md +++ b/src/data/markdown/docs/02 javascript api/alternative main modules/30 k6-x-browser.md @@ -16,6 +16,7 @@ Here's a list of the fully (✅) or partially (🚧) implemented classes of the - 🚧 [Frame](/javascript-api/xk6-browser/frame/) - ✅ [JSHandle](/javascript-api/xk6-browser/jshandle) - ✅ [Keyboard](/javascript-api/xk6-browser/keyboard) +- 🚧 [Locator](/javascript-api/xk6-browser/locator/) - ✅ [Mouse](/javascript-api/xk6-browser/mouse/) - 🚧 [Page](/javascript-api/xk6-browser/page/) - 🚧 [Request](/javascript-api/xk6-browser/request/) diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser.md new file mode 100644 index 0000000000..3478b8dfb4 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser.md @@ -0,0 +1,35 @@ +--- +title: "Browser" +excerpt: "xk6-browser: Browser Class" +--- + +The `Browser` class is the entry point for all your tests, and it is what interacts with the actual web browser via [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) (CDP). It manages: +- [BrowserContext](/javascript-api/xk6-browser/browsercontext/) which is where you can set a variety of attributes to control the behavior of pages; +- and [Page](/javascript-api/xk6-browser/page/) which is where your rendered site is displayed. + +A new Browser instance (hence a new browser process) can be created using the `launch()` method of the `chromium` module from `'k6/x/browser'`. + +| Method | Description | +|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------| +| [browser.close()](/javascript-api/xk6-browser/browser/close) | Closes the browser and all of its pages (if any were opened). | +| [browser.contexts()](/javascript-api/xk6-browser/browser/contexts) | Allows you to access all open [BrowserContext](/javascript-api/xk6-browser/browsercontext/)s. | +| [browser.isConnected](/javascript-api/xk6-browser/browser/isconnected) | Indicates whether the [CDP](https://chromedevtools.github.io/devtools-protocol/) connection to the browser process is active or not. | +| [browser.newContext([options])](/javascript-api/xk6-browser/browser/newcontext/) | Creates and returns a new [BrowserContext](/javascript-api/xk6-browser/browsercontext/). | +| [browser.newPage([options])](/javascript-api/xk6-browser/browser/newpage) | Creates a new [Page](/javascript-api/xk6-browser/page/) in a new [BrowserContext](/javascript-api/xk6-browser/browsercontext/) and returns the page. | +| [browser.on('disconnected')](/javascript-api/xk6-browser/browser/on) | Detects the disconnected event from the browser application. | +| [browser.version()](/javascript-api/xk6-browser/browser/version) | Returns the browser application's version. | + +### Example + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + const context = browser.newContext(); + const page = context.newPage(); + const res = page.goto('https://test.k6.io/'); + page.close(); + browser.close(); +} +``` diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/close.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/close.md new file mode 100644 index 0000000000..77472ba241 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/close.md @@ -0,0 +1,28 @@ +--- +title: 'close()' +excerpt: 'xk6-browser: Browser.close method' +--- + +Closes the browser and all of its pages (if any were opened). + +The [Browser](/javascript-api/xk6-browser/browser/) object cannot be used anymore and is considered disposed of. + + +### Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + const context = browser.newContext(); + context.newPage(); + + context.close(); + browser.close(); +} +``` + + \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/contexts.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/contexts.md new file mode 100644 index 0000000000..113561a7d3 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/contexts.md @@ -0,0 +1,32 @@ +--- +title: 'contexts()' +excerpt: 'xk6-browser: Browser.contexts method' +--- + +Allows you to access all open [BrowserContext](/javascript-api/xk6-browser/browsercontext/)s. + +### Returns + +| Type | Description | +| ----- | ------------------------------------------------------------------------------ | +| Array | Array of [BrowserContext](/javascript-api/xk6-browser/browsercontext/) objects | + + +### Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + console.log(browser.contexts().length); // 0 + + const context = browser.newContext(); +console.log(browser.contexts().length); // 1 + + context.close(); + browser.close(); +} +``` diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/isconnected.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/isconnected.md new file mode 100644 index 0000000000..9ad233909e --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/isconnected.md @@ -0,0 +1,37 @@ +--- +title: 'isConnected()' +excerpt: 'xk6-browser: Browser.isConnected method' +--- + +
+ +There is a known issue with this feature. See [issue #453](/~https://github.com/grafana/xk6-browser/issues/453) for details. + +
+ +Indicates whether the [CDP](https://chromedevtools.github.io/devtools-protocol/) connection to the browser process is active or not. + +### Returns + +| Type | Description | +| ------- | ---------------------------------------------------------------------------------------------- | +| boolean | Returns `true` if [Browser](/javascript-api/xk6-browser/browser/) is connected to the browser application. Otherwise, returns `false`. | + + +### Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + const isConnected = browser.isConnected(); + console.log(isConnected); // true + + browser.close(); +} +``` + + \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/newcontext--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/newcontext--options--.md new file mode 100644 index 0000000000..0674e3bc5a --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/newcontext--options--.md @@ -0,0 +1,74 @@ +--- +title: 'newContext([options])' +excerpt: 'xk6-browser: Browser.newContext method' +--- + +Creates and returns a new [BrowserContext](/javascript-api/xk6-browser/browsercontext/). + + + +| Parameter | Type | Default | Description | +|---------------------------------------------|---------|----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| options | object | `null` | | +| options.bypassCSP | boolean | `false` | Whether to bypass a page's Content-Security-Policy. | +| options.colorScheme | string | `'light'` | Whether to display a page in dark or light mode by emulating the 'prefers-colors-scheme' media feature. It can be one of `'light'`, `'dark'`, `'no-preference'`. | +| options.deviceScaleFactor | number | `1` | Sets the resolution ratio in physical pixels to the resolution in CSS pixels i.e. if set higher than `1`, then images will look sharper on high pixel density screens. See an [example](#devicescalefactor-example) below. | +| options.extraHTTPHeaders | object | `null` | Contains additional HTTP headers to be sent with every request, where the keys are HTTP headers and values are HTTP header values. | +| options.geolocation | object | `null` | Sets the user's geographical location. | +| options.geolocation.latitude | number | `0` | Latitude should be between `-90` and `90`. | +| options.geolocation.longitude | number | `0` | Longitude should be between `-180` and `180`. | +| options.geolocation.accuracy | number | `0` | Accuracy should only be a non-negative number. Defaults to `0`. | +| options.hasTouch | boolean | `false` | Whether to simulate a device with touch events. | +| options.httpCredentials | object | `null` | Sets the credentials for HTTP authentication using Basic Auth. | +| options.httpCredentials.username | string | `''` | Username to pass to the web browser for Basic HTTP Authentication. | +| options.httpCredentials.password | string | `''` | Password to pass to the web browser for Basic HTTP Authentication. | +| options.ignoreHTTPSErrors | boolean | `false` | Whether to ignore HTTPS errors that may be caused by invalid certificates. | +| options.isMobile | boolean | `false` | Whether to simulate a mobile device. | +| options.javaScriptEnabled | boolean | `true` | Whether to activate JavaScript support for the context. | +| options.locale | string | system | Specifies the user's locale, such as `'en-US'`, `'tr-TR'`, etc. | +| options.offline | boolean | `false` | Whether to emulate an offline network. | +| options.permissions | Array | `null` | Permissions to grant for the context's pages. See [browserContext.grantPermissions()](/javascript-api/xk6-browser/browsercontext#browsercontext-grantpermissions-permissions-options) for the options. | +| 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/xk6-browser/page#page-emulatemedia-options) for the options. | +| 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. | +| options.screen.width | number | `1280` | Page width in pixels. | +| options.screen.height | number | `720` | Page height in pixels. | +| options.timezoneID | string | system | Changes the context's timezone. See [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs. | +| options.userAgent | string | browser | Specifies the user agent to use in the context. | +| options.viewport | object | `{'width': 1280, 'height': 720}` | Sets a viewport size for all pages in the context. `null` disables the default viewport. | +| options.viewport.width | number | `1280` | Page width in pixels. | +| options.viewport.height | number | `720` | Page height in pixels. | + + + +### Returns + +| Type | Description | +| ------ | -------------------------------------------------------------------- | +| object | [BrowserContext](/javascript-api/xk6-browser/browsercontext/) object | + + +### deviceScaleFactor example + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch({ + headless: false, + }); + + const context = browser.newContext({ + viewport: { + width: 375, + height: 812, + }, + deviceScaleFactor: 3, + }); + const page = context.newPage(); + + page.goto('https://test.k6.io/'); + + page.close(); + browser.close(); +} +``` diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/newpage--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/newpage--options--.md new file mode 100644 index 0000000000..e1e3724c94 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/newpage--options--.md @@ -0,0 +1,72 @@ +--- +title: 'newPage([options])' +excerpt: 'xk6-browser: Browser.newPage method' +--- + +Creates a new [Page](/javascript-api/xk6-browser/page/) in a new [BrowserContext](/javascript-api/xk6-browser/browsercontext/) and returns the page. You do not need to create a new `BrowserContext` prior to using `newPage`. + + + +| Parameter | Type | Default | Description | +|---------------------------------------------|---------|----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| options | object | `null` | | +| options.bypassCSP | boolean | `false` | Whether to bypass a page's Content-Security-Policy. | +| options.colorScheme | string | `'light'` | Whether to display a page in dark or light mode by emulating the 'prefers-colors-scheme' media feature. It can be one of `'light'`, `'dark'`, `'no-preference'`. | +| options.deviceScaleFactor | number | `1` | Sets the resolution ratio in physical pixels to the resolution in CSS pixels i.e. if set higher than `1`, then images will look sharper on high pixel density screens. See an [example](#devicescalefactor-example) below. | +| options.extraHTTPHeaders | object | `null` | Contains additional HTTP headers to be sent with every request, where the keys are HTTP headers and values are HTTP header values. | +| options.geolocation | object | `null` | Sets the user's geographical location. | +| options.geolocation.latitude | number | `0` | Latitude should be between `-90` and `90`. | +| options.geolocation.longitude | number | `0` | Longitude should be between `-180` and `180`. | +| options.geolocation.accuracy | number | `0` | Accuracy should only be a non-negative number. Defaults to `0`. | +| options.hasTouch | boolean | `false` | Whether to simulate a device with touch events. | +| options.httpCredentials | object | `null` | Sets the credentials for HTTP authentication using Basic Auth. | +| options.httpCredentials.username | string | `''` | Username to pass to the web browser for Basic HTTP Authentication. | +| options.httpCredentials.password | string | `''` | Password to pass to the web browser for Basic HTTP Authentication. | +| options.ignoreHTTPSErrors | boolean | `false` | Whether to ignore HTTPS errors that may be caused by invalid certificates. | +| options.isMobile | boolean | `false` | Whether to simulate a mobile device. | +| options.javaScriptEnabled | boolean | `true` | Whether to activate JavaScript support for the context. | +| options.locale | string | system | Specifies the user's locale, such as `'en-US'`, `'tr-TR'`, etc. | +| options.offline | boolean | `false` | Whether to emulate an offline network. | +| options.permissions | Array | `null` | Permissions to grant for the context's pages. See [browserContext.grantPermissions()](/javascript-api/xk6-browser/browsercontext#browsercontext-grantpermissions-permissions-options) for the options. | +| 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/xk6-browser/page#page-emulatemedia-options) for the options. | +| 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. | +| options.screen.width | number | `1280` | Page width in pixels. | +| options.screen.height | number | `720` | Page height in pixels. | +| options.timezoneID | string | system | Changes the context's timezone. See [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs. | +| options.userAgent | string | browser | Specifies the user agent to use in the context. | +| options.viewport | object | `{'width': 1280, 'height': 720}` | Sets a viewport size for all pages in the context. `null` disables the default viewport. | +| options.viewport.width | number | `1280` | Page width in pixels. | +| options.viewport.height | number | `720` | Page height in pixels. | + + + +### Returns + +| Type | Description | +| ------ | ------------------------------------------------ | +| object | [Page](/javascript-api/xk6-browser/page/) object | + +### deviceScaleFactor example + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch({ + headless: false, + }); + + const page = browser.newPage({ + viewport: { + width: 375, + height: 812, + }, + deviceScaleFactor: 3, + }); + + page.goto('https://test.k6.io/'); + + page.close(); + browser.close(); +} +``` diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/on--event--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/on--event--.md new file mode 100644 index 0000000000..b31ca2d114 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/on--event--.md @@ -0,0 +1,65 @@ +--- +title: 'on(event)' +excerpt: 'xk6-browser: Browser.on method' +--- + +Detects events from the browser application. + +| Parameter | Type | Description | +| --------- | ------ | -------------------------------------------------- | +| event | string | The only accepted event value is `'disconnected'`. | + +### Returns + +The returned promise will be resolved when the [Browser](/javascript-api/xk6-browser/browser/) disconnects from the browser application. Possible reasons for this might be happening as follows: + +* Closed or crashed browser application. +* Calling of the [browser.close()](/javascript-api/xk6-browser/browser/close) method. + +| Type | Description | +| ------- | ------------------------------------------------------------------------------- | +| promise | On returns a Promise that is resolved when the browser process is disconnected. | + +### Example + + + +```javascript +import { chromium } from 'k6/x/browser'; +import { check, sleep } from 'k6'; + +export default function() { + const browser = chromium.launch(); + + check(browser, { + 'should be connected after launch': browser.isConnected(), + }); + + const handlerCalled = Symbol(); + + const p = browser.on('disconnected') + // The promise resolve/success handler + .then((val) => { + check(browser, { + 'should be disconnected on event': !browser.isConnected(), + }); + return handlerCalled; + // The promise reject/failure handler + }, (val) => { + console.error(`promise rejected: ${val}`); + }); + + p.then((val) => { + check(val, { + 'the browser.on success handler should be called': val === handlerCalled, + }); + }); + + check(browser, { + 'should be connected before ending iteration': browser.isConnected(), + }); + + // Disconnect from the browser instance. + browser.close(); +} +``` \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/version.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/version.md new file mode 100644 index 0000000000..6b24e33afd --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01 Browser/version.md @@ -0,0 +1,31 @@ +--- +title: 'version()' +excerpt: 'xk6-browser: Browser.version method' +--- + +Returns the browser application's version. + +### Returns + +| Type | Description | +| ------ | ---------------------------------- | +| string | The browser application's version. | + + +### Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + const version = browser.version(); + console.log(version); // 105.0.5195.52 + + browser.close(); +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser.md deleted file mode 100644 index dafd25ef6c..0000000000 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/01-browser.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: "Browser" -excerpt: "xk6-browser: Browser Class" ---- - - - -```javascript -import launcher from 'k6/x/browser'; -export default function () { - const browser = launcher.launch('chromium'); - const context = browser.newContext(); - const page = context.newPage(); - page.close(); - browser.close(); -} -``` - -- [browser.close()](#browser-close) -- [browser.contexts()](#browser-contexts) -- [browser.isConnected()](#browser-isconnected) -- 🚧 [browser.newBrowserCDPSession()](#browser-newbrowsercdpsession) -- [browser.newContext([options])](#browser-newcontext-options) -- [browser.newPage([options])](#browser-newpage-options) -- 🚧 [browser.on()](#browser-on) -- ❌ [browser.startTracing()](#browser-starttracing) -- ❌ [browser.stopTracing()](#browser-stoptracing) -- [browser.version()](#browser-version) - - -## browser.close() - -## browser.contexts() - -## browser.isConnected() - -## browser.newBrowserCDPSession() - -## browser.newContext([options]) - -## browser.newPage([options]) - -## browser.on() - -## browser.startTracing() - -## browser.stopTracing() - -## browser.version() diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext.md new file mode 100644 index 0000000000..cc87d47a9e --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext.md @@ -0,0 +1,26 @@ +--- +title: "BrowserContext" +excerpt: "xk6-browser: BrowserContext Class" +--- + +`BrowserContext`s provide a way to operate multiple independent sessions, with separate pages, cache, and cookies. A default `BrowserContext` is created when a [Browser](/javascript-api/xk6-browser/browser) is launched. + +The [Browser](/javascript-api/xk6-browser/browser) type is used to create a new `BrowserContext`. + +If a [page](/javascript-api/xk6-browser/page) opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's `BrowserContext`. + + +| Method | Description | +|-------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------| +| [BrowserContext.browser()](/javascript-api/xk6-browser/browsercontext/browser/) | Returns the [Browser](/javascript-api/xk6-browser/browser) instance that this `BrowserContext` belongs to. | +| [BrowserContext.clearCookies()](/javascript-api/xk6-browser/browsercontext/clearcookies/) | Clear the `BrowserContext`'s cookies. | +| [BrowserContext.clearPermissions()](/javascript-api/xk6-browser/browsercontext/clearpermissions) | Clears all permission overrides for the `BrowserContext`. | +| [BrowserContext.close()](/javascript-api/xk6-browser/browsercontext/close) | Close the `BrowserContext` and all its [page](/javascript-api/xk6-browser/page)s. | +| [BrowserContext.grantPermissions(permissions[, options])](/javascript-api/xk6-browser/browsercontext/grantpermissions) | Grants specified permissions to the `BrowserContext`. | +| [BrowserContext.newPage()](/javascript-api/xk6-browser/browsercontext/newpage) | Uses the `BrowserContext` to create a new [Page](/javascript-api/xk6-browser/page/) and returns it. | +| [BrowserContext.pages()](/javascript-api/xk6-browser/browsercontext/pages) | Returns a list of [page](/javascript-api/xk6-browser/page)s that belongs to the `BrowserContext`. | +| [BrowserContext.setDefaultNavigationTimeout(timeout)](/javascript-api/xk6-browser/browsercontext/setdefaultnavigationtimeout) | Sets the default navigation timeout in milliseconds. | +| [BrowserContext.setDefaultTimeout(timeout)](/javascript-api/xk6-browser/browsercontext/setdefaulttimeout) | Sets the default maximum timeout for all methods accepting a timeout option in milliseconds. | +| [BrowserContext.setGeolocation(geolocation)](/javascript-api/xk6-browser/browsercontext/setgeolocation) | Sets the `BrowserContext`'s geolocation. | +| [BrowserContext.setOffline(offline)](/javascript-api/xk6-browser/browsercontext/setoffline) | Toggles the `BrowserContext`'s connectivity on/off. | +| [BrowserContext.waitForEvent(event[, optionsOrPredicate])](/javascript-api/xk6-browser/browsercontext/waitforevent) | Waits for the event to fire and passes its value into the predicate function. | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/browser.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/browser.md new file mode 100644 index 0000000000..15e3500866 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/browser.md @@ -0,0 +1,31 @@ +--- +title: 'browser()' +excerpt: 'Returns the browser instance that this BrowserContext belongs to.' +--- + +Returns the [browser](/javascript-api/xk6-browser/browser) instance that this `BrowserContext` belongs to. + + +### Returns + +| Type | Description | +| ---------------------------------------------- | ----------------------- | +| [Browser](/javascript-api/xk6-browser/browser/) | The Browser instance. | + + +### Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + const context = browser.newContext(); + const contextBrowser = context.browser(); + contextBrowser.close(); +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/clearCookies.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/clearCookies.md new file mode 100644 index 0000000000..d1e852d6e9 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/clearCookies.md @@ -0,0 +1,12 @@ +--- +title: 'clearCookies()' +excerpt: 'Clears context cookies.' +--- + +
+ +There is a known issue with this feature. See [issue #442](/~https://github.com/grafana/xk6-browser/issues/442) for details. + +
+ +Clears the `BrowserContext`'s cookies. diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/clearPermissions.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/clearPermissions.md new file mode 100644 index 0000000000..b0354eb455 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/clearPermissions.md @@ -0,0 +1,28 @@ +--- +title: 'clearPermissions()' +excerpt: 'Clears all permission overrides for the BrowserContext.' +--- + +
+ +There is a known issue with this feature. See [issue #443](/~https://github.com/grafana/xk6-browser/issues/443) for details. + +
+ +Clears all permission overrides for the `BrowserContext`. + + +### Example + + + + + +```javascript +const context = browser.newContext(); +context.grantPermissions(['clipboard-read']); +// do stuff ... +context.clearPermissions(); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/close.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/close.md new file mode 100644 index 0000000000..ed71344a1e --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/close.md @@ -0,0 +1,26 @@ +--- +title: 'close()' +excerpt: 'Close the BrowserContext and all its pages.' +--- + +Close the `BrowserContext` and all its [page](/javascript-api/xk6-browser/page)s. The `BrowserContext` is unusable after this call and a new one must be created. This is typically called to cleanup before ending the test. + + +### Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + const context = browser.newContext(); + context.newPage(); + + context.close(); + browser.close(); +} +``` + + \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/grantPermissions.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/grantPermissions.md new file mode 100644 index 0000000000..f3376895c3 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/grantPermissions.md @@ -0,0 +1,32 @@ +--- +title: 'grantPermissions(permissions[, options])' +excerpt: 'Grants specified permissions to the BrowserContext.' +--- + +Grants specified permissions to the `BrowserContext`. Only grants corresponding permissions to the given origin if specified. + + + +| Parameter | Type | Description | +|----------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| permissions | array | A string array of permissions to grant. A permission can be one of the following values: `'geolocation'`, `'midi'`, `'midi-sysex'` (system-exclusive midi), `'notifications'`, `'camera'`, `'microphone'`, `'background-sync'`, `'ambient-light-sensor'`, `'accelerometer'`, `'gyroscope'`, `'magnetometer'`, `'accessibility-events'`, `'clipboard-read'`, `'clipboard-write'`, `'payment-handler'`. | +| options | object | Optional. | +| options.origin | string | The [origin](https://developer.mozilla.org/en-US/docs/Glossary/Origin) to grant permissions to, e.g. `'https://example.com'`. | + + + + +### Example + + + + + +```javascript +const context = browser.newContext(); +context.grantPermissions(['clipboard-read', 'clipboard-write'], { + origin: 'https://example.com/', +}); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/newPage.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/newPage.md new file mode 100644 index 0000000000..1f287343e6 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/newPage.md @@ -0,0 +1,35 @@ +--- +title: 'newPage()' +excerpt: 'Creates a new page inside this BrowserContext.' +--- + +Uses the `BrowserContext` to create a new [Page](/javascript-api/xk6-browser/page/) and returns it. + + +### Returns + +| Type | Description | +| ------ | ------------------------------------------------------- | +| object | A new [Page](/javascript-api/xk6-browser/page/) object. | + + +### Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + const context = browser.newContext(); + const page = context.newPage(); + + page.goto('https://test.k6.io/browser.php'); + + page.close(); + browser.close(); +} +``` + + \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/pages.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/pages.md new file mode 100644 index 0000000000..ecc29cdcfc --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/pages.md @@ -0,0 +1,41 @@ +--- +title: 'pages()' +excerpt: 'Returns a list of pages inside this BrowserContext.' +--- + +
+ +There is a known issue with this feature. See [issue #444](/~https://github.com/grafana/xk6-browser/issues/444) for details. + +
+ +Returns all open [Page](/javascript-api/xk6-browser/page/)s in the `BrowserContext`. + + +### Returns + +| Type | Description | +| ------ | --------------- | +| array | All open pages. | + + +### Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + const context = browser.newContext(); + context.newPage(); + const pages = context.pages(); + console.log(pages.length); // 1 + + context.close(); + browser.close(); +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setDefaultNavigationTimeout.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setDefaultNavigationTimeout.md new file mode 100644 index 0000000000..72845fe311 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setDefaultNavigationTimeout.md @@ -0,0 +1,32 @@ +--- +title: 'setDefaultNavigationTimeout(timeout)' +excerpt: 'Sets the default navigation timeout in milliseconds.' +--- + +
+ +There is a known issue with this feature. See [issue #445](/~https://github.com/grafana/xk6-browser/issues/445) for details. + +
+ +Sets the default maximum navigation timeout for [Page.goto()](/javascript-api/xk6-browser/page/goto/). + +| Parameter | Type | Default | Description | +|-----------|--------|--------------------------|------------------------------| +| timeout | number | Dependent on the action. | The timeout in milliseconds. | + + +### Example + + + + + +```javascript +const context = browser.newContext(); +const page = context.newPage(); +context.setDefaultNavigationTimeout(1000); // 1s +page.goto('https://httpbin.test.k6.io/delay/5'); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setDefaultTimeout.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setDefaultTimeout.md new file mode 100644 index 0000000000..7a3e14bc9e --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setDefaultTimeout.md @@ -0,0 +1,32 @@ +--- +title: 'setDefaultTimeout(timeout)' +excerpt: 'Sets the default timeout in milliseconds.' +--- + +
+ +There is a known issue with this feature. See [issue #456](/~https://github.com/grafana/xk6-browser/issues/456) for details. + +
+ +Sets the default maximum timeout for all methods accepting a `timeout` option in milliseconds. + +| Parameter | Type | Default | Description | +|-----------|--------|--------------------------|------------------------------| +| timeout | number | Dependent on the action. | The timeout in milliseconds. | + + +### Example + + + + + +```javascript +const context = browser.newContext(); +context.setDefaultTimeout(1000); // 1s +const page = context.newPage(); +page.click('h2'); // times out +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setGeolocation.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setGeolocation.md new file mode 100644 index 0000000000..655dd58f61 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setGeolocation.md @@ -0,0 +1,36 @@ +--- +title: 'setGeolocation(geolocation)' +excerpt: "Sets the BrowserContext's geolocation." +--- + +
+ +There is a known issue with this feature. See [issue #435](/~https://github.com/grafana/xk6-browser/issues/435) for details. + +
+ +Sets the context's geolocation. + + + +| Parameter | Type | Default | Description | +|-----------------------|--------|---------|---------------------------------------| +| geolocation | object | `null` | | +| geolocation.latitude | number | `0` | Latitude between -90 and 90. | +| geolocation.longitude | number | `0` | Latitude between -180 and 180. | +| geolocation.accuracy | number | `0` | Optional non-negative accuracy value. | + + + +### Example + + + + + +```javascript +const context = browser.newContext(); +context.setGeolocation({latitude: 59.95, longitude: 30.31667}); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setOffline.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setOffline.md new file mode 100644 index 0000000000..51fc31bde1 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/setOffline.md @@ -0,0 +1,34 @@ +--- +title: 'setOffline(offline)' +excerpt: "Toggles the BrowserContext's connectivity on/off." +--- + +Toggles the `BrowserContext`'s connectivity on/off. + +| Parameter | Type | Default | Description | +|-----------|---------|---------|---------------------------------------------------------------------------------------------| +| offline | boolean | `false` | Whether to emulate the `BrowserContext` being disconnected (`true`) or connected (`false`). | + + +### Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + const context = browser.newContext(); + + context.setOffline(true); + + const page = context.newPage(); + page.goto('https://test.k6.io/browser.php'); // Will not be able to load the page + + context.close(); + browser.close(); +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/waitForEvent.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/waitForEvent.md new file mode 100644 index 0000000000..a61eb36802 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02 BrowserContext/waitForEvent.md @@ -0,0 +1,31 @@ +--- +title: 'waitForEvent(event[, optionsOrPredicate])' +excerpt: 'Waits for event to fire and passes its value into the predicate function.' +--- + +
+ +This method is a Work In Progress. It requires async functionality and returning a `Promise` to be useful in scripts. See issue #447 for details. + +Consider using sync methods [Page.waitForNavigation()](/javascript-api/xk6-browser/page/waitfornavigation) and [Page.waitForSelector()](/javascript-api/xk6-browser/page/waitforselector) instead. + +
+ +Waits for the event to fire and passes its value into the predicate function. Returns the event data value when the predicate returns `true`. + + + +| Parameter | Type | Default | Description | +|------------------------------|------------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------| +| event | string | `null` | Name of event to wait for. **NOTE**: Currently this argument is disregarded, and `waitForEvent` will always wait for `'close'` or `'page'` events. | +| optionsOrPredicate | function\|object | `null` | Optional. If it's a function, the `'page'` event data will be passed to it and it must return `true` to continue. | +| optionsOrPredicate.predicate | function | `null` | Function that will be called when the `'page'` event is emitted. The event data will be passed to it and it must return `true` to continue. | +| optionsOrPredicate.timeout | number | `30000` | Maximum time to wait in milliseconds. Pass `0` to disable timeout. | + + + +### Returns + +| Type | Description | +| ------ | ------------------------------------------------ | +| object | [Page](/javascript-api/xk6-browser/page/) object | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02-browser-context.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02-browser-context.md deleted file mode 100644 index 3442692e22..0000000000 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/02-browser-context.md +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: "BrowserContext" -excerpt: "xk6-browser: BrowserContext Class" ---- - - - -```javascript -import launcher from 'k6/x/browser'; - -export default function () { - const browser = launcher.launch('chromium', { headless: false }); - const context = browser.newContext(); - const page = context.newPage(); - page.goto('http://whatsmyuseragent.org/'); - page.close(); - browser.close(); -} -``` - - - -- [browserContext.addInitScript(script[, arg])](#browsercontext-addinitscript-script-arg) -- [browserContext.clearCookies()](#browsercontext-clearcookies) -- [browserContext.clearPermissions()](#browsercontext-clearpermissions) -- [browserContext.grantPermissions(permissions[, options])](#browsercontext-grantpermissions-permissions-options) -- [browserContext.close()](#browsercontext-close) -- [browserContext.newPage()](#browsercontext-newpage) -- [browserContext.pages()](#browsercontext-pages) -- [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontext-setdefaultnavigationtimeout-timeout) -- [browserContext.setDefaultTimeout(timeout)](#browsercontext-setdefaulttimeout-timeout) -- [browserContext.setGeolocation(geolocation)](#browsercontext-setgeolocation-geolocation) -- [browserContext.setHTTPCredentials(httpCredentials)](#browsercontext-sethttpcredentials-httpcredentials) -- [browserContext.setOffline(offline)](#browsercontext-setoffline-offline) -- [Missing Playwright APIs](#missing-playwright-apis) - - - -## browserContext.addInitScript(script[, arg]) - -## browserContext.clearCookies() - -## browserContext.clearPermissions() - -## browserContext.grantPermissions(permissions[, options]) - -## browserContext.close() - -## browserContext.newPage() - -## browserContext.pages() - -## browserContext.setDefaultNavigationTimeout(timeout) - -## browserContext.setDefaultTimeout(timeout) - -## browserContext.setGeolocation(geolocation) - - -## browserContext.setHTTPCredentials(httpCredentials) - - -## browserContext.setOffline(offline) - - -## Missing Playwright APIs - - - - -- [addCookies()](https://playwright.dev/docs/api/class-browsercontext/#browsercontextaddcookiescookies) -- [backgroundPages()](https://playwright.dev/docs/api/class-browsercontext#browser-context-background-pages) -- [browser()](https://playwright.dev/docs/api/class-browsercontext#browser-context-browser) -- [cookies()](https://playwright.dev/docs/api/class-browsercontext#browser-context-cookies) -- [exposeBinding()](https://playwright.dev/docs/api/class-browsercontext#browser-context-expose-binding) -- [exposeFunction()](https://playwright.dev/docs/api/class-browsercontext#browser-context-expose-function) -- [newCDPSession()](https://playwright.dev/docs/api/class-browsercontext#browser-context-new-cdp-session) -- [serviceWorkers()](https://playwright.dev/docs/api/class-browsercontext/#browser-context-service-workers) -- [setExtraHTTPHeaders()](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-extra-http-headers) -- [storageState()](https://playwright.dev/docs/api/class-browsercontext#browser-context-storage-state) -- [request](https://playwright.dev/docs/api/class-browsercontext#browser-context-request) -- [tracing](https://playwright.dev/docs/api/class-browsercontext#browser-context-tracing) - - - -The following missing APIs depends on [event-loop support in k6](/~https://github.com/grafana/k6/issues/882): - - - -- [on(event)](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-background-page) -- [route()](https://playwright.dev/docs/api/class-browsercontext#browser-context-route) -- [unroute()](https://playwright.dev/docs/api/class-browsercontext#browser-context-unroute) -- [waitForEvent()](https://playwright.dev/docs/api/class-browsercontext#browser-context-wait-for-event) - - \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType.md new file mode 100644 index 0000000000..8240a9c219 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType.md @@ -0,0 +1,40 @@ +--- +title: "BrowserType" +excerpt: "xk6-browser: BrowserType Class" +--- + +The `BrowserType` is the entry point into launching a browser process; `chromium` is currently the only supported `BrowserType`. To use it, import `chromium` from the top level module `k6/x/browser`. + +| Method | Description | +|-----------------------------------------------------------------------------------------|------------------------------------------------------------------------------| +| browserType.connect([options]) | Connect attaches k6 browser to an existing browser instance. | +| [browserType.executablePath()](/javascript-api/xk6-browser/browsertype/executablepath/) | Returns the path where the extension expects to find the browser executable. | +| [browserType.launch([options])](/javascript-api/xk6-browser/browsertype/launch/) | Launches a new browser process. | +| browserType.launchPersistentContext(userDataDir, [options]) | Launches the browser with persistent storage. | +| [browserType.name()](/javascript-api/xk6-browser/browsertype/name/) | Returns the name of the `BrowserType`; currently it will return `chromium`. | + + +## Example + + + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch(); + const context = browser.newContext(); + const page = context.newPage(); + + page.goto('http://whatsmyuseragent.org/'); + page.screenshot({ path: `example-chromium.png` }); + + page.close(); + browser.close(); +} +``` + + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType/executablePath.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType/executablePath.md new file mode 100644 index 0000000000..a978032adf --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType/executablePath.md @@ -0,0 +1,28 @@ +--- +title: 'executablePath()' +excerpt: 'xk6-browser: BrowserType.executablePath method' +--- + +Returns the path where the extension expects to find the browser executable. + + +### Returns + +| Type | Description | +|--------|--------------------------------------| +| string | The expected browser executable path | + + +## Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const execPath = chromium.executablePath(); + console.log(execPath); + ... +} +``` \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType/launch--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType/launch--options--.md new file mode 100644 index 0000000000..0c295f7be3 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType/launch--options--.md @@ -0,0 +1,59 @@ +--- +title: 'launch([options])' +excerpt: 'xk6-browser: BrowserType.launch method' +--- + +Launches a new browser process. + +| Parameter | Type | Default | Description | +|-------------------|----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| args | string[] | `null` | Extra command line arguments to include when launching browser process. See [this link](https://peter.sh/experiments/chromium-command-line-switches/) for a list of Chromium arguments. Note that arguments should not start with `--` (see the [example](#example)). | +| debug | boolean | `false` | All CDP messages and internal fine grained logs will be logged if set to `true`. | +| devtools | boolean | `false` | Open up developer tools in the browser by default. | +| env | string[] | `null` | Environment variables to set before launching browser process. | +| executablePath | string | `null` | Override search for browser executable in favor of specified absolute path. | +| headless | boolean | `true` | Show browser GUI or not. | +| ignoreDefaultArgs | string[] | `null` | Ignore any of the default arguments included when launching browser process. | +| proxy | string | `null` | Specify to set browser's proxy configuration. | +| slowMo | string | `null` | Slow down input actions and navigation by the specified time e.g. `'500ms'`. | +| timeout | string | `'30s'` | Default timeout to use for various actions and navigation. | + + +### Returns + +| Type | Description | +|--------|--------------------------------------------------------| +| object | [Browser](/javascript-api/xk6-browser/browser/) object | + + +## Example + + + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch({ + args: ['show-property-changed-rects'], + debug: true, + devtools: true, + executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', + headless: false, + slowMo: '500ms', + timeout: '30s', + }); + const context = browser.newContext(); + const page = context.newPage(); + + page.goto('http://whatsmyuseragent.org/'); + page.screenshot({ path: `example-chromium.png` }); + + page.close(); + browser.close(); +} +``` + + \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType/name.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType/name.md new file mode 100644 index 0000000000..75cdc22c1c --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03 BrowserType/name.md @@ -0,0 +1,28 @@ +--- +title: 'name()' +excerpt: 'xk6-browser: BrowserType.name method' +--- + +Returns the name of the `BrowserType`; currently it will return `chromium`. + + +### Returns + +| Type | Description | +|--------|------------------------------| +| string | Currently returns `chromium` | + + +## Example + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const name = chromium.name(); + console.log(name); + ... +} +``` \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03-browser-type.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03-browser-type.md deleted file mode 100644 index c0bf4581f8..0000000000 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/03-browser-type.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: "BrowserType" -excerpt: "xk6-browser: BrowserType Class" ---- - - - -```javascript -import launcher from 'k6/x/browser'; - -export default function () { - const browser = launcher.launch('chromium', { - args: [], // Extra commandline arguments to include when launching browser process - debug: true, // Log all CDP messages to k6 logging subsystem - devtools: true, // Open up developer tools in the browser by default - env: {}, // Environment variables to set before launching browser process - executablePath: null, // Override search for browser executable in favor of specified absolute path - headless: false, // Show browser UI or not - ignoreDefaultArgs: [], // Ignore any of the default arguments included when launching browser process - proxy: {}, // Specify to set browser's proxy config - slowMo: '500ms', // Slow down input actions and navigations by specified time - timeout: '30s', // Default timeout to use for various actions and navigations - }); - browser.close(); -} -``` - -- [browserType.connect()](#browsertype-connect) -- [browserType.connectOverCDP()](#browsertype-connectovercdp) -- [browserType.executablePath()](#browsertype-executablepath) -- [browserType.launch([options])](#browsertype-launch-options) -- [browserType.launchPersistentContext()](#browsertype-launchpersistentcontext) -- [browserType.launchServer()](#browsertype-launchserver) -- [browserType.name()](#browsertype-name) - - -## browserType.connect() - -## browserType.connectOverCDP() - -## browserType.executablePath() - -## browserType.launch([options]) - -## browserType.launchPersistentContext() - -## browserType.launchServer() - -## browserType.name() - diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/04-element-handle.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/04-element-handle.md index 76a7855a79..7045e4412a 100644 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/04-element-handle.md +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/04-element-handle.md @@ -3,13 +3,56 @@ title: "ElementHandle" excerpt: "xk6-browser: ElementHandle Class" --- - + + +## Supported APIs + +| Method | Playwright Relevant Distinctions | +| - | - | +| elementHandle.$(selector) | - | +| elementHandle.$$(selector) | - | +| elementHandle.boundingBox() | - | +| elementHandle.check([options]) | - | +| elementHandle.click([options]) | - | +| elementHandle.contentFrame() | - | +| elementHandle.dblclick([options]) | - | +| elementHandle.dispatchEvent(type[, eventInit]) | - | +| elementHandle.fill(value[, options]) | - | +| elementHandle.focus() | - | +| elementHandle.getAttribute() | - | +| elementHandle.hover([options]) | - | +| elementHandle.innerHTML() | - | +| elementHandle.innerText() | - | +| elementHandle.inputValue([options]) | - | +| elementHandle.isChecked() | - | +| elementHandle.isDisabled() | - | +| elementHandle.isEditable() | - | +| elementHandle.isEnabled() | - | +| elementHandle.isHidden() | - | +| elementHandle.isVisible() | - | +| elementHandle.ownerFrame() | - | +| elementHandle.press(key[, options]) | - | +| elementHandle.screenshot([options]) | - | +| elementHandle.scrollIntoViewIfNeeded([options]) | - | +| elementHandle.selectOptions(values[, options]) | - | +| elementHandle.selectText([options]) | - | +| elementHandle.setChecked(checked[, options]) | - | +| elementHandle.tap([options]) | - | +| elementHandle.textContent() | - | +| elementHandle.type(text[, options]) | - | +| elementHandle.uncheck([options]) | - | +| elementHandle.waitForElementState(state[, options]) | - | +| elementHandle.waitForSelector(selector[, options]) | - | + +## Examples + + ```javascript -import launcher from 'k6/x/browser'; +import { chromium } from 'k6/x/browser'; export default function () { - const browser = launcher.launch('chromium', { + const browser = chromium.launch({ headless: false, slowMo: '500ms', // slow down by 500ms }); @@ -34,84 +77,46 @@ export default function () { } ``` + -- [elementHandle.$(selector)](#elementhandle---selector) -- [elementHandle.$$(selector)](#elementhandle----selector) -- [elementHandle.$eval()](#elementhandle--eval) -- [elementHandle.$$eval()](#elementhandle---eval) -- [elementHandle.boundingBox()](#elementhandle-boundingbox) -- [elementHandle.check([options])](#elementhandle-check-options) -- [elementHandle.click([options])](#elementhandle-click-options) -- [elementHandle.contentFrame()](#elementhandle-contentframe) -- [elementHandle.dblclick([options])](#elementhandle-dblclick-options) -- [elementHandle.dispatchEvent(type[, eventInit])](#elementhandle-dispatchevent-type-eventinit) -- [elementHandle.fill(value[, options])](#elementhandle-fill-value-options) -- [elementHandle.focus()](#elementhandle-focus) -- [elementHandle.getAttribute()](#elementhandle-getattribute) -- [elementHandle.hover([options])](#elementhandle-hover-options) -- [elementHandle.innerHTML()](#elementhandle-innerhtml) -- [elementHandle.innerText()](#elementhandle-innertext) -- [elementHandle.inputValue([options])](#elementhandle-inputvalue-options) -- [elementHandle.isChecked()](#elementhandle-ischecked) -- [elementHandle.isDisabled()](#elementhandle-isdisabled) -- [elementHandle.isEditable()](#elementhandle-iseditable) -- [elementHandle.isEnabled()](#elementhandle-isenabled) -- [elementHandle.isHidden()](#elementhandle-ishidden) -- [elementHandle.isVisible()](#elementhandle-isvisible) -- [elementHandle.ownerFrame()](#elementhandle-ownerframe) -- [elementHandle.press(key[, options])](#elementhandle-press-key-options) -- [elementHandle.screenshot([options])](#elementhandle-screenshot-options) -- [elementHandle.scrollIntoViewIfNeeded([options])](#elementhandle-scrollintoviewifneeded-options) -- [elementHandle.selectOptions(values[, options])](#elementhandle-selectoptions-values-options) -- [elementHandle.selectText([options])](#elementhandle-selecttext-options) -- [elementHandle.setChecked(checked[, options])](#elementhandle-setchecked-checked-options) -- [elementHandle.setInputFiles()](#elementhandle-setinputfiles) -- [elementHandle.tap([options])](#elementhandle-tap-options) -- [elementHandle.textContent()](#elementhandle-textcontent) -- [elementHandle.type(text[, options])](#elementhandle-type-text-options) -- [elementHandle.uncheck([options])](#elementhandle-uncheck-options) -- [elementHandle.waitForElementState(state[, options])](#elementhandle-waitforelementstate-state-options) -- [elementHandle.waitForSelector(selector[, options])](#elementhandle-waitforselector-selector-options) - - -## elementHandle.$(selector) -## elementHandle.$$(selector) -## elementHandle.$eval() -## elementHandle.$$eval() -## elementHandle.boundingBox() -## elementHandle.check([options]) -## elementHandle.click([options]) -## elementHandle.contentFrame() -## elementHandle.dblclick([options]) -## elementHandle.dispatchEvent(type[, eventInit]) -## elementHandle.fill(value[, options]) -## elementHandle.focus() -## elementHandle.getAttribute() -## elementHandle.hover([options]) -## elementHandle.innerHTML() -## elementHandle.innerText() -## elementHandle.inputValue([options]) -## elementHandle.isChecked() -## elementHandle.isDisabled() -## elementHandle.isEditable() -## elementHandle.isEnabled() -## elementHandle.isHidden() -## elementHandle.isVisible() -## elementHandle.ownerFrame() -## elementHandle.press(key[, options]) -## elementHandle.screenshot([options]) -## elementHandle.scrollIntoViewIfNeeded([options]) -## elementHandle.selectOptions(values[, options]) -## elementHandle.selectText([options]) -## elementHandle.setChecked(checked[, options]) -## elementHandle.setInputFiles() -## elementHandle.tap([options]) -## elementHandle.textContent() -## elementHandle.type(text[, options]) -## elementHandle.uncheck([options]) -## elementHandle.waitForElementState(state[, options]) -## elementHandle.waitForSelector(selector[, options]) + +```javascript +import { chromium } from 'k6/x/browser'; +import { check } from 'k6'; +export default function () { + const browser = chromium.launch({ + headless: false, + }); + const context = browser.newContext(); + const page = context.newPage(); + + // Inject page content + page.setContent(` +
Hello world
+ +
Edit me
+ + + + + `); + + // Check state + check(page, { + visible: (p) => p.$('.visible').isVisible(), + hidden: (p) => p.$('.hidden').isHidden(), + editable: (p) => p.$('.editable').isEditable(), + enabled: (p) => p.$('.enabled').isEnabled(), + disabled: (p) => p.$('.disabled').isDisabled(), + checked: (p) => p.$('.checked').isChecked(), + unchecked: (p) => p.$('.unchecked').isChecked() === false, + }); + page.close(); + browser.close(); +} +``` +
diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/05-frame.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/05-frame.md index b7871fad3f..1f5b64ada7 100644 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/05-frame.md +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/05-frame.md @@ -3,106 +3,53 @@ title: "Frame" excerpt: "xk6-browser: Frame Class" --- - - -## frame.$(selector[, options]) - -## frame.check(selector[, options]) - -## frame.childFrames() - -## frame.click(selector[, options]) - -## frame.content() - -## frame.dblclick(selector[, options]) - -## frame.dispatchEvent(selector, type[, eventInit, options]) - -## frame.evaluate(pageFunction[, arg]) - -## frame.evaluateHandle(pageFunction[, arg]) - -## frame.fill(selector, value[, options]) - -## frame.focus(selector[, options]) - -## frame.frameElement() - -## frame.getAttribute(selector, name[, options]) - -## frame.goto(url[, options]) - -## frame.hover(selector[, options]) - -## frame.innerHTML(selector[, options]) - -## frame.innerText(selector[, options]) - -## frame.inputValue(selector[, options]) - -## frame.isChecked(selector[, options]) - -## frame.isDetached() - -## frame.isDisabled(selector[, options]) - -## frame.isEditable(selector[, options]) - -## frame.isEnabled(selector[, options]) - -## frame.isHidden(selector[, options]) - -## frame.isVisible(selector[, options]) - -## frame.name() - -## frame.page() - -## frame.parentFrame() - -## frame.press(selector, key[, options]) - -## frame.selectOption(selector, values[, options]) - -## frame.setChecked(selector, checked[, options]) - -## frame.setContent(html[, options]) - -## frame.tap(selector[, options]) - -## frame.textContent(selector[, options]) - -## frame.title() - -## frame.uncheck(selector[, options]) - -## frame.url() - -## frame.waitForFunction(pageFunction[, arg, options]) - -## frame.waitForLoadState([state, options]) - -## frame.waitForNavigation([options]) - -## frame.waitForSelector(selector[, options]) - -## frame.waitForTimeout(timeout) - -## frame.waitForURL(url[, options]) - - -## frame.$eval() - -## frame.$$eval() - -## frame.addScriptTag() - -## frame.addStyleTag() - -## frame.dragAndDrop() - -## frame.locator() - -## frame.setInputFiles() - + + +## Supported APIs + +| Method | Playwright Relevant Distinctions | +| - | - | +| frame.$(selector[, options]) | - | +| frame.check(selector[, options]) | - | +| frame.childFrames() | - | +| frame.click(selector[, options]) | - | +| frame.content() | - | +| frame.dblclick(selector[, options]) | - | +| frame.dispatchEvent(selector, type[, eventInit, options]) | - | +| frame.evaluate(pageFunction[, arg]) | - | +| frame.evaluateHandle(pageFunction[, arg]) | - | +| frame.fill(selector, value[, options]) | - | +| frame.focus(selector[, options]) | - | +| frame.frameElement() | - | +| frame.getAttribute(selector, name[, options]) | - | +| frame.goto(url[, options]) | - | +| frame.hover(selector[, options]) | - | +| frame.innerHTML(selector[, options]) | - | +| frame.innerText(selector[, options]) | - | +| frame.inputValue(selector[, options]) | - | +| frame.isChecked(selector[, options]) | - | +| frame.isDetached() | - | +| frame.isDisabled(selector[, options]) | - | +| frame.isEditable(selector[, options]) | - | +| frame.isEnabled(selector[, options]) | - | +| frame.isHidden(selector[, options]) | - | +| frame.isVisible(selector[, options]) | - | +| frame.name() | - | +| frame.page() | - | +| frame.parentFrame() | - | +| frame.press(selector, key[, options]) | - | +| frame.selectOption(selector, values[, options]) | - | +| frame.setChecked(selector, checked[, options]) | - | +| frame.setContent(html[, options]) | - | +| frame.tap(selector[, options]) | - | +| frame.textContent(selector[, options]) | - | +| frame.title() | - | +| frame.title() | - | +| frame.uncheck(selector[, options]) | - | +| frame.url() | - | +| frame.waitForFunction(pageFunction[, arg, options]) | - | +| frame.waitForLoadState([state, options]) | - | +| frame.waitForNavigation([options]) | - | +| frame.waitForSelector(selector[, options]) | - | +| frame.waitForTimeout(timeout) | - | +| frame.waitForURL(url[, options]) | - | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/06-js-handle.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/06-js-handle.md index 4fe0994458..8a87bd0c93 100644 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/06-js-handle.md +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/06-js-handle.md @@ -3,28 +3,16 @@ title: "JSHandle" excerpt: "xk6-browser: JSHandle Class" --- - - - -- [jsHandle.asElement()](#jshandle-aselement) -- [jsHandle.dispose()](#jshandle-dispose) -- [jsHandle.evaluate(pageFunction[, arg])](#jshandle-evaluate-pagefunction-arg) -- [jsHandle.evaluateHandle(pageFunction[, arg])](#jshandle-evaluatehandle-pagefunction-arg) -- [jsHandle.getProperties()](#jshandle-getproperties) -- [jsHandle.getProperty(propertyName)](#jshandle-getproperty-propertyname) -- [jsHandle.jsonValue()](#jshandle-jsonvalue) - - -## jsHandle.asElement() - -## jsHandle.dispose() - -## jsHandle.evaluate(pageFunction[, arg]) - -## jsHandle.evaluateHandle(pageFunction[, arg]) - -## jsHandle.getProperties() - -## jsHandle.getProperty(propertyName) - -## jsHandle.jsonValue() \ No newline at end of file + + +## Supported APIs + +| Method | Playwright Relevant Distinctions | +| - | - | +| jsHandle.asElement() | - | +| jsHandle.dispose() | - | +| jsHandle.evaluate(pageFunction[, arg]) | - | +| jsHandle.evaluateHandle(pageFunction[, arg]) | - | +| jsHandle.getProperties() | - | +| jsHandle.getProperty(propertyName) | - | +| jsHandle.jsonValue() | - | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator.md new file mode 100644 index 0000000000..06d9ef26ac --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator.md @@ -0,0 +1,104 @@ +--- +title: "Locator" +excerpt: "xk6-browser: Locator Class" +--- + +The Locator API makes it easier to work with dynamically changing elements. Some of the benefits of using it over existing ways to locate an element (e.g. `Page.$()`) include: + +- Helps with writing robust tests by finding an element even if the underlying frame navigates. +- Makes it easier to work with dynamic web pages and SPAs built with Svelte, React, Vue, etc. +- Enables the use of test abstractions like the Page Object Model (POM) pattern to simplify and organize tests. +- `strict` mode is enabled for all `locator` methods, which means that if more than one element matches the given selector it will throw an error. + +Locator can be created with the [page.locator(selector[, options])](/javascript-api/xk6-browser/page/#page-locator) method. + +| Method | Description | +|---------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------| +| [locator.check([options])](/javascript-api/xk6-browser/locator/check) | Select the input checkbox. | +| [locator.click([options])](/javascript-api/xk6-browser/locator/click) | Mouse click on the chosen element. | +| [locator.dblclick([options])](/javascript-api/xk6-browser/locator/dblclick) | Mouse double click on the chosen element. | +| [locator.dispatchEvent(type, eventInit, [options])](/javascript-api/xk6-browser/locator/dispatchevent) | Dispatches HTML DOM event types e.g. `'click'`. | +| [locator.fill(value, [options])](/javascript-api/xk6-browser/locator/fill) | Fill an `input`, `textarea` or `contenteditable` element with the provided value. | +| [locator.focus([options])](/javascript-api/xk6-browser/locator/focus) | Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element, if it can be focused. | +| [locator.getAttribute(name, [options])](/javascript-api/xk6-browser/locator/getattribute) | Returns the element attribute value for the given attribute name. | +| [locator.hover([options])](/javascript-api/xk6-browser/locator/hover) | Hovers over the element. | +| [locator.innerHTML([options])](/javascript-api/xk6-browser/locator/innerhtml) | Returns the `element.innerHTML`. | +| [locator.innerText([options])](/javascript-api/xk6-browser/locator/innertext) | Returns the `element.innerText`. | +| [locator.inputValue([options])](/javascript-api/xk6-browser/locator/inputvalue) | Returns `input.value` for the selected `input`, `textarea` or `select` element. | +| [locator.isChecked([options])](/javascript-api/xk6-browser/locator/ischecked) | Checks if the `checkbox` `input` type is selected. | +| [locator.isDisabled([options])](/javascript-api/xk6-browser/locator/isdisabled) | Checks if the element is `disabled`. | +| [locator.isEditable([options])](/javascript-api/xk6-browser/locator/iseditable) | Checks if the element is `editable`. | +| [locator.isEnabled([options])](/javascript-api/xk6-browser/locator/isenabled) | Checks if the element is `enabled`. | +| [locator.isHidden([options])](/javascript-api/xk6-browser/locator/ishidden) | Checks if the element is `hidden`. | +| [locator.isVisible([options])](/javascript-api/xk6-browser/locator/isvisible) | Checks if the element is `visible`. | +| [locator.press(key, [options])](/javascript-api/xk6-browser/locator/press) | Press a single key on the keyboard or a combination of keys. | +| [locator.selectOption(values, [options])](/javascript-api/xk6-browser/locator/selectoption) | Select one or more options which match the values. | +| [locator.tap([options])](/javascript-api/xk6-browser/locator/tap) | Tap on the chosen element. | +| [locator.textContent([options])](/javascript-api/xk6-browser/locator/textcontent) | Returns the `element.textContent`. | +| [locator.type(text, [options])](/javascript-api/xk6-browser/locator/type) | Type in the text into the input field. | +| [locator.uncheck([options])](/javascript-api/xk6-browser/locator/uncheck) | Unselect the `input` checkbox. | +| [locator.waitFor([options])](/javascript-api/xk6-browser/locator/waitfor) | Wait for the element to be in a particular state e.g. `visible`. | + +### Example + + + + + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch({ + headless: false, + }); + const context = browser.newContext(); + const page = context.newPage(); + page.goto("https://test.k6.io/flip_coin.php", { + waitUntil: "networkidle", + }); + + /* + In this example, we will use two locators, matching a + different betting button on the page. If you were to query + the buttons once and save them as below, you would see an + error after the initial navigation. Try it! + + const heads = page.$("input[value='Bet on heads!']"); + const tails = page.$("input[value='Bet on tails!']"); + + The Locator API allows you to get a fresh element handle each + time you use one of the locator methods. And, you can carry a + locator across frame navigations. Let's create two locators; + each locates a button on the page. + */ + const heads = page.locator("input[value='Bet on heads!']"); + const tails = page.locator("input[value='Bet on tails!']"); + + const currentBet = page.locator("//p[starts-with(text(),'Your bet: ')]"); + + // the tails locator clicks on the tails button by using the + // locator's selector. + tails.click(); + // Since clicking on each button causes page navigation, + // waitForNavigation is needed. It's because the page + // won't be ready until the navigation completes. + page.waitForNavigation(); + console.log(currentBet.innerText()); + + // the heads locator clicks on the heads button by using the + // locator's selector. + heads.click(); + page.waitForNavigation(); + console.log(currentBet.innerText()); + + tails.click(); + page.waitForNavigation(); + console.log(currentBet.innerText()); + + page.close(); + browser.close(); +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/check--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/check--options--.md new file mode 100644 index 0000000000..abd218ccf0 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/check--options--.md @@ -0,0 +1,41 @@ +--- +title: 'check([options])' +excerpt: 'xk6-browser: locator.check method' +--- + +
+ +There are known issues with this feature. See [issue #471](/~https://github.com/grafana/xk6-browser/issues/471) and [issue #475](/~https://github.com/grafana/xk6-browser/issues/475) for details. + +
+ +Use this method to select an `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. | +| 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/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | +| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | + + + +### Example + + + + + +```javascript +const res = page.goto('https://test.k6.io/browser.php'); +const checkbox = page.locator("#checkbox1"); +checkbox.check(); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/click--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/click--options--.md new file mode 100644 index 0000000000..339e2e1466 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/click--options--.md @@ -0,0 +1,45 @@ +--- +title: 'click([options])' +excerpt: 'xk6-browser: locator.click method' +--- + +
+ +There are known issues with this feature. See [issue #471](/~https://github.com/grafana/xk6-browser/issues/471) and [issue #474](/~https://github.com/grafana/xk6-browser/issues/474) for details. + +
+ +Mouse click on the chosen element. + + + +| Parameter | Type | Default | Description | +|---------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| options | object | `null` | | +| options.button | string | `left` | The mouse button (`left`, `middle` or `right`) to use during the action. | +| options.clickCount | number | `1` | The number of times the action is performed. | +| options.delay | number | `0` | Milliseconds to wait between `mousedown` and `mouseup`. | +| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | +| options.modifiers | string[] | `null` | `Alt`, `Control`, `Meta` or `Shift` modifiers keys pressed during the action. If not specified, currently pressed modifiers are used. | +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | +| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | + + + +### Example + + + + + +```javascript +page.goto("https://test.k6.io/browser.php"); +const button = page.locator("#counter-button"); +button.click(); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/dblclick--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/dblclick--options--.md new file mode 100644 index 0000000000..3348de27af --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/dblclick--options--.md @@ -0,0 +1,44 @@ +--- +title: 'dblclick([options])' +excerpt: 'xk6-browser: locator.dblclick method' +--- + +
+ +There are known issues with this feature. See [issue #469](/~https://github.com/grafana/xk6-browser/issues/469) and [issue #471](/~https://github.com/grafana/xk6-browser/issues/471) for details. + +
+ +Mouse double click on the chosen element. + + + +| Parameter | Type | Default | Description | +|---------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| options | object | `null` | | +| options.button | string | `left` | The mouse button (`left`, `middle` or `right`) to use during the action. | +| options.delay | number | `0` | Milliseconds to wait between `mousedown` and `mouseup`. | +| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | +| options.modifiers | string[] | `null` | `Alt`, `Control`, `Meta` or `Shift` modifiers keys pressed during the action. If not specified, currently pressed modifiers are used. | +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | +| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | + + + +### Example + + + + + +```javascript +page.goto("https://test.k6.io/browser.php"); +const button = page.locator("#counter-button"); +button.dblclick(); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/dispatchevent--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/dispatchevent--options--.md new file mode 100644 index 0000000000..93d822168b --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/dispatchevent--options--.md @@ -0,0 +1,43 @@ +--- +title: 'dispatchEvent(type, eventInit, [options])' +excerpt: 'xk6-browser: locator.dispatchEvent method' +--- + +Dispatches HTML DOM event types e.g. `'click'`. + + + +| Parameter | Type | Defaults | Description | +|-----------------|--------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| type | string | `''` | DOM event type e.g. `'click'`. | +| eventInit | object | `null` | Optional event specific properties. See [eventInit](#eventinit) 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### eventInit + +Since eventInit is event-specific, please refer to the events documentation for the lists of initial properties: + +- [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent) +- [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent) +- [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent) +- [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent) +- [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent) +- [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent) +- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event) + +### Example + + + + + +```javascript +page.goto("https://test.k6.io/browser.php"); +const button = page.locator("#counter-button"); +button.dispatchEvent('click'); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/fill--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/fill--options--.md new file mode 100644 index 0000000000..406a2c93f0 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/fill--options--.md @@ -0,0 +1,32 @@ +--- +title: 'fill(value, [options])' +excerpt: 'xk6-browser: locator.fill method' +--- + +Fill an `input`, `textarea` or `contenteditable` element with the provided value. + + + +| Parameter | Type | Default | Description | +|---------------------|---------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| value | string | `''` | Value to set for the `input`, `textarea` or `contenteditable` element. | +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Example + + + + + +```javascript +page.goto("https://test.k6.io/browser.php"); +const textbox = page.locator("#text1"); +textbox.fill('hello world!'); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/focus--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/focus--options--.md new file mode 100644 index 0000000000..6952334384 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/focus--options--.md @@ -0,0 +1,29 @@ +--- +title: 'focus([options])' +excerpt: 'xk6-browser: locator.focus method' +--- + +Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element, if it can be focused on. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Example + + + + + +```javascript +page.goto("https://test.k6.io/browser.php"); +const textbox = page.locator("#text1"); +textbox.focus(); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/getattribute--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/getattribute--options--.md new file mode 100644 index 0000000000..2dd8068190 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/getattribute--options--.md @@ -0,0 +1,37 @@ +--- +title: 'getAttribute(name, [options])' +excerpt: 'xk6-browser: locator.getAttribute method' +--- + +Returns the element attribute value for the given attribute name. + + + +| Parameter | Type | Default | Description | +|-----------------|--------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| name | string | `''` | Attribute name to get the value for. | +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|--------|-------------------------------------| +| string | The value of the attribute or null. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const textInput = page.locator('#text1'); +const attribute = textInput.getAttribute('onfocus'); +console.log(attribute); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/hover--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/hover--options--.md new file mode 100644 index 0000000000..26dc37bec4 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/hover--options--.md @@ -0,0 +1,42 @@ +--- +title: 'hover([options])' +excerpt: 'xk6-browser: locator.hover method' +--- + +
+ +There is a known issue with this feature. See [issue #471](/~https://github.com/grafana/xk6-browser/issues/471) for details. + +
+ +Hovers over the element. + + + +| Parameter | Type | Default | Description | +|---------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| options | object | `null` | | +| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | +| options.modifiers | string[] | `null` | `Alt`, `Control`, `Meta` or `Shift` modifiers keys pressed during the action. If not specified, currently pressed modifiers are used. | +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | +| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | + + + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const offScreenElement = page.locator("#off-screen"); +offScreenElement.hover(); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/innerhtml--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/innerhtml--options--.md new file mode 100644 index 0000000000..dcfabfbdcc --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/innerhtml--options--.md @@ -0,0 +1,36 @@ +--- +title: 'innerHTML([options])' +excerpt: 'xk6-browser: locator.innerHTML method' +--- + +Returns the `element.innerHTML`. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|--------|--------------------------------| +| string | The innerHTML of the element. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const offScreen = page.locator('#off-screen'); +const innerHTML = offScreen.innerHTML(); +console.log(innerHTML); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/innertext--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/innertext--options--.md new file mode 100644 index 0000000000..274c261e66 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/innertext--options--.md @@ -0,0 +1,36 @@ +--- +title: 'innerText([options])' +excerpt: 'xk6-browser: locator.innerText method' +--- + +Returns the `element.innerText`. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|--------|--------------------------------| +| string | The innerText of the element. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const offScreen = page.locator('#off-screen'); +const innerText = offScreen.innerText(); +console.log(innerText); // Off page div +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/inputvalue--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/inputvalue--options--.md new file mode 100644 index 0000000000..0fb010ba61 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/inputvalue--options--.md @@ -0,0 +1,37 @@ +--- +title: 'inputValue([options])' +excerpt: 'xk6-browser: locator.inputValue method' +--- + +Returns `input.value` for the selected `input`, `textarea` or `select` element. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|--------|----------------------------------| +| string | The input value of the element. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const textInput = page.locator('#text1'); +textInput.fill("Hello world!"); +const inputValue = textInput.inputValue(); +console.log(inputValue); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/ischecked--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/ischecked--options--.md new file mode 100644 index 0000000000..30eccba3c1 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/ischecked--options--.md @@ -0,0 +1,37 @@ +--- +title: 'isChecked([options])' +excerpt: 'xk6-browser: locator.isChecked method' +--- + +Checks to see if the `checkbox` `input` type is selected or not. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|------|---------------------------------------------------| +| bool | `true` if the checkbox is selected, else `false`. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const checkbox = page.locator('#checkbox1'); +if (!checkbox.isChecked()) { + checkbox.check(); +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/isdisabled--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/isdisabled--options--.md new file mode 100644 index 0000000000..e12694d94a --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/isdisabled--options--.md @@ -0,0 +1,37 @@ +--- +title: 'isDisabled([options])' +excerpt: 'xk6-browser: locator.isDisabled method' +--- + +Checks if the element is `disabled`. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|------|---------------------------------------------------| +| bool | `true` if the element is `disabled`, else `false`. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const text = page.locator('#input-text-disabled'); +if (text.isDisabled()) { + console.log("element is disabled") +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/iseditable--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/iseditable--options--.md new file mode 100644 index 0000000000..3ce9366463 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/iseditable--options--.md @@ -0,0 +1,37 @@ +--- +title: 'isEditable([options])' +excerpt: 'xk6-browser: locator.isEditable method' +--- + +Checks if the element is `editable`. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|------|----------------------------------------------------| +| bool | `true` if the element is `editable`, else `false`. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const text = page.locator('#text1'); +if (text.isEditable()) { + text.fill("hello world!"); +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/isenabled--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/isenabled--options--.md new file mode 100644 index 0000000000..00932c7733 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/isenabled--options--.md @@ -0,0 +1,37 @@ +--- +title: 'isEnabled([options])' +excerpt: 'xk6-browser: locator.isEnabled method' +--- + +Checks if the element is `enabled`. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|------|---------------------------------------------------| +| bool | `true` if the element is `enabled`, else `false`. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const text = page.locator('#text1'); +if (text.isEnabled()) { + console.log("element is enabled"); +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/ishidden--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/ishidden--options--.md new file mode 100644 index 0000000000..7ef4649a0c --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/ishidden--options--.md @@ -0,0 +1,37 @@ +--- +title: 'isHidden([options])' +excerpt: 'xk6-browser: locator.isHidden method' +--- + +Checks if the element is `hidden`. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|------|---------------------------------------------------| +| bool | `true` if the element is `hidden`, else `false`. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const text = page.locator('#input-text-hidden'); +if (text.isHidden()) { + console.log("element is hidden"); +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/isvisible--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/isvisible--options--.md new file mode 100644 index 0000000000..544b796973 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/isvisible--options--.md @@ -0,0 +1,37 @@ +--- +title: 'isVisible([options])' +excerpt: 'xk6-browser: locator.isVisible method' +--- + +Checks if the element is `visible`. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|------|---------------------------------------------------| +| bool | `true` if the element is `visible`, else `false`. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const text = page.locator('#text1'); +if (text.isVisible()) { + console.log("element is visible"); +} +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/press--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/press--options--.md new file mode 100644 index 0000000000..abce6b6965 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/press--options--.md @@ -0,0 +1,34 @@ +--- +title: 'press(key, [options])' +excerpt: 'xk6-browser: locator.press method' +--- + +Press a single key on the keyboard or a combination of keys. + + + +| Parameter | Type | Default | Description | +|---------------------|---------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| key | string | `''` | Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values). | +| options | object | `null` | | +| options.delay | number | `0` | Milliseconds to wait between `keydown` and `keyup`. | +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const text = page.locator('#text1'); +text.press('i'); +text.press('ArrowLeft'); +text.press('h'); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/selectoption--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/selectoption--options--.md new file mode 100644 index 0000000000..3c288734b5 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/selectoption--options--.md @@ -0,0 +1,44 @@ +--- +title: 'selectOption(values, [options])' +excerpt: 'xk6-browser: locator.selectOption method' +--- + +
+ +There are known issues with this feature. See [issue #470](/~https://github.com/grafana/xk6-browser/issues/470) and [issue #471](/~https://github.com/grafana/xk6-browser/issues/471) for details. + +
+ +Select one or more options which match the values. + + + +| Parameter | Type | Default | Description | +|---------------------|------------------------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| values | string or string[] or object | `''` | If the `select` has the multiple attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. Object can be made up of keys with `value`, `label` or `index`. | +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|----------|-------------------------------| +| string[] | List of the selected options. | + +### Example + + + + + +```javascript +page.goto('https://test.k6.io/browser.php'); +const options = page.locator('#numbers-options'); +options.selectOption('three'); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/tap--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/tap--options--.md new file mode 100644 index 0000000000..5d17044e3d --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/tap--options--.md @@ -0,0 +1,45 @@ +--- +title: 'tap([options])' +excerpt: 'xk6-browser: locator.tap method' +--- + +
+ +There are known issues with this feature. See [issue #436](/~https://github.com/grafana/xk6-browser/issues/436) and [issue #471](/~https://github.com/grafana/xk6-browser/issues/471) for details. + +
+ +Tap on the chosen element. + + + +| Parameter | Type | Default | Description | +|---------------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| options | object | `null` | | +| options.force | boolean | `false` | Setting this to `true` will bypass the actionability checks (`visible`, `stable`, `enabled`). | +| options.modifiers | string[] | `null` | `Alt`, `Control`, `Meta` or `Shift` modifiers keys pressed during the action. If not specified, currently pressed modifiers are used. | +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | +| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | + + + +### Example + + + + + +```javascript +const page = context.newPage({ + hasTouch: true, +}); +const res = page.goto('https://test.k6.io/browser.php'); +const options = page.locator("#numbers-options"); +options.tap(); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/textcontent--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/textcontent--options--.md new file mode 100644 index 0000000000..aa45cf079d --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/textcontent--options--.md @@ -0,0 +1,41 @@ +--- +title: 'textContent([options])' +excerpt: 'xk6-browser: locator.textContent method' +--- + +Returns the `element.textContent`. + + + +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Returns + +| Type | Description | +|--------|-------------------------------------------| +| string | The text content of the selector or null. | + +### Example + + + + + +```javascript +const res = page.goto('https://test.k6.io/browser.php'); +const options = page.locator("#checkbox1"); +console.log(options.textContent()); /* Zero + One + Two + Three + Four + Five + */ +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/type--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/type--options--.md new file mode 100644 index 0000000000..887cfb64dc --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/type--options--.md @@ -0,0 +1,32 @@ +--- +title: 'type(text, [options])' +excerpt: 'xk6-browser: locator.type method' +--- + +Type in the text into the input field. + + + +| Parameter | Type | Default | Description | +|---------------------|---------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| text | string | `''` | A text to type into a focused element. | +| options | object | `null` | | +| options.delay | number | `0` | Milliseconds to wait between key presses. Defaults to `0`. | +| 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](/javascript-api/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Example + + + + + +```javascript +const res = page.goto('https://test.k6.io/browser.php'); +const text = page.locator("#text1"); +text.type('hello world!'); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/uncheck--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/uncheck--options--.md new file mode 100644 index 0000000000..fe2c53d001 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/uncheck--options--.md @@ -0,0 +1,42 @@ +--- +title: 'uncheck([options])' +excerpt: 'xk6-browser: locator.uncheck method' +--- + +
+ +There is a known issue with this feature. See [issue #471](/~https://github.com/grafana/xk6-browser/issues/471) for details. + +
+ +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. | +| 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/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | +| options.trial | boolean | `false` | Setting this to `true` will perform the actionability checks without performing the action. | + + + +### Example + + + + + +```javascript +const res = page.goto('https://test.k6.io/browser.php'); +const checkbox = page.locator("#checkbox1"); +checkbox.check(); +checkbox.uncheck(); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/waitfor--options--.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/waitfor--options--.md new file mode 100644 index 0000000000..545e2fbf3e --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07 Locator/waitfor--options--.md @@ -0,0 +1,38 @@ +--- +title: 'waitFor([options])' +excerpt: 'xk6-browser: locator.waitFor method' +--- + +
+ +There is a known issue with this feature. See [issue #472](/~https://github.com/grafana/xk6-browser/issues/472) for details. + +
+ +Wait for the element to be in a particular state e.g. `visible`. + + + +| Parameter | Type | Default | Description | +|-----------------|--------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| options | object | `null` | | +| options.state | string | `visible` | Can be `attached`, `detached`, `visible` or `hidden`. | +| 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/xk6-browser/browsercontext/) or [Page](/javascript-api/xk6-browser/page/). | + + + +### Example + + + + + +```javascript +const res = page.goto('https://test.k6.io/browser.php'); +const text = page.locator('#input-text-hidden'); +text.waitFor({ + state: 'hidden', +}); +``` + + diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07-keyboard.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07-keyboard.md deleted file mode 100644 index 7fada71f20..0000000000 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/07-keyboard.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: "Keyboard" -excerpt: "xk6-browser: Keyboard Class" ---- - - - -- [keyboard.down(key)](#keyboard-down-key) -- [keyboard.insertText(text)](#keyboard-inserttext-text) -- [keyboard.press(key[, options])](#keyboard-press-key-options) -- [keyboard.type(text[, options])](#keyboard-type-text-options) -- [keyboard.up(key)](#keyboard-up-key) - -## keyboard.down(key) -## keyboard.insertText(text) -## keyboard.press(key[, options]) -## keyboard.type(text[, options]) -## keyboard.up(key) diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/08-keyboard.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/08-keyboard.md new file mode 100644 index 0000000000..b3c78cd78f --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/08-keyboard.md @@ -0,0 +1,16 @@ +--- +title: "Keyboard" +excerpt: "xk6-browser: Keyboard Class" +--- + + + +## Supported APIs + +| Method | Playwright Relevant Distinctions | +| - | - | +| keyboard.down(key) | - | +| keyboard.insertText(text) | - | +| keyboard.press(key[, options]) | - | +| keyboard.type(text[, options]) | - | +| keyboard.up(key) | - | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/08-launcher.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/08-launcher.md deleted file mode 100644 index 577536a1c2..0000000000 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/08-launcher.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -title: "launcher" -excerpt: "xk6-browser: launcher Object" ---- - -This object can be used to launch or connect to Chromium, returning instances of [Browser](/javascript-api/xk6-browser/browser/). - -```javascript -import launcher from 'k6/x/browser'; - -export default function () { - const browser = launcher.launch('chromium', { - args: [], // Extra commandline arguments to include when launching browser process - debug: true, // Log all CDP messages to k6 logging subsystem - devtools: true, // Open up developer tools in the browser by default - env: {}, // Environment variables to set before launching browser process - executablePath: null, // Override search for browser executable in favor of specified absolute path - headless: false, // Show browser UI or not - ignoreDefaultArgs: [], // Ignore any of the default arguments included when launching browser process - proxy: {}, // Specify to set browser's proxy config - slowMo: '500ms', // Slow down input actions and navigations by specified time - timeout: '30s', // Default timeout to use for various actions and navigations - }); - browser.close(); -} -``` - -```javascript -import launcher from 'k6/x/browser'; - -export default function () { - const browser = launcher.launch('chromium', { headless: false }); - const context = browser.newContext(); - const page = context.newPage(); - page.goto('http://whatsmyuseragent.org/'); - page.close(); - browser.close(); -} -``` diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/08-mouse.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/08-mouse.md deleted file mode 100644 index 82543236f1..0000000000 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/08-mouse.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: "Mouse" -excerpt: "xk6-browser: Mouse Class" ---- - - - - -- [mouse.click(x, y[, options])](#mouse-click-x-y-options) -- [mouse.dblclick(x, y[, options])](#mouse-dblclick-x-y-options) -- [mouse.down([options])](#mouse-down-options) -- [mouse.move(x, y[, options])](#mouse-move-x-y-options) -- [mouse.up([options])](#mouse-up-options) -- [mouse.wheel(deltaX, deltaY)](#mouse-wheel-deltax-deltay) - -## mouse.click(x, y[, options]) -## mouse.dblclick(x, y[, options]) -## mouse.down([options]) -## mouse.move(x, y[, options]) -## mouse.up([options]) -## mouse.wheel(deltaX, deltaY) diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/09-mouse.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/09-mouse.md new file mode 100644 index 0000000000..46c7783940 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/09-mouse.md @@ -0,0 +1,17 @@ +--- +title: "Mouse" +excerpt: "xk6-browser: Mouse Class" +--- + + + +## Supported APIs + +| Method | Playwright Relevant Distinctions | +| - | - | +| mouse.click(x, y[, options]) | - | +| mouse.dblclick(x, y[, options]) | - | +| mouse.down([options]) | - | +| mouse.move(x, y[, options]) | - | +| mouse.up([options]) | - | +| mouse.wheel(deltaX, deltaY) | - | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/09-page.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/09-page.md deleted file mode 100644 index f1e31d4750..0000000000 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/09-page.md +++ /dev/null @@ -1,207 +0,0 @@ ---- -title: "Page" -excerpt: "xk6-browser: Page Class" ---- - - - -```javascript -import launcher from 'k6/x/browser'; - -export default function () { - const browser = launcher.launch('chromium', { - headless: false, - }); - const context = browser.newContext(); - const page = context.newPage(); - - // Goto front page, find login link and click it - page.goto('https://test.k6.io/', { waitUntil: 'networkidle' }); - const elem = page.$('a[href="/my_messages.php"]'); - elem.click(); - - // Wait for login page to load - page.waitForLoadState(); - - // Enter login credentials and login - page.$('input[name="login"]').type('admin'); - page.$('input[name="password"]').type('123'); - page.$('input[type="submit"]').click(); - - // Wait for next page to load - page.waitForNavigation(); - - page.close(); - browser.close(); -} -``` - - -## page.bringToFront() - -## page.check(selector[, options]) - -## page.click(selector[, options]) - -## page.close([options]) - -## page.content() - -## page.context() - -## page.dblclick(selector[, options]) - -## page.dispatchEvent(selector, type[, eventInit, options]) - -## page.emulateMedia([options]) - -## page.evaluate(pageFunction[, arg]) - -## page.evaluateHandle(pageFunction[, arg]) - -## page.fill(selector, value[, options]) - -## page.focus(selector[, options]) - -## page.frames() - -## page.getAttribute(selector, name[, options]) - -## page.goto(url[, options]) - -## page.hover(selector[, options]) - -## page.innerHTML(selector[, options]) - -## page.innerText(selector[, options]) - -## page.inputValue(selector[, options]) - -## page.isChecked(selector[, options]) - -## page.isClosed() - -## page.isDisabled(selector[, options]) - -## page.isEditable(selector[, options]) - -## page.isEnabled(selector[, options]) - -## page.isHidden(selector[, options]) - -## page.isVisible(selector[, options]) - -## page.mainFrame() - -## page.opener() - -## page.press(selector, key[, options]) - -## page.reload([options]) - -## page.screenshot([options]) - -## page.selectOption(selector, values[, options]) - -## page.setChecked(selector, checked[, options]) - -## page.setContent(html[, options]) - -## page.setDefaultNavigationTimeout(timeout) - -## page.setDefaultTimeout(timeout) - -## page.setExtraHTTPHeaders(headers) - -## page.setInputFiles(selector, files[, options]) - -## page.setViewportSize(viewportSize) - -## page.tap(selector[, options]) - -## page.textContent(selector[, options]) - -## page.title() - -## page.type(selector, text[, options]) - -## page.uncheck(selector[, options]) - -## page.unroute(url[, handler]) - -## page.url() - -## page.viewportSize() - -## page.waitForFunction(pageFunction[, arg, options]) - -## page.waitForLoadState([state, options]) - -## page.waitForNavigation([options]) - -## page.waitForRequest(urlOrPredicate[, options]) - -## page.waitForResponse(urlOrPredicate[, options]) - -## page.waitForSelector(selector[, options]) - -## page.waitForTimeout(timeout) - -## page.keyboard - -## page.mouse - -## page.touchscreen - -## page.$eval() - -## page.$$eval() - -## page.addInitScript() - -## page.addScriptTag() - -## page.addStyleTag() - -## page.dragAndDrop() - -## page.exposeBinding() - -## page.exposeFunction() - -## page.frame() - -## page.goBack() - -## page.goForward() - -## page.locator() - -## page.pause() - -## page.pdf() - -## page.video() - -## page.workers() - -## page.accessibility - -## page.coverage - -## page.request - -## page.on() - -## page.route() - -## page.unroute() - -## page.waitForEvent() - -## page.waitForResponse() - -## page.waitForURL() - - - diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/10-page.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/10-page.md new file mode 100644 index 0000000000..7b88207864 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/10-page.md @@ -0,0 +1,103 @@ +--- +title: "Page" +excerpt: "xk6-browser: Page Class" +--- + + + +## Supported APIs + +| Method | Playwright Relevant Distinctions | Description | +| - | - | - | +| page.bringToFront() | - | - | +| page.check(selector[, options]) | - | - | +| page.click(selector[, options]) | - | - | +| page.close([options]) | - | - | +| page.content() | - | - | +| page.context() | - | - | +| page.dblclick(selector[, options]) | - | - | +| page.dispatchEvent(selector, type[, eventInit, options]) | - | - | +| page.emulateMedia([options]) | - | - | +| page.evaluate(pageFunction[, arg]) | - | - | +| page.evaluateHandle(pageFunction[, arg]) | - | - | +| page.fill(selector, value[, options]) | - | - | +| page.focus(selector[, options]) | - | - | +| page.frames() | - | - | +| page.getAttribute(selector, name[, options]) | - | - | +| page.goto(url[, options]) | - | - | +| page.hover(selector[, options]) | - | - | +| page.innerHTML(selector[, options]) | - | - | +| page.innerText(selector[, options]) | - | - | +| page.inputValue(selector[, options]) | - | - | +| page.isChecked(selector[, options]) | - | - | +| page.isClosed() | - | - | +| page.isDisabled(selector[, options]) | - | - | +| page.isEditable(selector[, options]) | - | - | +| page.isEnabled(selector[, options]) | - | - | +| page.isHidden(selector[, options]) | - | - | +| page.isVisible(selector[, options]) | - | - | +| page.locator(selector[, options]) | - | Creates and returns a new page `locator` given a selector with strict mode on. The strict mode only allows selecting a single matching element, and will throw an error if multiple matches are found. | +| page.mainFrame() | - | - | +| page.opener() | - | - | +| page.press(selector, key[, options]) | - | - | +| page.reload([options]) | - | - | +| page.screenshot([options]) | - | - | +| page.selectOption(selector, values[, options]) | - | - | +| page.setChecked(selector, checked[, options]) | - | - | +| page.setContent(html[, options]) | - | - | +| page.setDefaultNavigationTimeout(timeout) | - | - | +| page.setDefaultTimeout(timeout) | - | - | +| page.setExtraHTTPHeaders(headers) | - | - | +| page.setInputFiles(selector, files[, options]) | - | - | +| page.setViewportSize(viewportSize) | - | - | +| page.tap(selector[, options]) | - | - | +| page.textContent(selector[, options]) | - | - | +| page.title() | - | - | +| page.type(selector, text[, options]) | - | - | +| page.uncheck(selector[, options]) | - | - | +| page.unroute(url[, handler]) | - | - | +| page.url() | - | - | +| page.viewportSize() | - | - | +| page.waitForFunction(pageFunction[, arg, options]) | - | - | +| page.waitForLoadState([state, options]) | - | - | +| page.waitForNavigation([options]) | - | - | +| page.waitForRequest(urlOrPredicate[, options]) | - | - | +| page.waitForResponse(urlOrPredicate[, options]) | - | - | +| page.waitForSelector(selector[, options]) | - | - | +| page.waitForTimeout(timeout) | - | - | +| keyboard | - | - | +| mouse | - | - | +| touchscreen | - | - | + +### Example + +```javascript +import { chromium } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch({ + headless: false, + }); + const context = browser.newContext(); + const page = context.newPage(); + + // Goto front page, find login link and click it + page.goto('https://test.k6.io/', { waitUntil: 'networkidle' }); + const elem = page.$('a[href="/my_messages.php"]'); + elem.click(); + + // Wait for login page to load + page.waitForLoadState(); + + // Enter login credentials and login + page.$('input[name="login"]').type('admin'); + page.$('input[name="password"]').type('123'); + page.$('input[type="submit"]').click(); + + // Wait for next page to load + page.waitForNavigation(); + + page.close(); + browser.close(); +} +``` diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/10-request.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/10-request.md deleted file mode 100644 index 4718d6ad49..0000000000 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/10-request.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: "Request" -excerpt: "xk6-browser: Request Class" ---- - - - -- [request.allHeaders()](#request-allheaders) -- [request.failure()](#request-failure) -- [request.frame()](#request-frame) -- [request.headers()](#request-headers) -- [request.headersArray()](#request-headersarray) -- [request.headerValue(name)](#request-headervalue-name) -- [request.isNavigationRequest()](#request-isnavigationrequest) -- [request.method()](#request-method) -- [request.postData()](#request-postdata) -- [request.postDataBuffer()](#request-postdatabuffer) -- [request.postDataJSON()](#request-postdatajson) -- [request.redirectedFrom()](#request-redirectedfrom) -- [request.redirectedTo()](#request-redirectedto) -- [request.resourceType()](#request-resourcetype) -- [request.response()](#request-response) -- [request.sizes()](#request-sizes) -- [request.timing()](#request-timing) -- [request.url()](#request-url) - -## request.allHeaders() - -## request.failure() - -## request.frame() - -## request.headers() - -## request.headersArray() - -## request.headerValue(name) - -## request.isNavigationRequest() - -## request.method() - -## request.postData() - -## request.postDataBuffer() - -## request.postDataJSON() - -## request.redirectedFrom() - -## request.redirectedTo() - -## request.resourceType() - -## request.response() - -## request.sizes() - -## request.timing() - -## request.url() - diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/11-request.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/11-request.md new file mode 100644 index 0000000000..451bb6cc00 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/11-request.md @@ -0,0 +1,25 @@ +--- +title: "Request" +excerpt: "xk6-browser: Request Class" +--- + + + +## Supported APIs + +| Method | Playwright Relevant Distinctions | +| - | - | +| request.allHeaders() | - | +| request.frame() | - | +| request.headers() | - | +| request.headersArray() | - | +| request.headerValue(name) | - | +| request.isNavigationRequest() | - | +| request.method() | - | +| request.postData() | - | +| request.postDataBuffer() | - | +| request.resourceType() | - | +| request.response() | - | +| request.sizes() | - | +| request.timing() | - | +| request.url() | - | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/11-response.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/11-response.md deleted file mode 100644 index 9f8be0db33..0000000000 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/11-response.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: "Response" -excerpt: "xk6-browser: Response Class" ---- - - - -- [response.allHeaders()](#response-allheaders) -- [response.body()](#response-body) -- [response.finished()](#response-finished) -- [response.frame()](#response-frame) -- [response.headers()](#response-headers) -- [response.headersArray()](#response-headersarray) -- [response.headerValue(name)](#response-headervalue-name) -- [response.headerValues(name)](#response-headervalues-name) -- [response.json()](#response-json) -- [response.ok()](#response-ok) -- [response.request()](#response-request) -- [response.securityDetails()](#response-securitydetails) -- [response.serverAddr()](#response-serveraddr) -- [response.status()](#response-status) -- [response.statusText()](#response-statustext) -- [response.text()](#response-text) -- [response.url()](#response-url) - - - -## response.allHeaders() - -## response.body() - -## response.frame() - -## response.headers() - -## response.headersArray() - -## response.headerValue(name) - -## response.headerValues(name) - -## response.json() - -## response.ok() - -## response.request() - -## response.securityDetails() - -## response.serverAddr() - -## response.status() - -## response.statusText() - -## response.text() - -## response.url() - -## response.finished() diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/12-response.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/12-response.md new file mode 100644 index 0000000000..2433de81c8 --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/12-response.md @@ -0,0 +1,27 @@ +--- +title: "Response" +excerpt: "xk6-browser: Response Class" +--- + + + +## Supported APIs + +| Method | Playwright Relevant Distinctions | +| - | - | +| response.allHeaders() | - | +| response.body() | - | +| response.frame() | - | +| response.headers() | - | +| response.headersArray() | - | +| response.headerValue(name) | - | +| response.headerValues(name) | - | +| response.json() | - | +| response.ok() | - | +| response.request() | - | +| response.securityDetails() | - | +| response.serverAddr() | - | +| response.status() | - | +| response.statusText() | - | +| response.text() | - | +| response.url() | - | diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/12-touchscreen.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/12-touchscreen.md deleted file mode 100644 index 0c61386f40..0000000000 --- a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/12-touchscreen.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: "Touchscreen" -excerpt: "xk6-browser: Touchscreen Class" ---- - - - -## touchscreen.tap(x, y) \ No newline at end of file diff --git a/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/13-touchscreen.md b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/13-touchscreen.md new file mode 100644 index 0000000000..1ebe2b1e0b --- /dev/null +++ b/src/data/markdown/docs/30 xk6-browser/01 xk6-browser/13-touchscreen.md @@ -0,0 +1,12 @@ +--- +title: "Touchscreen" +excerpt: "xk6-browser: Touchscreen Class" +--- + + + +## Supported APIs + +| Method | Playwright Relevant Distinctions | +| - | - | +| touchscreen.tap(x, y) | - | diff --git a/src/data/markdown/docs/30 xk6-browser/30 xk6-browser.md b/src/data/markdown/docs/30 xk6-browser/30 xk6-browser.md index 875657f7ec..7756781810 100644 --- a/src/data/markdown/docs/30 xk6-browser/30 xk6-browser.md +++ b/src/data/markdown/docs/30 xk6-browser/30 xk6-browser.md @@ -5,17 +5,44 @@ excerpt: "xk6-browser brings browser automation and end-to-end testing to k6 whi [xk6-browser](/~https://github.com/grafana/xk6-browser) brings browser automation and end-to-end web testing to k6 while supporting core k6 features. It adds browser-level scripting APIs to interact with real browsers and collect frontend metrics as part of your k6 tests. +## Installation + +xk6-browser is currently being developed as a [k6 extension](/extensions). You have to run a k6 version built with the browser extension to use the [browser-level APIs](#browser-level-apis) in your k6 tests. + +### Download a release binary + +The quickest way to get started is to [download a release binary from GitHub](/~https://github.com/grafana/xk6-browser/releases). + +### Build from source + +If you're more adventurous or want to get the latest changes of the xk6-browser extension, you can also build from source. + + + +## Your First Test + +The first step is to import the `chromium` [BrowserType](/javascript-api/xk6-browser/browsertype), and use its `launch` method to start up a Chromium [Browser](/javascript-api/xk6-browser/browser) process (which is currently the only available `BrowserType`). After it starts, you can interact with it using the [browser-level APIs](#browser-level-apis). + +### Example + + + ```javascript -import launcher from 'k6/x/browser'; +import { chromium } from 'k6/x/browser'; export default function () { - const browser = launcher.launch('chromium', { headless: false }); + const browser = chromium.launch({ + headless: false, + slowMo: '500ms', + }); + const context = browser.newContext(); const page = context.newPage(); - page.goto('http://whatsmyuseragent.org/'); + page.goto('https://test.k6.io/browser.php/'); page.screenshot({ path: `example-chromium.png` }); + page.close(); browser.close(); } @@ -23,83 +50,70 @@ export default function () { -## Installation +### Running the Example Test -xk6-browser is currently being developed as a [k6 extension](/extensions). You have to run a k6 version built with the browser extension to use the [browser-level APIs](#browser-level-apis) in your k6 tests. +If you have downloaded the pre-built binary you will find the binary named `xk6-browser`. Using the [example](#example), create a new file (such as `browser_test.js`) in the same directory as the pre-built binary, and paste the example in that file. Now run: -### Download a release binary +``` +xk6-browser run browser_test.js +``` -The quickest way to get started is to [download a release binary from GitHub](/~https://github.com/grafana/xk6-browser/releases). +## Module Properties -### Build from source +Listed in the table are the importable properties from the top level module (`'k6/x/browser'`). -If you're more adventurous or want to get the latest changes of the xk6-browser extension, you can also build from source. +| Property | Description | +|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| chromium | A [BrowserType](/javascript-api/xk6-browser/browsertype) to launch tests in a Chromium-based browser. | +| devices | Returns predefined emulation settings for many end-user devices that can be used to simulate browser behavior on a mobile device. See the [devices example](#devices-example) below. | +| version | Returns the version number of xk6-browser. | + +### Devices Example + + + + + +```javascript +import { chromium, devices } from 'k6/x/browser'; + +export default function () { + const browser = chromium.launch({ headless: false }); + const iphoneX = devices['iPhone X']; + const context = browser.newContext(iphoneX); + const page = context.newPage(); + + page.goto('https://test.k6.io/browser.php/', { + waitUntil: 'networkidle', + }); + + page.close(); + browser.close(); +} +``` + + - ## Browser-level APIs -`xk6-browser` uses [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) to instrument and interact with the browser. The `xk6-browser` APIs aims for rough compatibility with the [Playwright API for NodeJS](https://playwright.dev/docs/api/class-playwright). +`xk6-browser` uses [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) (CDP) to instrument and interact with the browser. The `xk6-browser` APIs aims for rough compatibility with the [Playwright API for NodeJS](https://playwright.dev/docs/api/class-playwright). Note that because k6 does not run in NodeJS, `xk6-browser` APIs will slightly differ from their Playwright counterparts. -Here's a list of the fully (✅) or partially (🚧) implemented classes of the Playwright API (with a more detailed breakdown of missing APIs in the table below): - - - -- 🚧 [Browser](/javascript-api/xk6-browser/browser/) -- 🚧 [BrowserContext](/javascript-api/xk6-browser/browsercontext/) -- 🚧 [BrowserType](/javascript-api/xk6-browser/browsertype/) -- 🚧 [ElementHandle](/javascript-api/xk6-browser/elementhandle/) -- 🚧 [Frame](/javascript-api/xk6-browser/frame/) -- ✅ [JSHandle](/javascript-api/xk6-browser/jshandle) -- ✅ [Keyboard](/javascript-api/xk6-browser/keyboard) -- ✅ [Mouse](/javascript-api/xk6-browser/mouse/) -- 🚧 [Page](/javascript-api/xk6-browser/page/) -- 🚧 [Request](/javascript-api/xk6-browser/request/) -- 🚧 [Response](/javascript-api/xk6-browser/response/) -- 🚧 [Browser](/javascript-api/xk6-browser/browser/) -- ✅ [Touchscreen](/javascript-api/xk6-browser/touchscreen/) - - - -| k6 Class | Missing Playwright APIs | -| - | - | -| [Browser](/javascript-api/xk6-browser/browser/) | [`on()`](https://playwright.dev/docs/api/class-browser#browser-event-disconnected) (dependent on event-loop support in k6), [`startTracing()`](https://playwright.dev/docs/api/class-browser#browser-start-tracing), [`stopTracing()`](https://playwright.dev/docs/api/class-browser#browser-stop-tracing) | -| [BrowserContext](/javascript-api/xk6-browser/browsercontext/) | [`addCookies()`](https://playwright.dev/docs/api/class-browsercontext#browsercontextaddcookiescookies), [`backgroundPages()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-background-pages), [`cookies()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-cookies), [`exposeBinding()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-expose-binding), [`exposeFunction()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-expose-function), [`newCDPSession()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-new-cdp-session), [`on()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-background-page) (dependent on event-loop support in k6), [`route()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-route) (dependent on event-loop support in k6), [`serviceWorkers()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-service-workers), [`storageState()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-storage-state), [`unroute()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-unroute) (dependent on event-loop support in k6), [`waitForEvent()`](https://playwright.dev/docs/api/class-browsercontext#browser-context-wait-for-event) (dependent on event-loop support in k6), [`tracing`](https://playwright.dev/docs/api/class-browsercontext#browser-context-tracing) | -| [BrowserType](/javascript-api/xk6-browser/browsertype/) | [`connect()`](https://playwright.dev/docs/api/class-browsertype#browser-type-connect), [`connectOverCDP()`](https://playwright.dev/docs/api/class-browsertype#browser-type-connect-over-cdp), [`launchPersistentContext()`](https://playwright.dev/docs/api/class-browsertype#browsertypelaunchpersistentcontextuserdatadir-options), [`launchServer()`](https://playwright.dev/docs/api/class-browsertype#browsertypelaunchserveroptions) | -| [ElementHandle](/javascript-api/xk6-browser/elementhandle/) | [`$eval()`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector), [`$$eval()`](https://playwright.dev/docs/api/class-elementhandle#element-handle-eval-on-selector-all), [`setInputFiles()`](https://playwright.dev/docs/api/class-elementhandle#element-handle-set-input-files) | -| [Frame](/javascript-api/xk6-browser/frame/) | [`$eval()`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector), [`$$eval()`](https://playwright.dev/docs/api/class-frame#frame-eval-on-selector-all), [`addScriptTag()`](https://playwright.dev/docs/api/class-frame#frame-add-script-tag), [`addStyleTag()`](https://playwright.dev/docs/api/class-frame#frame-add-style-tag), [`dragAndDrop()`](https://playwright.dev/docs/api/class-frame#frame-drag-and-drop), [`locator()`](https://playwright.dev/docs/api/class-frame#frame-locator), [`setInputFiles()`](https://playwright.dev/docs/api/class-frame#frame-set-input-files) | -| [JSHandle](/javascript-api/xk6-browser/jshandle) | | -| [Keyboard](/javascript-api/xk6-browser/keyboard/) | | -| [Mouse](/javascript-api/xk6-browser/mouse/) | | -| [Page](/javascript-api/xk6-browser/page/) | [`$eval()`](https://playwright.dev/docs/api/class-page#page-eval-on-selector), [`$$eval()`](https://playwright.dev/docs/api/class-page#page-eval-on-selector-all), [`addInitScript()`](https://playwright.dev/docs/api/class-page#page-add-init-script), [`addScriptTag()`](https://playwright.dev/docs/api/class-page#page-add-script-tag), [`addStyleTag()`](https://playwright.dev/docs/api/class-page#page-add-style-tag), [`dragAndDrop()`](https://playwright.dev/docs/api/class-page#page-drag-and-drop), [`exposeBinding()`](https://playwright.dev/docs/api/class-page#page-expose-binding), [`exposeFunction()`](https://playwright.dev/docs/api/class-page#page-expose-function), [`frame()`](https://playwright.dev/docs/api/class-page#page-frame), [`goBack()`](https://playwright.dev/docs/api/class-page#page-go-back), [`goForward()`](https://playwright.dev/docs/api/class-page#page-go-forward), [`locator()`](https://playwright.dev/docs/api/class-page#page-locator), [`on()`](https://playwright.dev/docs/api/class-page#page-event-close) (dependent on event-loop support in k6), [`pause()`](https://playwright.dev/docs/api/class-page#page-pause), [`pdf()`](https://playwright.dev/docs/api/class-page#page-pdf), [`route()`](https://playwright.dev/docs/api/class-page#page-route) (dependent on event-loop support in k6), [`unroute()`](https://playwright.dev/docs/api/class-page#page-unroute) (dependent on event-loop support in k6), [`video()`](https://playwright.dev/docs/api/class-page#page-video), [`waitForEvent()`](https://playwright.dev/docs/api/class-page#page-wait-for-event) (dependent on event-loop support in k6), [`waitForResponse()`](https://playwright.dev/docs/api/class-page#page-wait-for-response) (dependent on event-loop support in k6), [`waitForURL()`](https://playwright.dev/docs/api/class-page#page-wait-for-url) (dependent on event-loop support in k6), [`workers()`](https://playwright.dev/docs/api/class-page#page-workers) | -| [Request](/javascript-api/xk6-browser/request/) | [`failure()`](https://playwright.dev/docs/api/class-request#request-failure) (dependent on event-loop support in k6), [`postDataJSON()`](https://playwright.dev/docs/api/class-request#request-post-data-json), [`redirectFrom()`](https://playwright.dev/docs/api/class-request#request-redirected-from), [`redirectTo()`](https://playwright.dev/docs/api/class-request#request-redirected-to) | -| [Response](/javascript-api/xk6-browser/response/) | [`finished()`](https://playwright.dev/docs/api/class-response#response-finished) (dependent on event-loop support in k6) | -| [Touchscreen](/javascript-api/xk6-browser/touchscreen/) | | - -The following Playwright APIs are not supported yet: - - - -- [Accessibility](https://playwright.dev/docs/api/class-accessibility) -- [BrowserServer](https://playwright.dev/docs/api/class-browserserver) -- [CDPSession](https://playwright.dev/docs/api/class-cdpsession) -- [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) -- [Coverage](https://playwright.dev/docs/api/class-coverage) -- [Dialog](https://playwright.dev/docs/api/class-dialog) -- [Download](https://playwright.dev/docs/api/class-download) -- [FetchRequest](https://playwright.dev/docs/api/class-fetchrequest) -- [FetchResponse](https://playwright.dev/docs/api/class-fetchresponse) -- [FileChooser](https://playwright.dev/docs/api/class-filechooser) -- [Locator](https://playwright.dev/docs/api/class-locator) -- [Logger](https://playwright.dev/docs/api/class-logger) -- [Route](https://playwright.dev/docs/api/class-route) -- [Selectors](https://playwright.dev/docs/api/class-selectors) -- [Tracing](https://playwright.dev/docs/api/class-tracing) -- [Video](https://playwright.dev/docs/api/class-video) -- [WebSocket](https://playwright.dev/docs/api/class-websocket) -- [Worker](https://playwright.dev/docs/api/class-worker) - - +| k6 Class | Description | +|-------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [Browser](/javascript-api/xk6-browser/browser/) | The entry point for all tests and used to launch [BrowserContext](/javascript-api/xk6-browser/browsercontext/)s and [Page](/javascript-api/xk6-browser/page/)s. | +| [BrowserContext](/javascript-api/xk6-browser/browsercontext/) | Enables independent browser sessions with separate [Page](/javascript-api/xk6-browser/page/)s, cache, and cookies. | +| [BrowserType](/javascript-api/xk6-browser/browsertype/) | The `BrowserType` is the entry point into launching a browser process; `chromium` is currently the only supported `BrowserType`. | +| [ElementHandle](/javascript-api/xk6-browser/elementhandle/) | Represents an in-page DOM element. | +| [Frame](/javascript-api/xk6-browser/frame/) | Access and interact with the [`Page`](/javascript-api/xk6-browser/page/).'s `Frame`s. | +| [JSHandle](/javascript-api/xk6-browser/jshandle) | Represents an in-page JavaScript object. | +| [Keyboard](/javascript-api/xk6-browser/keyboard/) | Used to simulate the keyboard interactions with the associated [`Page`](/javascript-api/xk6-browser/page/). | +| [Locator](/javascript-api/xk6-browser/locator/) | The Locator API makes it easier to work with dynamically changing elements. | +| [Mouse](/javascript-api/xk6-browser/mouse/) | Used to simulate the mouse interactions with the associated [`Page`](/javascript-api/xk6-browser/page/). | +| [Page](/javascript-api/xk6-browser/page/) | Provides methods to interact with a single tab in a [`Browser`](/javascript-api/xk6-browser/browser/). | +| [Request](/javascript-api/xk6-browser/request/) | Used to keep track of the request the [`Page`](/javascript-api/xk6-browser/page/) makes. | +| [Response](/javascript-api/xk6-browser/response/) | Represents the response received by the [`Page`](/javascript-api/xk6-browser/page/). | +| [Touchscreen](/javascript-api/xk6-browser/touchscreen/) | Used to simulate touch interactions with the associated [`Page`](/javascript-api/xk6-browser/page/). | diff --git a/src/data/markdown/versioned-js-api/v0.35/javascript api/alternative main modules/30 k6-x-browser.md b/src/data/markdown/versioned-js-api/v0.35/javascript api/alternative main modules/30 k6-x-browser.md index cb58dff15e..94f21cb3f4 100644 --- a/src/data/markdown/versioned-js-api/v0.35/javascript api/alternative main modules/30 k6-x-browser.md +++ b/src/data/markdown/versioned-js-api/v0.35/javascript api/alternative main modules/30 k6-x-browser.md @@ -16,6 +16,7 @@ Here's a list of the fully (✅) or partially (🚧) implemented classes of the - 🚧 [Frame](/javascript-api/xk6-browser/frame/) - ✅ [JSHandle](/javascript-api/xk6-browser/jshandle) - ✅ [Keyboard](/javascript-api/xk6-browser/keyboard) +- 🚧 [Locator](/javascript-api/xk6-browser/locator/) - ✅ [Mouse](/javascript-api/xk6-browser/mouse/) - 🚧 [Page](/javascript-api/xk6-browser/page/) - 🚧 [Request](/javascript-api/xk6-browser/request/) diff --git a/src/data/markdown/versioned-js-api/v0.36/javascript api/alternative main modules/30 k6-x-browser.md b/src/data/markdown/versioned-js-api/v0.36/javascript api/alternative main modules/30 k6-x-browser.md index cb58dff15e..94f21cb3f4 100644 --- a/src/data/markdown/versioned-js-api/v0.36/javascript api/alternative main modules/30 k6-x-browser.md +++ b/src/data/markdown/versioned-js-api/v0.36/javascript api/alternative main modules/30 k6-x-browser.md @@ -16,6 +16,7 @@ Here's a list of the fully (✅) or partially (🚧) implemented classes of the - 🚧 [Frame](/javascript-api/xk6-browser/frame/) - ✅ [JSHandle](/javascript-api/xk6-browser/jshandle) - ✅ [Keyboard](/javascript-api/xk6-browser/keyboard) +- 🚧 [Locator](/javascript-api/xk6-browser/locator/) - ✅ [Mouse](/javascript-api/xk6-browser/mouse/) - 🚧 [Page](/javascript-api/xk6-browser/page/) - 🚧 [Request](/javascript-api/xk6-browser/request/) diff --git a/src/data/markdown/versioned-js-api/v0.37/javascript api/alternative main modules/30 k6-x-browser.md b/src/data/markdown/versioned-js-api/v0.37/javascript api/alternative main modules/30 k6-x-browser.md index cb58dff15e..94f21cb3f4 100644 --- a/src/data/markdown/versioned-js-api/v0.37/javascript api/alternative main modules/30 k6-x-browser.md +++ b/src/data/markdown/versioned-js-api/v0.37/javascript api/alternative main modules/30 k6-x-browser.md @@ -16,6 +16,7 @@ Here's a list of the fully (✅) or partially (🚧) implemented classes of the - 🚧 [Frame](/javascript-api/xk6-browser/frame/) - ✅ [JSHandle](/javascript-api/xk6-browser/jshandle) - ✅ [Keyboard](/javascript-api/xk6-browser/keyboard) +- 🚧 [Locator](/javascript-api/xk6-browser/locator/) - ✅ [Mouse](/javascript-api/xk6-browser/mouse/) - 🚧 [Page](/javascript-api/xk6-browser/page/) - 🚧 [Request](/javascript-api/xk6-browser/request/) diff --git a/src/data/markdown/versioned-js-api/v0.38/javascript api/alternative main modules/30 k6-x-browser.md b/src/data/markdown/versioned-js-api/v0.38/javascript api/alternative main modules/30 k6-x-browser.md index cb58dff15e..94f21cb3f4 100644 --- a/src/data/markdown/versioned-js-api/v0.38/javascript api/alternative main modules/30 k6-x-browser.md +++ b/src/data/markdown/versioned-js-api/v0.38/javascript api/alternative main modules/30 k6-x-browser.md @@ -16,6 +16,7 @@ Here's a list of the fully (✅) or partially (🚧) implemented classes of the - 🚧 [Frame](/javascript-api/xk6-browser/frame/) - ✅ [JSHandle](/javascript-api/xk6-browser/jshandle) - ✅ [Keyboard](/javascript-api/xk6-browser/keyboard) +- 🚧 [Locator](/javascript-api/xk6-browser/locator/) - ✅ [Mouse](/javascript-api/xk6-browser/mouse/) - 🚧 [Page](/javascript-api/xk6-browser/page/) - 🚧 [Request](/javascript-api/xk6-browser/request/)