@serenity-js/web 3.0.0-rc.35 → 3.0.0-rc.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +0 -2
- package/lib/screenplay/models/Cookie.d.ts +66 -5
- package/lib/screenplay/models/Cookie.d.ts.map +1 -1
- package/lib/screenplay/models/Cookie.js +65 -4
- package/lib/screenplay/models/Cookie.js.map +1 -1
- package/package.json +9 -9
- package/src/screenplay/models/Cookie.ts +67 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.0.0-rc.37](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.36...v3.0.0-rc.37) (2022-12-18)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **web:** support for setting cookies using async or partially async data ([ec8a65d](https://github.com/serenity-js/serenity-js/commit/ec8a65d9e3c1e2eb311d14eb32f1de9e26b5879b)), closes [#1421](https://github.com/serenity-js/serenity-js/issues/1421)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [3.0.0-rc.36](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.35...v3.0.0-rc.36) (2022-11-28)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @serenity-js/web
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
# [3.0.0-rc.35](https://github.com/serenity-js/serenity-js/compare/v3.0.0-rc.34...v3.0.0-rc.35) (2022-11-25)
|
|
7
26
|
|
|
8
27
|
|
package/README.md
CHANGED
|
@@ -17,5 +17,3 @@ If you have any questions, join us on [Serenity/JS Community Chat](https://gitte
|
|
|
17
17
|
## Serenity/JS Web
|
|
18
18
|
|
|
19
19
|
[`@serenity-js/web`](https://serenity-js.org/modules/web/) contains Serenity/JS Screenplay Pattern APIs for testing Web apps.
|
|
20
|
-
|
|
21
|
-
[](https://app.saucelabs.com/builds/b709ea824727341f8cf23a82ce1cfe59)
|
|
@@ -1,9 +1,68 @@
|
|
|
1
|
-
import { Answerable, Interaction, Optional, QuestionAdapter, Timestamp } from '@serenity-js/core';
|
|
1
|
+
import { Answerable, Interaction, Optional, QuestionAdapter, Timestamp, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
2
|
import { CookieData } from './CookieData';
|
|
3
3
|
/**
|
|
4
4
|
* A Screenplay Pattern-style model responsible for managing cookies available to the current {@apilink Page}.
|
|
5
5
|
*
|
|
6
|
+
* ## Checking if a cookie exists
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
10
|
+
* import { Navigate, Cookie } from '@serenity-js/web'
|
|
11
|
+
* import { Ensure, isPresent } from '@serenity-js/assertions'
|
|
12
|
+
*
|
|
13
|
+
* await actorCalled('Sid')
|
|
14
|
+
* .attemptsTo(
|
|
15
|
+
* Navigate.to('https://example.org'),
|
|
16
|
+
*
|
|
17
|
+
* Ensure.that(
|
|
18
|
+
* Cookie.called('example-cookie-name'),
|
|
19
|
+
* isPresent()
|
|
20
|
+
* ),
|
|
21
|
+
* )
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* ## Setting a cookie
|
|
25
|
+
*
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
28
|
+
* import { Navigate, Cookie } from '@serenity-js/web'
|
|
29
|
+
* import { Ensure, isPresent, not } from '@serenity-js/assertions'
|
|
30
|
+
*
|
|
31
|
+
* await actorCalled('Sid')
|
|
32
|
+
* .attemptsTo(
|
|
33
|
+
* Navigate.to('https://example.org'),
|
|
34
|
+
*
|
|
35
|
+
* Ensure.that(Cookie.called('example-cookie-name'), not(isPresent())),
|
|
36
|
+
*
|
|
37
|
+
* Cookie.set({
|
|
38
|
+
* name: 'favourite',
|
|
39
|
+
* value: 'triple chocolate',
|
|
40
|
+
* }),
|
|
41
|
+
*
|
|
42
|
+
* Ensure.that(Cookie.called('example-cookie-name'), isPresent()),
|
|
43
|
+
* )
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* ## Reading a cookie
|
|
47
|
+
*
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
50
|
+
* import { Navigate, Cookie } from '@serenity-js/web'
|
|
51
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
52
|
+
*
|
|
53
|
+
* await actorCalled('Sid')
|
|
54
|
+
* .attemptsTo(
|
|
55
|
+
* Navigate.to('https://example.org'),
|
|
56
|
+
*
|
|
57
|
+
* Ensure.that(
|
|
58
|
+
* Cookie.called('some-cookie-name').value(),
|
|
59
|
+
* equals('triple chocolate')
|
|
60
|
+
* ),
|
|
61
|
+
* )
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
6
64
|
* ## Learn more
|
|
65
|
+
* - {@apilink CookieData}
|
|
7
66
|
* - {@apilink Page.cookie}
|
|
8
67
|
*
|
|
9
68
|
* @group Models
|
|
@@ -17,14 +76,16 @@ export declare abstract class Cookie implements Optional {
|
|
|
17
76
|
*/
|
|
18
77
|
static called(name: Answerable<string>): QuestionAdapter<Cookie>;
|
|
19
78
|
/**
|
|
20
|
-
* Sets a cookie for the current {@apilink Page}.
|
|
79
|
+
* Sets a cookie for the current {@apilink Page}. Note that {@apilink CookieData} can be either a plain-old JavaScript object, or an {@apilink Answerable} {@apilink WithAnswerableProperties}.
|
|
21
80
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
81
|
+
* :::info
|
|
82
|
+
* Make sure that the actor performing this interaction is on the page that should receive the cookie.
|
|
83
|
+
* Because of browser security restrictions, an actor can't set a cookie for an arbitrary page without being on that page.
|
|
84
|
+
* :::
|
|
24
85
|
*
|
|
25
86
|
* @param cookieData
|
|
26
87
|
*/
|
|
27
|
-
static set(cookieData: Answerable<CookieData
|
|
88
|
+
static set(cookieData: Answerable<WithAnswerableProperties<CookieData>>): Interaction;
|
|
28
89
|
/**
|
|
29
90
|
* Creates an {@apilink Interaction|interaction} to delete all cookies available to the current {@apilink Page}..
|
|
30
91
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cookie.d.ts","sourceRoot":"","sources":["../../../src/screenplay/models/Cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAK,WAAW,EAAE,QAAQ,EAAY,eAAe,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"Cookie.d.ts","sourceRoot":"","sources":["../../../src/screenplay/models/Cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAK,WAAW,EAAE,QAAQ,EAAY,eAAe,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAKzI,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,8BAAsB,MAAO,YAAW,QAAQ;IA2DtB,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM;IAzD3D;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC;IAQhE;;;;;;;;;OASG;IACH,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAC,GAAG,WAAW;IAsBrF;;OAEG;IACH,MAAM,CAAC,SAAS,IAAI,WAAW;IAO/B,OAAO,CAAC,MAAM,CAAa;IAE3B,SAAS,aAAgC,UAAU,EAAE,MAAM;IAI3D;;OAEG;IACH,IAAI,IAAI,MAAM;IAId;;;;;OAKG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAcnC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAK9B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAK7B;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAK/B;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAKpC;;;;;OAKG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAKlC;;;;;OAKG;IACG,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC;IAKlC;;OAEG;IACH,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAEhC;;;;;;;OAOG;IACH,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC;IAE9C;;OAEG;YACW,cAAc;CAO/B"}
|
|
@@ -8,7 +8,66 @@ const abilities_1 = require("../abilities");
|
|
|
8
8
|
/**
|
|
9
9
|
* A Screenplay Pattern-style model responsible for managing cookies available to the current {@apilink Page}.
|
|
10
10
|
*
|
|
11
|
+
* ## Checking if a cookie exists
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
15
|
+
* import { Navigate, Cookie } from '@serenity-js/web'
|
|
16
|
+
* import { Ensure, isPresent } from '@serenity-js/assertions'
|
|
17
|
+
*
|
|
18
|
+
* await actorCalled('Sid')
|
|
19
|
+
* .attemptsTo(
|
|
20
|
+
* Navigate.to('https://example.org'),
|
|
21
|
+
*
|
|
22
|
+
* Ensure.that(
|
|
23
|
+
* Cookie.called('example-cookie-name'),
|
|
24
|
+
* isPresent()
|
|
25
|
+
* ),
|
|
26
|
+
* )
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ## Setting a cookie
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
33
|
+
* import { Navigate, Cookie } from '@serenity-js/web'
|
|
34
|
+
* import { Ensure, isPresent, not } from '@serenity-js/assertions'
|
|
35
|
+
*
|
|
36
|
+
* await actorCalled('Sid')
|
|
37
|
+
* .attemptsTo(
|
|
38
|
+
* Navigate.to('https://example.org'),
|
|
39
|
+
*
|
|
40
|
+
* Ensure.that(Cookie.called('example-cookie-name'), not(isPresent())),
|
|
41
|
+
*
|
|
42
|
+
* Cookie.set({
|
|
43
|
+
* name: 'favourite',
|
|
44
|
+
* value: 'triple chocolate',
|
|
45
|
+
* }),
|
|
46
|
+
*
|
|
47
|
+
* Ensure.that(Cookie.called('example-cookie-name'), isPresent()),
|
|
48
|
+
* )
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* ## Reading a cookie
|
|
52
|
+
*
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
55
|
+
* import { Navigate, Cookie } from '@serenity-js/web'
|
|
56
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
57
|
+
*
|
|
58
|
+
* await actorCalled('Sid')
|
|
59
|
+
* .attemptsTo(
|
|
60
|
+
* Navigate.to('https://example.org'),
|
|
61
|
+
*
|
|
62
|
+
* Ensure.that(
|
|
63
|
+
* Cookie.called('some-cookie-name').value(),
|
|
64
|
+
* equals('triple chocolate')
|
|
65
|
+
* ),
|
|
66
|
+
* )
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
11
69
|
* ## Learn more
|
|
70
|
+
* - {@apilink CookieData}
|
|
12
71
|
* - {@apilink Page.cookie}
|
|
13
72
|
*
|
|
14
73
|
* @group Models
|
|
@@ -27,16 +86,18 @@ class Cookie {
|
|
|
27
86
|
});
|
|
28
87
|
}
|
|
29
88
|
/**
|
|
30
|
-
* Sets a cookie for the current {@apilink Page}.
|
|
89
|
+
* Sets a cookie for the current {@apilink Page}. Note that {@apilink CookieData} can be either a plain-old JavaScript object, or an {@apilink Answerable} {@apilink WithAnswerableProperties}.
|
|
31
90
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
91
|
+
* :::info
|
|
92
|
+
* Make sure that the actor performing this interaction is on the page that should receive the cookie.
|
|
93
|
+
* Because of browser security restrictions, an actor can't set a cookie for an arbitrary page without being on that page.
|
|
94
|
+
* :::
|
|
34
95
|
*
|
|
35
96
|
* @param cookieData
|
|
36
97
|
*/
|
|
37
98
|
static set(cookieData) {
|
|
38
99
|
return core_1.Interaction.where((0, core_1.d) `#actor sets cookie: ${cookieData}`, async (actor) => {
|
|
39
|
-
const cookie = (0, tiny_types_1.ensure)('cookieData', await actor.answer(cookieData), (0, tiny_types_1.isDefined)(), (0, tiny_types_1.isPlainObject)());
|
|
100
|
+
const cookie = (0, tiny_types_1.ensure)('cookieData', await actor.answer(core_1.Question.fromObject(cookieData)), (0, tiny_types_1.isDefined)(), (0, tiny_types_1.isPlainObject)());
|
|
40
101
|
const page = await abilities_1.BrowseTheWeb.as(actor).currentPage();
|
|
41
102
|
const sanitisedCookieData = {
|
|
42
103
|
name: (0, tiny_types_1.ensure)(`Cookie.set(cookieData.name)`, cookie.name, (0, tiny_types_1.isDefined)(), (0, tiny_types_1.isString)()),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cookie.js","sourceRoot":"","sources":["../../../src/screenplay/models/Cookie.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"Cookie.js","sourceRoot":"","sources":["../../../src/screenplay/models/Cookie.ts"],"names":[],"mappings":";;;AAAA,4CAAyI;AACzI,2CAAqH;AAErH,yCAAkD;AAClD,4CAA4C;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,MAAsB,MAAM;IAExB;;;;OAIG;IACH,MA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GAOG;AACH,SAAS,eAAe,CAA6B,IAAgB,EAAE,QAAW,EAAE,GAAG,UAA2C;IAC9H,OAAO,IAAI,CAAC,QAAQ,CAAC;QACjB,CAAC,CAAC,IAAA,mBAAM,EAAC,yBAAyB,QAAQ,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,UAAU,CAAC;QAC7E,CAAC,CAAC,SAAS,CAAC;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-js/web",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.37",
|
|
4
4
|
"description": "Serenity/JS Screenplay Pattern APIs for the Web",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jan Molak",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"web"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"clean": "rimraf
|
|
30
|
+
"clean": "rimraf '../../target/coverage/web'",
|
|
31
31
|
"test": "nyc mocha --config ../../.mocharc.yml 'spec/**/*.spec.*'",
|
|
32
|
-
"compile": "tsc --project tsconfig.build.json"
|
|
32
|
+
"compile": "rimraf lib && tsc --project tsconfig.build.json"
|
|
33
33
|
},
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|
|
@@ -44,18 +44,18 @@
|
|
|
44
44
|
"npm": "^6 || ^7 || ^8"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@serenity-js/assertions": "3.0.0-rc.
|
|
48
|
-
"@serenity-js/core": "3.0.0-rc.
|
|
47
|
+
"@serenity-js/assertions": "3.0.0-rc.37",
|
|
48
|
+
"@serenity-js/core": "3.0.0-rc.37",
|
|
49
49
|
"tiny-types": "^1.19.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@integration/testing-tools": "3.0.0",
|
|
53
53
|
"@types/chai": "^4.3.4",
|
|
54
|
-
"@types/mocha": "^10.0.
|
|
55
|
-
"mocha": "^10.
|
|
54
|
+
"@types/mocha": "^10.0.1",
|
|
55
|
+
"mocha": "^10.2.0",
|
|
56
56
|
"nyc": "15.1.0",
|
|
57
57
|
"ts-node": "^10.9.1",
|
|
58
|
-
"typescript": "^4.9.
|
|
58
|
+
"typescript": "^4.9.4"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "7856213c0d34cc512e55c22c2d2635832c3499b8"
|
|
61
61
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Answerable, d, Interaction, Optional, Question, QuestionAdapter, Timestamp } from '@serenity-js/core';
|
|
1
|
+
import { Answerable, d, Interaction, Optional, Question, QuestionAdapter, Timestamp, WithAnswerableProperties } from '@serenity-js/core';
|
|
2
2
|
import { ensure, isBoolean, isDefined, isInstanceOf, isOneOf, isPlainObject, isString, Predicate } from 'tiny-types';
|
|
3
3
|
|
|
4
4
|
import { CookieMissingError } from '../../errors';
|
|
@@ -8,7 +8,66 @@ import { CookieData } from './CookieData';
|
|
|
8
8
|
/**
|
|
9
9
|
* A Screenplay Pattern-style model responsible for managing cookies available to the current {@apilink Page}.
|
|
10
10
|
*
|
|
11
|
+
* ## Checking if a cookie exists
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
15
|
+
* import { Navigate, Cookie } from '@serenity-js/web'
|
|
16
|
+
* import { Ensure, isPresent } from '@serenity-js/assertions'
|
|
17
|
+
*
|
|
18
|
+
* await actorCalled('Sid')
|
|
19
|
+
* .attemptsTo(
|
|
20
|
+
* Navigate.to('https://example.org'),
|
|
21
|
+
*
|
|
22
|
+
* Ensure.that(
|
|
23
|
+
* Cookie.called('example-cookie-name'),
|
|
24
|
+
* isPresent()
|
|
25
|
+
* ),
|
|
26
|
+
* )
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ## Setting a cookie
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
33
|
+
* import { Navigate, Cookie } from '@serenity-js/web'
|
|
34
|
+
* import { Ensure, isPresent, not } from '@serenity-js/assertions'
|
|
35
|
+
*
|
|
36
|
+
* await actorCalled('Sid')
|
|
37
|
+
* .attemptsTo(
|
|
38
|
+
* Navigate.to('https://example.org'),
|
|
39
|
+
*
|
|
40
|
+
* Ensure.that(Cookie.called('example-cookie-name'), not(isPresent())),
|
|
41
|
+
*
|
|
42
|
+
* Cookie.set({
|
|
43
|
+
* name: 'favourite',
|
|
44
|
+
* value: 'triple chocolate',
|
|
45
|
+
* }),
|
|
46
|
+
*
|
|
47
|
+
* Ensure.that(Cookie.called('example-cookie-name'), isPresent()),
|
|
48
|
+
* )
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* ## Reading a cookie
|
|
52
|
+
*
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { actorCalled } from '@serenity-js/core'
|
|
55
|
+
* import { Navigate, Cookie } from '@serenity-js/web'
|
|
56
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
57
|
+
*
|
|
58
|
+
* await actorCalled('Sid')
|
|
59
|
+
* .attemptsTo(
|
|
60
|
+
* Navigate.to('https://example.org'),
|
|
61
|
+
*
|
|
62
|
+
* Ensure.that(
|
|
63
|
+
* Cookie.called('some-cookie-name').value(),
|
|
64
|
+
* equals('triple chocolate')
|
|
65
|
+
* ),
|
|
66
|
+
* )
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
11
69
|
* ## Learn more
|
|
70
|
+
* - {@apilink CookieData}
|
|
12
71
|
* - {@apilink Page.cookie}
|
|
13
72
|
*
|
|
14
73
|
* @group Models
|
|
@@ -29,17 +88,19 @@ export abstract class Cookie implements Optional {
|
|
|
29
88
|
}
|
|
30
89
|
|
|
31
90
|
/**
|
|
32
|
-
* Sets a cookie for the current {@apilink Page}.
|
|
91
|
+
* Sets a cookie for the current {@apilink Page}. Note that {@apilink CookieData} can be either a plain-old JavaScript object, or an {@apilink Answerable} {@apilink WithAnswerableProperties}.
|
|
33
92
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
93
|
+
* :::info
|
|
94
|
+
* Make sure that the actor performing this interaction is on the page that should receive the cookie.
|
|
95
|
+
* Because of browser security restrictions, an actor can't set a cookie for an arbitrary page without being on that page.
|
|
96
|
+
* :::
|
|
36
97
|
*
|
|
37
98
|
* @param cookieData
|
|
38
99
|
*/
|
|
39
|
-
static set(cookieData: Answerable<CookieData
|
|
100
|
+
static set(cookieData: Answerable<WithAnswerableProperties<CookieData>>): Interaction {
|
|
40
101
|
|
|
41
102
|
return Interaction.where(d `#actor sets cookie: ${ cookieData }`, async actor => {
|
|
42
|
-
const cookie = ensure('cookieData', await actor.answer(cookieData), isDefined(), isPlainObject());
|
|
103
|
+
const cookie = ensure('cookieData', await actor.answer(Question.fromObject(cookieData)) as CookieData, isDefined(), isPlainObject());
|
|
43
104
|
|
|
44
105
|
const page = await BrowseTheWeb.as(actor).currentPage();
|
|
45
106
|
|