@serenity-js/web 3.0.0-rc.13 → 3.0.0-rc.14

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/lib/errors/index.js +5 -1
  3. package/lib/errors/index.js.map +1 -1
  4. package/lib/expectations/index.js +5 -1
  5. package/lib/expectations/index.js.map +1 -1
  6. package/lib/expectations/isVisible.d.ts +4 -1
  7. package/lib/expectations/isVisible.js +4 -1
  8. package/lib/expectations/isVisible.js.map +1 -1
  9. package/lib/index.js +5 -1
  10. package/lib/index.js.map +1 -1
  11. package/lib/input/index.js +5 -1
  12. package/lib/input/index.js.map +1 -1
  13. package/lib/screenplay/abilities/index.js +5 -1
  14. package/lib/screenplay/abilities/index.js.map +1 -1
  15. package/lib/screenplay/index.js +5 -1
  16. package/lib/screenplay/index.js.map +1 -1
  17. package/lib/screenplay/interactions/index.js +5 -1
  18. package/lib/screenplay/interactions/index.js.map +1 -1
  19. package/lib/screenplay/models/PageElement.d.ts +9 -0
  20. package/lib/screenplay/models/PageElement.js +1 -2
  21. package/lib/screenplay/models/PageElement.js.map +1 -1
  22. package/lib/screenplay/models/PageElements.js +2 -2
  23. package/lib/screenplay/models/PageElements.js.map +1 -1
  24. package/lib/screenplay/models/index.js +5 -1
  25. package/lib/screenplay/models/index.js.map +1 -1
  26. package/lib/screenplay/models/selectors/index.js +5 -1
  27. package/lib/screenplay/models/selectors/index.js.map +1 -1
  28. package/lib/screenplay/questions/Attribute.d.ts +62 -25
  29. package/lib/screenplay/questions/Attribute.js +68 -27
  30. package/lib/screenplay/questions/Attribute.js.map +1 -1
  31. package/lib/screenplay/questions/CssClasses.d.ts +70 -26
  32. package/lib/screenplay/questions/CssClasses.js +76 -30
  33. package/lib/screenplay/questions/CssClasses.js.map +1 -1
  34. package/lib/screenplay/questions/Selected.d.ts +5 -5
  35. package/lib/screenplay/questions/Selected.js +2 -2
  36. package/lib/screenplay/questions/Selected.js.map +1 -1
  37. package/lib/screenplay/questions/Text.d.ts +22 -18
  38. package/lib/screenplay/questions/Text.js +61 -19
  39. package/lib/screenplay/questions/Text.js.map +1 -1
  40. package/lib/screenplay/questions/Value.d.ts +55 -16
  41. package/lib/screenplay/questions/Value.js +59 -18
  42. package/lib/screenplay/questions/Value.js.map +1 -1
  43. package/lib/screenplay/questions/index.js +5 -1
  44. package/lib/screenplay/questions/index.js.map +1 -1
  45. package/lib/stage/crew/index.js +5 -1
  46. package/lib/stage/crew/index.js.map +1 -1
  47. package/lib/stage/crew/photographer/index.js +5 -1
  48. package/lib/stage/crew/photographer/index.js.map +1 -1
  49. package/lib/stage/crew/photographer/strategies/index.js +5 -1
  50. package/lib/stage/crew/photographer/strategies/index.js.map +1 -1
  51. package/lib/stage/index.js +5 -1
  52. package/lib/stage/index.js.map +1 -1
  53. package/package.json +6 -6
  54. package/src/expectations/isVisible.ts +4 -1
  55. package/src/screenplay/models/PageElement.ts +11 -2
  56. package/src/screenplay/models/PageElements.ts +3 -3
  57. package/src/screenplay/questions/Attribute.ts +85 -34
  58. package/src/screenplay/questions/CssClasses.ts +82 -30
  59. package/src/screenplay/questions/Selected.ts +7 -7
  60. package/src/screenplay/questions/Text.ts +80 -25
  61. package/src/screenplay/questions/Value.ts +67 -20
  62. package/lib/screenplay/questions/ElementQuestion.d.ts +0 -33
  63. package/lib/screenplay/questions/ElementQuestion.js +0 -53
  64. package/lib/screenplay/questions/ElementQuestion.js.map +0 -1
  65. package/src/screenplay/questions/ElementQuestion.ts +0 -58
@@ -2,13 +2,12 @@ import { Answerable, AnswersQuestions, d, MetaQuestion, Question, QuestionAdapte
2
2
  import { asyncMap } from '@serenity-js/core/lib/io';
3
3
 
4
4
  import { PageElement, PageElements } from '../models';
5
- import { ElementQuestion } from './ElementQuestion';
6
5
 
7
6
  /**
8
7
  * @desc
9
8
  * Resolves to the visible (i.e. not hidden by CSS) `innerText` of:
10
- * - a given {@link WebElement}, represented by Answerable<{@link @wdio/types~Element}>
11
- * - a group of {@link WebElement}s, represented by Answerable<{@link @wdio/types~ElementList}>
9
+ * - a given {@link PageElement}
10
+ * - a group of {@link PageElements}
12
11
  *
13
12
  * The result includes the visible text of any sub-elements, without any leading or trailing whitespace.
14
13
  *
@@ -23,13 +22,15 @@ import { ElementQuestion } from './ElementQuestion';
23
22
  * @example <caption>Retrieve text of a single element</caption>
24
23
  * import { actorCalled } from '@serenity-js/core';
25
24
  * import { Ensure, equals } from '@serenity-js/assertions';
26
- * import { BrowseTheWeb, by, Target, Text } from '@serenity-js/webdriverio';
25
+ * import { By, PageElement, Text } from '@serenity-js/web';
26
+ * import { BrowseTheWebWithWebdriverIO } from '@serenity-js/webdriverio';
27
27
  *
28
28
  * const header = () =>
29
- * Target.the('header').located(by.tagName('h1'))
29
+ * PageElement.located(By.css('h1'))
30
+ * .describedAs('header')
30
31
  *
31
32
  * actorCalled('Lisa')
32
- * .whoCan(BrowseTheWeb.using(browser))
33
+ * .whoCan(BrowseTheWebWithWebdriverIO.using(browser))
33
34
  * .attemptsTo(
34
35
  * Ensure.that(Text.of(header()), equals('Shopping list')),
35
36
  * )
@@ -37,13 +38,15 @@ import { ElementQuestion } from './ElementQuestion';
37
38
  * @example <caption>Retrieve text of a multiple elements</caption>
38
39
  * import { actorCalled } from '@serenity-js/core';
39
40
  * import { Ensure, equals } from '@serenity-js/assertions';
40
- * import { BrowseTheWeb, by, Target, Text } from '@serenity-js/webdriverio';
41
+ * import { By, PageElement, Text } from '@serenity-js/web';
42
+ * import { BrowseTheWebWithWebdriverIO } from '@serenity-js/webdriverio';
41
43
  *
42
44
  * const shoppingListItems = () =>
43
- * Target.the('shopping list items').located(by.css('#shopping-list li'))
45
+ * PageElements.located(By.css('#shopping-list li'))
46
+ * .describedAs('shopping list items')
44
47
  *
45
48
  * actorCalled('Lisa')
46
- * .whoCan(BrowseTheWeb.using(browser))
49
+ * .whoCan(BrowseTheWebWithWebdriverIO.using(browser))
47
50
  * .attemptsTo(
48
51
  * Ensure.that(
49
52
  * Text.ofAll(shoppingListItems()),
@@ -54,15 +57,17 @@ import { ElementQuestion } from './ElementQuestion';
54
57
  * @example <caption>Find element with matching text</caption>
55
58
  * import { actorCalled } from '@serenity-js/core';
56
59
  * import { contain, Ensure } from '@serenity-js/assertions';
57
- * import { BrowseTheWeb, by, CssClasses, Target, Text } from '@serenity-js/webdriverio';
60
+ * import { By, CssClasses, PageElement, Text } from '@serenity-js/web';
61
+ * import { BrowseTheWebWithWebdriverIO } from '@serenity-js/webdriverio';
58
62
  *
59
63
  * const shoppingListItemCalled = (name: string) =>
60
- * Target.the('shopping list items').located(by.css('#shopping-list li'))
64
+ * PageElements.located(By.css('#shopping-list li'))
65
+ * .describedAs('shopping list items')
61
66
  * .where(Text, equals(name))
62
67
  * .first()
63
68
  *
64
69
  * actorCalled('Lisa')
65
- * .whoCan(BrowseTheWeb.using(browser))
70
+ * .whoCan(BrowseTheWebWithWebdriverIO.using(browser))
66
71
  * .attemptsTo(
67
72
  * Ensure.that(
68
73
  * CssClasses.of(shoppingListItemCalled('Honey)),
@@ -77,11 +82,10 @@ export class Text {
77
82
 
78
83
  /**
79
84
  * @desc
80
- * Retrieves text of a single {@link WebElement},
81
- * represented by Answerable<{@link @wdio/types~Element}>.
85
+ * Retrieves text of a single {@link PageElement}.
82
86
  *
83
87
  * @param {Answerable<PageElement>} element
84
- * @returns {Question<Promise<string>> & MetaQuestion<Answerable<PageElement>, Promise<string>>}
88
+ * @returns {@serenity-js/core/lib/screenplay~QuestionAdapter<string>}
85
89
  *
86
90
  * @see {@link @serenity-js/core/lib/screenplay/questions~MetaQuestion}
87
91
  */
@@ -94,11 +98,10 @@ export class Text {
94
98
 
95
99
  /**
96
100
  * @desc
97
- * Retrieves text of a group of {@link WebElement}s,
98
- * represented by Answerable<{@link @wdio/types~ElementList}>
101
+ * Retrieves text of a group of {@link PageElements}.
99
102
  *
100
- * @param {Answerable<PageElement[]>} elements
101
- * @returns {Question<Promise<string[]>> & MetaQuestion<Answerable<PageElement>, Promise<string[]>>}
103
+ * @param {Answerable<PageElements | PageElement[]>} elements
104
+ * @returns {@serenity-js/core/lib/screenplay~QuestionAdapter<string[]>}
102
105
  *
103
106
  * @see {@link @serenity-js/core/lib/screenplay/questions~MetaQuestion}
104
107
  */
@@ -118,15 +121,21 @@ export class Text {
118
121
  }
119
122
 
120
123
  class TextOfSingleElement
121
- extends ElementQuestion<Promise<string>>
124
+ extends Question<Promise<string>>
122
125
  implements MetaQuestion<Answerable<PageElement>, Promise<string>>
123
126
  {
127
+ /**
128
+ * @private
129
+ */
130
+ private subject: string;
131
+
124
132
  static of(element: Answerable<PageElement>): QuestionAdapter<string> & MetaQuestion<Answerable<PageElement>, Promise<string>> {
125
133
  return Question.createAdapter(new TextOfSingleElement(element)) as QuestionAdapter<string> & MetaQuestion<Answerable<PageElement>, Promise<string>>;
126
134
  }
127
135
 
128
- constructor(private readonly element: Answerable<PageElement>) {
129
- super(`the text of ${ element }`);
136
+ protected constructor(private readonly element: Answerable<PageElement>) {
137
+ super();
138
+ this.subject = d`the text of ${ element }`;
130
139
  }
131
140
 
132
141
  of(parent: Answerable<PageElement>): Question<Promise<string>> {
@@ -138,18 +147,44 @@ class TextOfSingleElement
138
147
 
139
148
  return element.text();
140
149
  }
150
+
151
+ /**
152
+ * @desc
153
+ * Changes the description of this question's subject.
154
+ *
155
+ * @param {string} subject
156
+ * @returns {Question<T>}
157
+ */
158
+ describedAs(subject: string): this {
159
+ this.subject = subject;
160
+ return this;
161
+ }
162
+
163
+ /**
164
+ * @returns {string}
165
+ * Returns a human-readable representation of this {@link @serenity-js/core/lib/screenplay~Question}.
166
+ */
167
+ toString(): string {
168
+ return this.subject;
169
+ }
141
170
  }
142
171
 
143
172
  class TextOfMultipleElements
144
- extends ElementQuestion<Promise<string[]>>
173
+ extends Question<Promise<string[]>>
145
174
  implements MetaQuestion<Answerable<PageElement>, Promise<string[]>>
146
175
  {
176
+ /**
177
+ * @private
178
+ */
179
+ private subject: string;
180
+
147
181
  static of(elements: PageElements): QuestionAdapter<string[]> & MetaQuestion<Answerable<PageElement>, Promise<string[]>> {
148
182
  return Question.createAdapter(new TextOfMultipleElements(elements)) as QuestionAdapter<string[]> & MetaQuestion<Answerable<PageElement>, Promise<string[]>>;
149
183
  }
150
184
 
151
- constructor(private readonly elements: PageElements) {
152
- super(d`the text of ${ elements }`);
185
+ protected constructor(private readonly elements: PageElements) {
186
+ super();
187
+ this.subject = d`the text of ${ elements }`;
153
188
  }
154
189
 
155
190
  of(parent: Answerable<PageElement>): Question<Promise<string[]>> {
@@ -161,4 +196,24 @@ class TextOfMultipleElements
161
196
 
162
197
  return asyncMap(elements, element => element.text());
163
198
  }
199
+
200
+ /**
201
+ * @desc
202
+ * Changes the description of this question's subject.
203
+ *
204
+ * @param {string} subject
205
+ * @returns {Question<T>}
206
+ */
207
+ describedAs(subject: string): this {
208
+ this.subject = subject;
209
+ return this;
210
+ }
211
+
212
+ /**
213
+ * @returns {string}
214
+ * Returns a human-readable representation of this {@link @serenity-js/core/lib/screenplay~Question}.
215
+ */
216
+ toString(): string {
217
+ return this.subject;
218
+ }
164
219
  }
@@ -1,60 +1,87 @@
1
- import { Answerable, AnswersQuestions, MetaQuestion, Question, UsesAbilities } from '@serenity-js/core';
2
- import { formatted } from '@serenity-js/core/lib/io';
1
+ import { Answerable, AnswersQuestions, d, MetaQuestion, Question, QuestionAdapter, UsesAbilities } from '@serenity-js/core';
3
2
 
4
3
  import { PageElement } from '../models';
5
- import { ElementQuestion } from './ElementQuestion';
6
4
 
7
5
  /**
8
6
  * @desc
9
- * Returns the `value` attribute of a given {@link WebElement},
10
- * represented by Answerable<{@link @wdio/types~Element}>
7
+ * Retrieves the `value` attribute of a given {@link PageElement}.
11
8
  *
12
9
  * @example <caption>Example widget</caption>
13
10
  * <input type="text" id="username" value="Alice" />
14
11
  *
15
- * @example <caption>Retrieve CSS classes of a given WebElement</caption>
12
+ * @example <caption>Retrieve the `value` of a given PageElement</caption>
16
13
  * import { actorCalled } from '@serenity-js/core';
17
14
  * import { Ensure, equals } from '@serenity-js/assertions';
18
- * import { BrowseTheWeb, by, Value, Target } from '@serenity-js/webdriverio';
15
+ * import { By, PageElement, Value } from '@serenity-js/web';
16
+ * import { BrowseTheWebWithWebdriverIO } from '@serenity-js/webdriverio';
19
17
  *
20
18
  * const usernameField = () =>
21
- * Target.the('username field').located(by.id('username'))
19
+ * PageElement.located(By.id('username')).describedAs('username field')
22
20
  *
23
21
  * actorCalled('Lisa')
24
- * .whoCan(BrowseTheWeb.using(browser))
22
+ * .whoCan(BrowseTheWebWithWebdriverIO.using(browser))
25
23
  * .attemptsTo(
26
24
  * Ensure.that(Value.of(usernameField), equals('Alice')),
27
25
  * )
28
26
  *
27
+ * @example <caption>Using Value as QuestionAdapter</caption>
28
+ * import { actorCalled } from '@serenity-js/core';
29
+ * import { Ensure, equals } from '@serenity-js/assertions';
30
+ * import { By, PageElement, Value } from '@serenity-js/web';
31
+ * import { BrowseTheWebWithWebdriverIO } from '@serenity-js/webdriverio';
32
+ *
33
+ * const usernameField = () =>
34
+ * PageElement.located(By.id('username')).describedAs('username field')
35
+ *
36
+ * actorCalled('Lisa')
37
+ * .whoCan(BrowseTheWebWithWebdriverIO.using(browser))
38
+ * .attemptsTo(
39
+ * Ensure.that(
40
+ * Value.of(usernameField).toLocaleLowerCase()[0],
41
+ * equals('a') // [a]lice
42
+ * ),
43
+ * )
44
+ *
29
45
  * @extends {@serenity-js/core/lib/screenplay~Question}
30
46
  * @implements {@serenity-js/core/lib/screenplay/questions~MetaQuestion}
31
47
  */
32
48
  export class Value
33
- extends ElementQuestion<Promise<string>>
49
+ extends Question<Promise<string>>
34
50
  implements MetaQuestion<Answerable<PageElement>, Promise<string>>
35
51
  {
36
52
  /**
37
- * @param {Answerable<PageElement>} element
38
- * @returns {Value}
53
+ * @private
39
54
  */
40
- static of(element: Answerable<PageElement>): Question<Promise<string>> & MetaQuestion<Answerable<PageElement>, Promise<string>> {
41
- return new Value(element);
55
+ private subject: string;
56
+
57
+ /**
58
+ * @desc
59
+ * Retrieves the `value` attribute of a given {@link PageElement}.
60
+ *
61
+ * @param {@serenity-js/core/lib/screenplay~Answerable<PageElement>} element
62
+ * @returns {@serenity-js/core/lib/screenplay~QuestionAdapter<string>}
63
+ *
64
+ * @see {@link @serenity-js/core/lib/screenplay/questions~MetaQuestion}
65
+ */
66
+ static of(element: Answerable<PageElement>): QuestionAdapter<string> & MetaQuestion<Answerable<PageElement>, Promise<string>> {
67
+ return Question.createAdapter(new Value(element)) as QuestionAdapter<string> & MetaQuestion<Answerable<PageElement>, Promise<string>>;
42
68
  }
43
69
 
44
70
  /**
45
71
  * @param {Answerable<PageElement>} element
46
72
  */
47
73
  constructor(private readonly element: Answerable<PageElement>) {
48
- super(formatted`the value of ${ element }`);
74
+ super();
75
+ this.subject = d`the value of ${ element }`;
49
76
  }
50
77
 
51
78
  /**
52
79
  * @desc
53
- * Resolves to the value of a given [`input`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input)
54
- * {@link WebElement}, located in the context of a `parent` element.
80
+ * Retrieves the `value` attribute of a given {@link PageElement}.
81
+ * located within the `parent` element.
55
82
  *
56
- * @param {Answerable<PageElement>} parent
57
- * @returns {Question<Promise<string>>}
83
+ * @param {@serenity-js/core/lib/screenplay~Answerable<PageElement>} parent
84
+ * @returns {@serenity-js/core/lib/screenplay~QuestionAdapter<string>}
58
85
  *
59
86
  * @see {@link @serenity-js/core/lib/screenplay/questions~MetaQuestion}
60
87
  */
@@ -75,8 +102,28 @@ export class Value
75
102
  * @see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities}
76
103
  */
77
104
  async answeredBy(actor: AnswersQuestions & UsesAbilities): Promise<string> {
78
- const element = await this.resolve(actor, this.element);
105
+ const element = await actor.answer(this.element);
79
106
 
80
107
  return element.value();
81
108
  }
109
+
110
+ /**
111
+ * @desc
112
+ * Changes the description of this question's subject.
113
+ *
114
+ * @param {string} subject
115
+ * @returns {Question<T>}
116
+ */
117
+ describedAs(subject: string): this {
118
+ this.subject = subject;
119
+ return this;
120
+ }
121
+
122
+ /**
123
+ * @returns {string}
124
+ * Returns a human-readable representation of this {@link @serenity-js/core/lib/screenplay~Question}.
125
+ */
126
+ toString(): string {
127
+ return this.subject;
128
+ }
82
129
  }
@@ -1,33 +0,0 @@
1
- import { Answerable, AnswersQuestions, Question } from '@serenity-js/core';
2
- /**
3
- * @desc
4
- * A base class for questions about {@link PageElement}s.
5
- *
6
- * @extends {@serenity-js/core/lib/screenplay~Question}
7
- */
8
- export declare abstract class ElementQuestion<T> extends Question<T> {
9
- protected subject: string;
10
- constructor(subject: string);
11
- /**
12
- * @desc
13
- * Changes the description of this question's subject.
14
- *
15
- * @param {string} subject
16
- * @returns {Question<T>}
17
- */
18
- describedAs(subject: string): this;
19
- toString(): string;
20
- /**
21
- * @desc
22
- * Returns the resolved {@link PageElement}, or throws a {@link @serenity-js/core/lib/errors~LogicError}
23
- * if the element is `undefined`.
24
- *
25
- * @param {@serenity-js/core/lib/screenplay/actor~AnswersQuestions} actor
26
- * @param {@serenity-js/core/lib/screenplay~Answerable<Element|ElementList>} element
27
- *
28
- * @returns {Promise<PageElement|PageElements>}
29
- *
30
- * @protected
31
- */
32
- protected resolve<T>(actor: AnswersQuestions, element: Answerable<T>): Promise<T>;
33
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ElementQuestion = void 0;
4
- const core_1 = require("@serenity-js/core");
5
- const io_1 = require("@serenity-js/core/lib/io");
6
- /**
7
- * @desc
8
- * A base class for questions about {@link PageElement}s.
9
- *
10
- * @extends {@serenity-js/core/lib/screenplay~Question}
11
- */
12
- // todo: remove
13
- class ElementQuestion extends core_1.Question {
14
- constructor(subject) {
15
- super();
16
- this.subject = subject;
17
- }
18
- /**
19
- * @desc
20
- * Changes the description of this question's subject.
21
- *
22
- * @param {string} subject
23
- * @returns {Question<T>}
24
- */
25
- describedAs(subject) {
26
- this.subject = subject;
27
- return this;
28
- }
29
- toString() {
30
- return this.subject;
31
- }
32
- /**
33
- * @desc
34
- * Returns the resolved {@link PageElement}, or throws a {@link @serenity-js/core/lib/errors~LogicError}
35
- * if the element is `undefined`.
36
- *
37
- * @param {@serenity-js/core/lib/screenplay/actor~AnswersQuestions} actor
38
- * @param {@serenity-js/core/lib/screenplay~Answerable<Element|ElementList>} element
39
- *
40
- * @returns {Promise<PageElement|PageElements>}
41
- *
42
- * @protected
43
- */
44
- async resolve(actor, element) {
45
- const resolved = await actor.answer(element);
46
- if (!resolved) {
47
- throw new core_1.LogicError((0, io_1.formatted) `Couldn't find ${element}`);
48
- }
49
- return resolved;
50
- }
51
- }
52
- exports.ElementQuestion = ElementQuestion;
53
- //# sourceMappingURL=ElementQuestion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ElementQuestion.js","sourceRoot":"","sources":["../../../src/screenplay/questions/ElementQuestion.ts"],"names":[],"mappings":";;;AAAA,4CAAuF;AACvF,iDAAqD;AAErD;;;;;GAKG;AACH,eAAe;AACf,MAAsB,eAClB,SAAQ,eAAW;IAEnB,YAAsB,OAAe;QACjC,KAAK,EAAE,CAAC;QADU,YAAO,GAAP,OAAO,CAAQ;IAErC,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,OAAe;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,QAAQ;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED;;;;;;;;;;;OAWG;IACO,KAAK,CAAC,OAAO,CACnB,KAAuB,EACvB,OAAsB;QAEtB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAI,CAAE,QAAQ,EAAE;YACZ,MAAM,IAAI,iBAAU,CAAC,IAAA,cAAS,EAAC,iBAAkB,OAAQ,EAAE,CAAC,CAAC;SAChE;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AA/CD,0CA+CC"}
@@ -1,58 +0,0 @@
1
- import { Answerable, AnswersQuestions, LogicError, Question } from '@serenity-js/core';
2
- import { formatted } from '@serenity-js/core/lib/io';
3
-
4
- /**
5
- * @desc
6
- * A base class for questions about {@link PageElement}s.
7
- *
8
- * @extends {@serenity-js/core/lib/screenplay~Question}
9
- */
10
- // todo: remove
11
- export abstract class ElementQuestion<T>
12
- extends Question<T>
13
- {
14
- constructor(protected subject: string) {
15
- super();
16
- }
17
-
18
- /**
19
- * @desc
20
- * Changes the description of this question's subject.
21
- *
22
- * @param {string} subject
23
- * @returns {Question<T>}
24
- */
25
- describedAs(subject: string): this {
26
- this.subject = subject;
27
- return this;
28
- }
29
-
30
- toString(): string {
31
- return this.subject;
32
- }
33
-
34
- /**
35
- * @desc
36
- * Returns the resolved {@link PageElement}, or throws a {@link @serenity-js/core/lib/errors~LogicError}
37
- * if the element is `undefined`.
38
- *
39
- * @param {@serenity-js/core/lib/screenplay/actor~AnswersQuestions} actor
40
- * @param {@serenity-js/core/lib/screenplay~Answerable<Element|ElementList>} element
41
- *
42
- * @returns {Promise<PageElement|PageElements>}
43
- *
44
- * @protected
45
- */
46
- protected async resolve<T>(
47
- actor: AnswersQuestions,
48
- element: Answerable<T>,
49
- ): Promise<T> {
50
- const resolved = await actor.answer(element);
51
-
52
- if (! resolved) {
53
- throw new LogicError(formatted `Couldn't find ${ element }`);
54
- }
55
-
56
- return resolved;
57
- }
58
- }