-
Notifications
You must be signed in to change notification settings - Fork 15
/
02.cookies.js
54 lines (44 loc) · 1.29 KB
/
02.cookies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { browser } from "k6/browser";
import { check } from "k6";
const BASE_URL = __ENV.BASE_URL || "http://localhost:3333";
export const options = {
scenarios: {
ui: {
executor: "shared-iterations",
options: {
browser: {
type: "chromium",
},
},
},
},
};
export default async function () {
const pizzaContext = await browser.newContext();
await pizzaContext.addCookies([
{
name: "FooBar",
value: 123456,
domain: BASE_URL,
path: '/',
},
]);
const pizzaPage = await pizzaContext.newPage();
const cookies = await pizzaContext.cookies();
await pizzaPage.goto(BASE_URL);
check(cookies, {
"cookie length of QuickPizza page": cookies => cookies.length === 1,
"cookie name": cookies => cookies[0].name === "FooBar",
"cookie value": cookies => cookies[0].value === "123456"
});
await pizzaPage.close();
await pizzaContext.close();
const anotherContext = await browser.newContext();
const anotherPage = await anotherContext.newPage();
const anotherCookies = await anotherContext.cookies();
await anotherPage.goto('https://example.org/');
check(anotherCookies, {
"cookie length of example test page": anotherCookies => anotherCookies.length === 0,
});
await anotherPage.close();
}