Skip to content

Commit 7e825d8

Browse files
authored
Merge pull request #1367 from grafana/release/v0.47.0
Documentation for k6 v0.47.0
2 parents 4e8c865 + f845011 commit 7e825d8

File tree

368 files changed

+18458
-108
lines changed

Some content is hidden

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

368 files changed

+18458
-108
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ The [browser module API](/javascript-api/k6-experimental/browser#browser-module-
1010
If a [page](/javascript-api/k6-experimental/browser/page/) opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's `BrowserContext`.
1111

1212

13-
| Method | Description |
14-
|-------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
15-
| [BrowserContext.addCookies()](/javascript-api/k6-experimental/browser/browsercontext/addcookies/) | Adds cookies into the `BrowserContext`. |
16-
| [BrowserContext.clearCookies()](/javascript-api/k6-experimental/browser/browsercontext/clearcookies/) <BWIPT id="442"/> | Clear the `BrowserContext`'s cookies. |
17-
| [BrowserContext.clearPermissions()](/javascript-api/k6-experimental/browser/browsercontext/clearpermissions) <BWIPT id="443"/> | Clears all permission overrides for the `BrowserContext`. |
18-
| [BrowserContext.close()](/javascript-api/k6-experimental/browser/browsercontext/close) | Close the `BrowserContext` and all its [page](/javascript-api/k6-experimental/browser/page/)s. |
19-
| [BrowserContext.grantPermissions(permissions[, options])](/javascript-api/k6-experimental/browser/browsercontext/grantpermissions) | Grants specified permissions to the `BrowserContext`. |
20-
| [BrowserContext.newPage()](/javascript-api/k6-experimental/browser/browsercontext/newpage) | Uses the `BrowserContext` to create a new [Page](/javascript-api/k6-experimental/browser/page/) and returns it. |
21-
| [BrowserContext.pages()](/javascript-api/k6-experimental/browser/browsercontext/pages) <BWIPT id="444"/> | Returns a list of [page](/javascript-api/k6-experimental/browser/page/)s that belongs to the `BrowserContext`. |
22-
| [BrowserContext.setDefaultNavigationTimeout(timeout)](/javascript-api/k6-experimental/browser/browsercontext/setdefaultnavigationtimeout) <BWIPT id="445"/> | Sets the default navigation timeout in milliseconds. |
23-
| [BrowserContext.setDefaultTimeout(timeout)](/javascript-api/k6-experimental/browser/browsercontext/setdefaulttimeout) <BWIPT id="456"/> | Sets the default maximum timeout for all methods accepting a timeout option in milliseconds. |
24-
| [BrowserContext.setGeolocation(geolocation)](/javascript-api/k6-experimental/browser/browsercontext/setgeolocation) <BWIPT id="435"/> | Sets the `BrowserContext`'s geolocation. |
25-
| [BrowserContext.setOffline(offline)](/javascript-api/k6-experimental/browser/browsercontext/setoffline) | Toggles the `BrowserContext`'s connectivity on/off. |
26-
| [BrowserContext.waitForEvent(event[, optionsOrPredicate])](/javascript-api/k6-experimental/browser/browsercontext/waitforevent) <BWIPT id="447"/> | Waits for the event to fire and passes its value into the predicate function. |
13+
| Method | Description |
14+
| ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
15+
| [BrowserContext.addCookies()](/javascript-api/k6-experimental/browser/browsercontext/addcookies/) | Adds [cookies](/javascript-api/k6-experimental/browser/browsercontext/cookie) into the `BrowserContext`. |
16+
| [BrowserContext.clearCookies()](/javascript-api/k6-experimental/browser/browsercontext/clearcookies/) | Clear the `BrowserContext`'s [cookies](/javascript-api/k6-experimental/browser/browsercontext/cookie). |
17+
| [BrowserContext.clearPermissions()](/javascript-api/k6-experimental/browser/browsercontext/clearpermissions) <BWIPT id="443"/> | Clears all permission overrides for the `BrowserContext`. |
18+
| [BrowserContext.cookies()](/javascript-api/k6-experimental/browser/browsercontext/cookies) | Returns a list of [cookies](/javascript-api/k6-experimental/browser/browsercontext/cookie) from the `BrowserContext`. |
19+
| [BrowserContext.close()](/javascript-api/k6-experimental/browser/browsercontext/close) | Close the `BrowserContext` and all its [page](/javascript-api/k6-experimental/browser/page/)s. |
20+
| [BrowserContext.grantPermissions(permissions[, options])](/javascript-api/k6-experimental/browser/browsercontext/grantpermissions) | Grants specified permissions to the `BrowserContext`. |
21+
| [BrowserContext.newPage()](/javascript-api/k6-experimental/browser/browsercontext/newpage) | Uses the `BrowserContext` to create a new [Page](/javascript-api/k6-experimental/browser/page/) and returns it. |
22+
| [BrowserContext.pages()](/javascript-api/k6-experimental/browser/browsercontext/pages) <BWIPT id="444"/> | Returns a list of [page](/javascript-api/k6-experimental/browser/page/)s that belongs to the `BrowserContext`. |
23+
| [BrowserContext.setDefaultNavigationTimeout(timeout)](/javascript-api/k6-experimental/browser/browsercontext/setdefaultnavigationtimeout) | Sets the default navigation timeout in milliseconds. |
24+
| [BrowserContext.setDefaultTimeout(timeout)](/javascript-api/k6-experimental/browser/browsercontext/setdefaulttimeout) | Sets the default maximum timeout for all methods accepting a timeout option in milliseconds. |
25+
| [BrowserContext.setGeolocation(geolocation)](/javascript-api/k6-experimental/browser/browsercontext/setgeolocation) <BWIPT id="435"/> | Sets the `BrowserContext`'s geolocation. |
26+
| [BrowserContext.setOffline(offline)](/javascript-api/k6-experimental/browser/browsercontext/setoffline) | Toggles the `BrowserContext`'s connectivity on/off. |
27+
| [BrowserContext.waitForEvent(event[, optionsOrPredicate])](/javascript-api/k6-experimental/browser/browsercontext/waitforevent) <BWIPT id="447"/> | Waits for the event to fire and passes its value into the predicate function. |

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

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ title: 'addCookies()'
33
excerpt: 'Clears context cookies.'
44
---
55

6-
Adds cookies into the `BrowserContext`. All pages within this context will have these cookies installed.
6+
Adds a list of [cookies](/javascript-api/k6-experimental/browser/browsercontext/cookie) into the [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/cookie). All pages within this [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/cookie) will have these [cookies](/javascript-api/k6-experimental/browser/browsercontext/cookie) set.
7+
8+
<Blockquote mod="info">
9+
10+
If a [cookie](/javascript-api/k6-experimental/browser/browsercontext/cookie)'s `url` property is not provided, both `domain` and `path` properties must be specified.
11+
12+
</Blockquote>
13+
714

815
### Example
916

@@ -27,18 +34,54 @@ export const options = {
2734

2835
export default async function () {
2936
const context = browser.newContext();
37+
const page = context.newPage();
3038

31-
context.addCookies([
32-
{
33-
name: 'myCookie',
34-
value: 'hello world',
35-
url: 'https://test.k6.io/',
36-
},
37-
]);
39+
try {
40+
const unixTimeSinceEpoch = Math.round(new Date() / 1000);
41+
const day = 60*60*24;
42+
const dayAfter = unixTimeSinceEpoch+day;
43+
const dayBefore = unixTimeSinceEpoch-day;
3844

39-
const page = context.newPage();
40-
await page.goto('https://test.k6.io/');
41-
page.close();
45+
context.addCookies([
46+
// this cookie expires at the end of the session
47+
{
48+
name: 'testcookie',
49+
value: '1',
50+
sameSite: 'Strict',
51+
domain: 'httpbin.org',
52+
path: '/',
53+
httpOnly: true,
54+
secure: true,
55+
},
56+
// this cookie expires in a day
57+
{
58+
name: 'testcookie2',
59+
value: '2',
60+
sameSite: 'Lax',
61+
domain: 'httpbin.org',
62+
path: '/',
63+
expires: dayAfter,
64+
},
65+
// this cookie expires in the past, so it will be removed.
66+
{
67+
name: 'testcookie3',
68+
value: '3',
69+
sameSite: 'Lax',
70+
domain: 'httpbin.org',
71+
path: '/',
72+
expires: dayBefore
73+
}
74+
]);
75+
76+
const response = await page.goto('https://httpbin.org/cookies', {
77+
waitUntil: 'networkidle',
78+
});
79+
console.log(response.json());
80+
// prints:
81+
// {"cookies":{"testcookie":"1","testcookie2":"2"}}
82+
} finally {
83+
page.close();
84+
}
4285
}
4386
```
4487

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ title: 'clearCookies()'
33
excerpt: 'Clears context cookies.'
44
---
55

6-
<Blockquote mod="attention">
7-
8-
This feature has **known issues**. For details, refer to
9-
[#442](https://github.com/grafana/xk6-browser/issues/442).
10-
11-
</Blockquote>
12-
136
Clears the `BrowserContext`'s cookies.
147

158
### Example
@@ -36,8 +29,11 @@ export default async function () {
3629
const context = browser.newContext();
3730
const page = context.newPage();
3831

39-
await page.goto('https://test.k6.io/');
32+
await page.goto('https://httpbin.org/cookies/set?testcookie=testcookievalue');
33+
console.log(context.cookies().length); // prints: 1
34+
4035
context.clearCookies();
36+
console.log(context.cookies().length); // prints: 0
4137
}
4238
```
4339

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: "Cookie"
3+
excerpt: "Browser module: Cookie Class"
4+
---
5+
6+
Cookie class represents a cookie in the [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext).
7+
8+
See the [HTTP Cookies documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) on the Mozilla website for more details about cookies.
9+
10+
| Property | Type | Default | Description |
11+
| -------- | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
12+
| name | string | `""` | The cookie's name. Required. |
13+
| value | string | `""` | The cookie's value. Required. |
14+
| domain | string | `""` | The cookie's domain. |
15+
| path | string | `'/'` | The cookie's path. |
16+
| url | string | `""` | The cookie's URL. |
17+
| expires | number | `-1` | The cookie's expiration date as the number of seconds since the UNIX epoch. `-1` means a session cookie. |
18+
| httpOnly | bool | `false` | A cookie is inaccessible to the JavaScript [document.cookie](https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie) API when this property is `true`. |
19+
| secure | bool | `false` | The cookie's secure flag. |
20+
| sameSite | string | `'Lax'` | The cookie's same site flag. It can be one of `'Strict'`, `'Lax'`, and `'None'`. |
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: 'cookies([urls])'
3+
excerpt: 'Retrieves context cookies.'
4+
---
5+
6+
Returns a list of [cookies](/javascript-api/k6-experimental/browser/browsercontext/cookie) from the [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext) filtered by the provided `urls`. If no `urls` are provided, all cookies are returned.
7+
8+
| Parameter | Type | Description |
9+
|----------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
10+
| urls | array | A string array of URLs to filter the [cookies](/javascript-api/k6-experimental/browser/browsercontext/cookie) in the [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext). |
11+
12+
### Returns
13+
14+
| Type | Description |
15+
| ---- | ----------- |
16+
| array | A list of [cookies](/javascript-api/k6-experimental/browser/browsercontext/cookie). |
17+
18+
<Blockquote mod="info">
19+
20+
[Cookies](/javascript-api/k6-experimental/browser/browsercontext/cookie) can be added with [BrowserContext.addCookies](/javascript-api/k6-experimental/browser/browsercontext/addcookies/).
21+
22+
</Blockquote>
23+
24+
### Example
25+
26+
<CodeGroup labels={[]}>
27+
28+
```javascript
29+
import { browser } from 'k6/experimental/browser';
30+
31+
export const options = {
32+
scenarios: {
33+
ui: {
34+
executor: 'shared-iterations',
35+
options: {
36+
browser: {
37+
type: 'chromium',
38+
},
39+
},
40+
},
41+
},
42+
};
43+
44+
export default async function () {
45+
const context = browser.newContext();
46+
const page = context.newPage();
47+
48+
try {
49+
// get cookies from the browser context
50+
let cookies = context.cookies();
51+
console.log("initial cookies length:", cookies.length); // prints 0
52+
53+
// let's add more cookies to filter by urls
54+
context.addCookies([
55+
{ name: 'foo', value: 'foovalue', sameSite: 'Strict', url: 'http://foo.com' },
56+
{ name: 'bar', value: 'barvalue', sameSite: 'Lax', url: 'https://bar.com' },
57+
{ name: 'baz', value: 'bazvalue', sameSite: 'Lax', url: 'https://baz.com' }
58+
]);
59+
60+
// get all cookies
61+
cookies = context.cookies();
62+
console.log("filtered cookies length:", cookies.length); // prints 3
63+
64+
// get cookies filtered by urls
65+
cookies = context.cookies('http://foo.com', 'https://baz.com');
66+
console.log("filtered cookies length:", cookies.length); // prints 2
67+
68+
// the first filtered cookie
69+
console.log("1st cookie's name :", cookies[0].name); // prints foo
70+
console.log("1st cookie's value:", cookies[0].value); // prints foovalue
71+
// the first filtered cookie
72+
console.log("2nd cookie's name :", cookies[1].name); // prints baz
73+
console.log("2nd cookie's value:", cookies[1].value); // prints bazvalue
74+
} finally {
75+
page.close();
76+
}
77+
}
78+
```
79+
80+
</CodeGroup>

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ title: 'setDefaultNavigationTimeout(timeout)'
33
excerpt: 'Sets the default navigation timeout in milliseconds.'
44
---
55

6-
<Blockquote mod="attention">
7-
8-
This feature has **known issues.** For details, refer to
9-
[#445](https://github.com/grafana/xk6-browser/issues/445).
10-
11-
</Blockquote>
12-
136
Sets the default maximum navigation timeout for [Page.goto()](https://playwright.dev/docs/api/class-page#page-goto).
147

158
| Parameter | Type | Default | Description |

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ title: 'setDefaultTimeout(timeout)'
33
excerpt: 'Sets the default timeout in milliseconds.'
44
---
55

6-
<Blockquote mod="attention">
7-
8-
This feature has **known issues**. For details, refer to
9-
[#456](https://github.com/grafana/xk6-browser/issues/456).
10-
11-
</Blockquote>
12-
136
Sets the default maximum timeout for all methods accepting a `timeout` option in milliseconds.
147

158
| Parameter | Type | Default | Description |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: "ConsoleMessage"
3+
excerpt: "Browser module: ConsoleMessage Class"
4+
---
5+
6+
<BrowserDocsWIP/>
7+
8+
## Supported APIs
9+
10+
| Method | Playwright Relevant Distinctions |
11+
| - | - |
12+
| <a href="https://playwright.dev/docs/api/class-consolemessage#console-message-args" target="_blank" >consoleMessage.args()</a> | - |
13+
| <a href="https://playwright.dev/docs/api/class-consolemessage#console-message-page" target="_blank" >consoleMessage.page()</a> | - |
14+
| <a href="https://playwright.dev/docs/api/class-consolemessage#console-message-text" target="_blank" >consoleMessage.text()</a> | - |
15+
| <a href="https://playwright.dev/docs/api/class-consolemessage#console-message-type" target="_blank" >consoleMessage.type()</a> | - |

0 commit comments

Comments
 (0)