You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: 'The k6 testing library provides test assertion capabilities for both protocol and browser testing.'
4
4
weight: 00
5
5
---
6
6
7
-
# testing
7
+
# k6-testing
8
8
9
-
The k6 testing library provides assertion capabilities for both protocol and browser testing, and draws inspiration from Playwright's test API design. The entire library is centered around the [`expect()`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/testing/expect) function, which can be configured for convenience.
9
+
The k6 testing library provides assertion capabilities for both protocol and browser testing, and draws inspiration from _Playwright_'s test API design.
10
+
The entire library is centered around the [`expect()`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/testing/expect) function, which can be configured for convenience.
10
11
11
12
{{< admonition type="note" >}}
12
13
The k6 testing library source code is available on [GitHub](https://github.com/grafana/k6-jslib-testing).
13
14
{{< /admonition >}}
14
15
15
16
## Features
16
17
17
-
-**Playwright-inspired assertions**: API designed with patterns inspired by Playwright's testing approach
18
+
-**[Playwright-inspired assertions](https://playwright.dev/docs/test-assertions)**: API designed with patterns inspired by Playwright's testing approach
18
19
-**[Protocol and browser testing](#demo)**: Works with both HTTP/API testing and browser automation
19
20
-**[Auto-retrying assertions](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/testing/expect#retrying-assertions)**: Automatically retry assertions until they pass or timeout
20
21
-**[Soft assertions](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/testing/expect#soft-assertions)**: Continue test execution even after assertion failures
Synchronous assertions that evaluate immediately. These are ideal for testing static values, API responses, and scenarios where the expected condition should be true at the moment of evaluation.
Asynchronous assertions that automatically retry until conditions become true or timeout. These are suitable for browser testing, dynamic content, and scenarios where conditions may change over time.
120
128
121
129
## API Reference
122
130
123
-
| Function | Description |
124
-
| --- | --- |
125
-
|[expect()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/testing/expect)| Main assertion function |
Copy file name to clipboardExpand all lines: docs/sources/k6/next/javascript-api/k6-browser/_index.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,9 @@ weight: 02
8
8
9
9
# browser
10
10
11
-
The browser module APIs aim for rough compatibility with the [Playwright API for NodeJS](https://playwright.dev/docs/api/class-playwright).
11
+
The browser module APIs are inspired by Playwright and other frontend testing frameworks.
12
12
13
-
Note that because k6 does not run in NodeJS, the browser module APIs will slightly differ from their Playwright counterparts.
14
-
15
-
You can find examples of using [the browser module API](#browser-module-api) in our [getting started guide](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser).
13
+
You can find examples of using [the browser module API](#browser-module-api) in the [getting started guide](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser).
The method returns an element [Locator](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/). Locators resolve to the element when the action takes place, which means locators can span over navigations where the underlying dom changes.
| selector | string |`''`| A selector to use when resolving a DOM element. |
15
+
| options | object |`null`||
16
+
| options.hasText | string or RegExp |`null`| Matches only elements that contain the specified text. String or regular expression. Optional. |
17
+
| options.hasNotText | string or RegExp |`null`| Matches only elements that do not contain the specified text. String or regular expression. Optional. |
FrameLocator represents a view to an `iframe` on the page. It captures the logic sufficient to retrieve the `iframe` and locate elements in that `iframe`. FrameLocator can be created with `locator.contentFrame()` method.
9
+
FrameLocator represents a way to find element(s) in an `iframe`. Frames can be nested, and this locator supports selecting a frame element and then working with it.
10
+
11
+
A FrameLocator can be created with the `locator.contentFrame()` method.
@@ -17,4 +19,4 @@ FrameLocator represents a view to an `iframe` on the page. It captures the logic
17
19
|[getByTestId(testId)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/framelocator/getbytestid/)| Returns a locator for elements with the specified `data-testid` attribute. |
18
20
|[getByText(text[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/framelocator/getbytext/)| Returns a locator for elements containing the specified text. |
19
21
|[getByTitle(title[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/framelocator/getbytitle/)| Returns a locator for elements with the specified `title` attribute. |
20
-
|[locator(selector)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/framelocator/locator)| Returns a [Locator](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator) for the given `selector`. |
22
+
|[locator(selector[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/framelocator/locator)| Returns a new chained `locator` for the given `selector` within the frame.|
0 commit comments