expect-webdriverio 4.3.0 → 4.4.0

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.
@@ -0,0 +1,26 @@
1
+ import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
2
+ async function condition(el, label, options) {
3
+ const actualLabel = await el.getComputedLabel();
4
+ if (Array.isArray(label)) {
5
+ return compareTextWithArray(actualLabel, label, options);
6
+ }
7
+ return compareText(actualLabel, label, options);
8
+ }
9
+ export async function toHaveComputedLabel(received, label, options = {}) {
10
+ const isNot = this.isNot;
11
+ const { expectation = 'computed label', verb = 'have' } = this;
12
+ let el = await received;
13
+ let actualLabel;
14
+ const pass = await waitUntil(async () => {
15
+ const result = await executeCommand.call(this, el, condition, options, [label, options]);
16
+ el = result.el;
17
+ actualLabel = result.values;
18
+ return result.success;
19
+ }, isNot, options);
20
+ updateElementsArray(pass, received, el);
21
+ const message = enhanceError(el, wrapExpectedWithArray(el, actualLabel, label), actualLabel, this, verb, expectation, '', options);
22
+ return {
23
+ pass,
24
+ message: () => message,
25
+ };
26
+ }
@@ -0,0 +1,7 @@
1
+ import { toHaveComputedLabel } from './toHaveComputedLabel.js';
2
+ export function toHaveComputedLabelContaining(el, label, options = {}) {
3
+ return toHaveComputedLabel.call(this, el, label, {
4
+ ...options,
5
+ containing: true
6
+ });
7
+ }
@@ -0,0 +1,26 @@
1
+ import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
2
+ async function condition(el, role, options) {
3
+ const actualRole = await el.getComputedRole();
4
+ if (Array.isArray(role)) {
5
+ return compareTextWithArray(actualRole, role, options);
6
+ }
7
+ return compareText(actualRole, role, options);
8
+ }
9
+ export async function toHaveComputedRole(received, role, options = {}) {
10
+ const isNot = this.isNot;
11
+ const { expectation = 'computed role', verb = 'have' } = this;
12
+ let el = await received;
13
+ let actualRole;
14
+ const pass = await waitUntil(async () => {
15
+ const result = await executeCommand.call(this, el, condition, options, [role, options]);
16
+ el = result.el;
17
+ actualRole = result.values;
18
+ return result.success;
19
+ }, isNot, options);
20
+ updateElementsArray(pass, received, el);
21
+ const message = enhanceError(el, wrapExpectedWithArray(el, actualRole, role), actualRole, this, verb, expectation, '', options);
22
+ return {
23
+ pass,
24
+ message: () => message,
25
+ };
26
+ }
@@ -0,0 +1,7 @@
1
+ import { toHaveComputedRole } from './toHaveComputedRole.js';
2
+ export function toHaveComputedRoleContaining(el, role, options = {}) {
3
+ return toHaveComputedRole.call(this, el, role, {
4
+ ...options,
5
+ containing: true
6
+ });
7
+ }
@@ -0,0 +1,26 @@
1
+ import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
2
+ async function condition(el, html, options) {
3
+ const actualHTML = await el.getHTML(options.includeSelectorTag);
4
+ if (Array.isArray(html)) {
5
+ return compareTextWithArray(actualHTML, html, options);
6
+ }
7
+ return compareText(actualHTML, html, options);
8
+ }
9
+ export async function toHaveHTML(received, html, options = {}) {
10
+ const isNot = this.isNot;
11
+ const { expectation = 'HTML', verb = 'have' } = this;
12
+ let el = await received;
13
+ let actualHTML;
14
+ const pass = await waitUntil(async () => {
15
+ const result = await executeCommand.call(this, el, condition, options, [html, options]);
16
+ el = result.el;
17
+ actualHTML = result.values;
18
+ return result.success;
19
+ }, isNot, options);
20
+ updateElementsArray(pass, received, el);
21
+ const message = enhanceError(el, wrapExpectedWithArray(el, actualHTML, html), actualHTML, this, verb, expectation, '', options);
22
+ return {
23
+ pass,
24
+ message: () => message
25
+ };
26
+ }
@@ -0,0 +1,7 @@
1
+ import { toHaveHTML } from './toHaveHTML.js';
2
+ export function toHaveHTMLContaining(el, html, options = {}) {
3
+ return toHaveHTML.call(this, el, html, {
4
+ ...options,
5
+ containing: true
6
+ });
7
+ }
@@ -0,0 +1,26 @@
1
+ import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
2
+ async function condition(el, height) {
3
+ const actualHeight = await el.getSize('height');
4
+ return {
5
+ value: actualHeight,
6
+ result: actualHeight === height,
7
+ };
8
+ }
9
+ export async function toHaveHeight(received, height, options = {}) {
10
+ const isNot = this.isNot;
11
+ const { expectation = 'height', verb = 'have' } = this;
12
+ let el = await received;
13
+ let actualHeight;
14
+ const pass = await waitUntil(async () => {
15
+ const result = await executeCommand.call(this, el, condition, options, [height, options]);
16
+ el = result.el;
17
+ actualHeight = result.values;
18
+ return result.success;
19
+ }, isNot, options);
20
+ updateElementsArray(pass, received, el);
21
+ const message = enhanceError(el, wrapExpectedWithArray(el, actualHeight, height), actualHeight, this, verb, expectation, '', options);
22
+ return {
23
+ pass,
24
+ message: () => message,
25
+ };
26
+ }
@@ -0,0 +1,23 @@
1
+ import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray, compareObject, } from '../../utils.js';
2
+ async function condition(el, size) {
3
+ const actualSize = await el.getSize();
4
+ return compareObject(actualSize, size);
5
+ }
6
+ export async function toHaveSize(received, size, options = {}) {
7
+ const isNot = this.isNot;
8
+ const { expectation = 'size', verb = 'have' } = this;
9
+ let el = await received;
10
+ let actualSize;
11
+ const pass = await waitUntil(async () => {
12
+ const result = await executeCommand.call(this, el, condition, options, [size, options]);
13
+ el = result.el;
14
+ actualSize = result.values;
15
+ return result.success;
16
+ }, isNot, options);
17
+ updateElementsArray(pass, received, el);
18
+ const message = enhanceError(el, wrapExpectedWithArray(el, actualSize, size), actualSize, this, verb, expectation, '', options);
19
+ return {
20
+ pass,
21
+ message: () => message,
22
+ };
23
+ }
@@ -0,0 +1,26 @@
1
+ import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
2
+ async function condition(el, width) {
3
+ const actualWidth = await el.getSize('width');
4
+ return {
5
+ value: actualWidth,
6
+ result: actualWidth === width,
7
+ };
8
+ }
9
+ export async function toHaveWidth(received, width, options = {}) {
10
+ const isNot = this.isNot;
11
+ const { expectation = 'width', verb = 'have' } = this;
12
+ let el = await received;
13
+ let actualWidth;
14
+ const pass = await waitUntil(async () => {
15
+ const result = await executeCommand.call(this, el, condition, options, [width, options]);
16
+ el = result.el;
17
+ actualWidth = result.values;
18
+ return result.success;
19
+ }, isNot, options);
20
+ updateElementsArray(pass, received, el);
21
+ const message = enhanceError(el, wrapExpectedWithArray(el, actualWidth, width), actualWidth, this, verb, expectation, '', options);
22
+ return {
23
+ pass,
24
+ message: () => message,
25
+ };
26
+ }
package/lib/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import isEqual from 'lodash.isequal';
1
2
  import { executeCommand } from './util/executeCommand.js';
2
3
  import { wrapExpectedWithArray, updateElementsArray } from './util/elementsUtil.js';
3
4
  import { enhanceError, enhanceErrorBe, numberError } from './util/formatMessage.js';
@@ -161,6 +162,18 @@ export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false
161
162
  result: textInArray
162
163
  };
163
164
  };
165
+ export const compareObject = (actual, expected) => {
166
+ if (typeof actual !== 'object' || Array.isArray(actual)) {
167
+ return {
168
+ value: actual,
169
+ result: false
170
+ };
171
+ }
172
+ return {
173
+ value: actual,
174
+ result: isEqual(actual, expected)
175
+ };
176
+ };
164
177
  export const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }) => {
165
178
  let result = true;
166
179
  const actual = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -60,6 +60,7 @@
60
60
  "devDependencies": {
61
61
  "@types/debug": "^4.1.8",
62
62
  "@types/jest": "^29.5.4",
63
+ "@types/lodash.isequal": "^4.5.6",
63
64
  "@types/node": "^20.6.0",
64
65
  "@typescript-eslint/eslint-plugin": "^6.7.0",
65
66
  "@typescript-eslint/parser": "^6.7.0",
@@ -84,6 +85,7 @@
84
85
  },
85
86
  "dependencies": {
86
87
  "expect": "^29.7.0",
87
- "jest-matcher-utils": "^29.7.0"
88
+ "jest-matcher-utils": "^29.7.0",
89
+ "lodash.isequal": "^4.5.0"
88
90
  }
89
91
  }
@@ -1,380 +1,469 @@
1
1
  type searchValue = string | RegExp
2
2
  type replaceValue = string | ((substring: string, ...args: any[]) => string)
3
- type Replacer = [searchValue, replaceValue]
4
-
5
- declare namespace ExpectWebdriverIO {
6
- function expect<T = unknown, R extends void | Promise<void> = void | Promise<void>>(
7
- actual: T
8
- ): Matchers<R, T>
9
- function setOptions(options: DefaultOptions): void
10
- function getConfig(): any
11
- const matchers: Record<
12
- string,
13
- (
14
- actual: any,
15
- ...expected: any[]
16
- ) => Promise<{
17
- pass: boolean
18
- message(): string
19
- }>
20
- >
21
-
22
- interface DefaultOptions {
23
- /**
24
- * time in ms to wait for expectation to succeed. Default: 3000
25
- */
26
- wait?: number
27
-
28
- /**
29
- * interval between attempts. Default: 100
30
- */
31
- interval?: number
32
- }
33
-
34
- interface CommandOptions extends DefaultOptions {
35
- /**
36
- * user message to prepend before assertion error
37
- */
38
- message?: string
39
- }
40
-
41
- interface StringOptions extends CommandOptions {
42
- /**
43
- * apply `toLowerCase` to both actual and expected values
44
- */
45
- ignoreCase?: boolean
46
-
47
- /**
48
- * apply `trim` to actual value
49
- */
50
- trim?: boolean
51
-
52
- /**
53
- * expect actual value to contain expected value.
54
- * Otherwise strict equal
55
- */
56
- containing?: boolean
57
-
58
- /**
59
- * expect actual value to start with the expected value
60
- * Otherwise strict equal
61
- */
62
- atStart?: boolean
63
-
64
- /**
65
- * expect actual value to end with the expected value
66
- * Otherwise strict equal
67
- */
68
- atEnd?: boolean
69
-
70
- /**
71
- * expect actual value to have the expected value at the given index (index starts at 0 not 1)
72
- * Otherwise strict equal
73
- */
74
- atIndex?: number
75
-
76
- /**
77
- * replace the actual value (example: strip newlines from the value) and expect it to match the expected value
78
- * Otherwise strict equal
79
- */
80
- replace?: Replacer | Replacer[]
81
-
82
- /**
83
- * might be helpful to force converting property value to string
84
- */
85
- asString?: boolean
86
- }
87
-
88
- interface NumberOptions extends CommandOptions {
89
- /**
90
- * equals
91
- */
92
- eq?: number
93
- /**
94
- * less than or equals
95
- */
96
- lte?: number
97
-
98
- /**
99
- * greater than or equals
100
- */
101
- gte?: number
102
- }
103
-
104
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
105
- interface Matchers<R, T> {
106
- // ===== $ or $$ =====
107
- /**
108
- * `WebdriverIO.Element` -> `isDisplayed`
109
- */
110
- toBeDisplayed(options?: ExpectWebdriverIO.CommandOptions): R
111
-
112
- /**
113
- * `WebdriverIO.Element` -> `isExisting`
114
- */
115
- toExist(options?: ExpectWebdriverIO.CommandOptions): R
116
- /**
117
- * `WebdriverIO.Element` -> `isExisting`
118
- */
119
- toBePresent(options?: ExpectWebdriverIO.CommandOptions): R
120
- /**
121
- * `WebdriverIO.Element` -> `isExisting`
122
- */
123
- toBeExisting(options?: ExpectWebdriverIO.CommandOptions): R
124
-
125
- /**
126
- * `WebdriverIO.Element` -> `getAttribute`
127
- */
128
- toHaveAttribute(
129
- attribute: string,
130
- value?: string | RegExp,
131
- options?: ExpectWebdriverIO.StringOptions
132
- ): R
133
- /**
134
- * `WebdriverIO.Element` -> `getAttribute`
135
- */
136
- toHaveAttr(attribute: string, value?: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
137
-
138
- /**
139
- * `WebdriverIO.Element` -> `getAttribute`
140
- * Element's attribute includes the value.
141
- */
142
- toHaveAttributeContaining(
143
- attribute: string,
144
- contains: string | RegExp,
145
- options?: ExpectWebdriverIO.StringOptions
146
- ): R
147
- /**
148
- * `WebdriverIO.Element` -> `getAttribute`
149
- * Element's attribute includes the value.
150
- */
151
- toHaveAttrContaining(
152
- attribute: string,
153
- contains: string | RegExp,
154
- options?: ExpectWebdriverIO.StringOptions
155
- ): R
156
-
157
- /**
158
- * `WebdriverIO.Element` -> `getAttribute` class
159
- * @deprecated since v1.3.1 - use `toHaveElementClass` instead.
160
- */
161
- toHaveClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
162
-
163
- /**
164
- * `WebdriverIO.Element` -> `getAttribute` class
165
- */
166
- toHaveElementClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
167
-
168
- /**
169
- * `WebdriverIO.Element` -> `getAttribute` class
170
- * @deprecated since v1.3.1 - use `toHaveElementClassContaining` instead.
171
- * Element's class includes the className.
172
- */
173
- toHaveClassContaining(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
174
-
175
- /**
176
- * `WebdriverIO.Element` -> `getAttribute` class
177
- * Element's class includes the className.
178
- */
179
- toHaveElementClassContaining(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
180
-
181
- /**
182
- * `WebdriverIO.Element` -> `getProperty`
183
- */
184
- toHaveElementProperty(
185
- property: string | RegExp,
186
- value?: any,
187
- options?: ExpectWebdriverIO.StringOptions
188
- ): R
189
-
190
- /**
191
- * `WebdriverIO.Element` -> `getProperty` value
192
- */
193
- toHaveValue(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
194
- /**
195
- * `WebdriverIO.Element` -> `getProperty` value
196
- * Element's value includes the value.
197
- */
198
- toHaveValueContaining(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
199
-
200
- /**
201
- * `WebdriverIO.Element` -> `isClickable`
202
- */
203
- toBeClickable(options?: ExpectWebdriverIO.StringOptions): R
204
-
205
- /**
206
- * `WebdriverIO.Element` -> `!isEnabled`
207
- */
208
- toBeDisabled(options?: ExpectWebdriverIO.StringOptions): R
209
-
210
- /**
211
- * `WebdriverIO.Element` -> `isDisplayedInViewport`
212
- */
213
- toBeDisplayedInViewport(options?: ExpectWebdriverIO.StringOptions): R
214
-
215
- /**
216
- * `WebdriverIO.Element` -> `isEnabled`
217
- */
218
- toBeEnabled(options?: ExpectWebdriverIO.StringOptions): R
219
-
220
- /**
221
- * `WebdriverIO.Element` -> `isFocused`
222
- */
223
- toBeFocused(options?: ExpectWebdriverIO.StringOptions): R
224
-
225
- /**
226
- * `WebdriverIO.Element` -> `isSelected`
227
- */
228
- toBeSelected(options?: ExpectWebdriverIO.StringOptions): R
229
-
230
- /**
231
- * `WebdriverIO.Element` -> `isSelected`
232
- */
233
- toBeChecked(options?: ExpectWebdriverIO.StringOptions): R
234
-
235
- /**
236
- * `WebdriverIO.Element` -> `$$('./*').length`
237
- * supports less / greater then or equals to be passed in options
238
- */
239
- toHaveChildren(
240
- size?: number | ExpectWebdriverIO.NumberOptions,
241
- options?: ExpectWebdriverIO.NumberOptions
242
- ): R
243
-
244
- /**
245
- * `WebdriverIO.Element` -> `getAttribute` href
246
- */
247
- toHaveHref(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
248
- /**
249
- * `WebdriverIO.Element` -> `getAttribute` href
250
- */
251
- toHaveLink(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
252
-
253
- /**
254
- * `WebdriverIO.Element` -> `getAttribute` href
255
- * Element's href includes the value provided
256
- */
257
- toHaveHrefContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
258
- /**
259
- * `WebdriverIO.Element` -> `getAttribute` href
260
- * Element's href includes the value provided
261
- */
262
- toHaveLinkContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
263
-
264
- /**
265
- * `WebdriverIO.Element` -> `getProperty` value
266
- */
267
- toHaveId(id: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
268
-
269
- /**
270
- * `WebdriverIO.Element` -> `getText`
271
- */
272
- toHaveText(
273
- text: string | RegExp | Array<string | RegExp>,
274
- options?: ExpectWebdriverIO.StringOptions
275
- ): R
276
- /**
277
- * `WebdriverIO.Element` -> `getText`
278
- * Element's text includes the text provided
279
- */
280
- toHaveTextContaining(
281
- text: string | RegExp | Array<string | RegExp>,
282
- options?: ExpectWebdriverIO.StringOptions
283
- ): R
284
-
285
- /**
286
- * `WebdriverIO.Element` -> `getAttribute("style")`
287
- */
288
- toHaveStyle(style: { [key: string]: string }, options?: ExpectWebdriverIO.StringOptions): R
289
-
290
- // ===== browser only =====
291
- /**
292
- * `WebdriverIO.Browser` -> `getUrl`
293
- */
294
- toHaveUrl(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
295
-
296
- // ===== browser only =====
297
- /**
298
- * `WebdriverIO.Browser` -> `getUrl`
299
- * Browser's url includes the provided text
300
- */
301
- toHaveUrlContaining(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
302
-
303
- /**
304
- * `WebdriverIO.Browser` -> `getTitle`
305
- */
306
- toHaveTitle(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
307
-
308
- // ===== browser only =====
309
- /**
310
- * `WebdriverIO.Browser` -> `getTitle`
311
- * Browser's title includes the provided text
312
- */
313
- toHaveTitleContaining(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
314
-
315
- // ===== $$ only =====
316
- /**
317
- * `WebdriverIO.ElementArray` -> `$$('...').length`
318
- * supports less / greater then or equals to be passed in options
319
- */
320
- toBeElementsArrayOfSize(
321
- size: number | ExpectWebdriverIO.NumberOptions,
322
- options?: ExpectWebdriverIO.NumberOptions
323
- ): R
324
-
325
- // ==== network mock ====
326
-
327
- /**
328
- * Check that `WebdriverIO.Mock` was called
329
- */
330
- toBeRequested(options?: ExpectWebdriverIO.CommandOptions): R
331
-
332
- /**
333
- * Check that `WebdriverIO.Mock` was called N times
334
- */
335
- toBeRequestedTimes(
336
- times: number | ExpectWebdriverIO.NumberOptions,
337
- options?: ExpectWebdriverIO.NumberOptions
338
- ): R
339
-
340
- /**
341
- * Check that `WebdriverIO.Mock` was called with the specific parameters
342
- */
343
- toBeRequestedWith(requestedWith: RequestedWith, options?: ExpectWebdriverIO.CommandOptions): R
344
- }
345
-
346
- type RequestedWith = {
347
- url?: string | ExpectWebdriverIO.PartialMatcher | ((url: string) => boolean)
348
- method?: string | Array<string>
349
- statusCode?: number | Array<number>
350
- requestHeaders?:
351
- | Record<string, string>
352
- | ExpectWebdriverIO.PartialMatcher
353
- | ((headers: Record<string, string>) => boolean)
354
- responseHeaders?:
355
- | Record<string, string>
356
- | ExpectWebdriverIO.PartialMatcher
357
- | ((headers: Record<string, string>) => boolean)
358
- postData?:
359
- | string
360
- | ExpectWebdriverIO.JsonCompatible
361
- | ExpectWebdriverIO.PartialMatcher
362
- | ((r: string | undefined) => boolean)
363
- response?:
364
- | string
365
- | ExpectWebdriverIO.JsonCompatible
366
- | ExpectWebdriverIO.PartialMatcher
367
- | ((r: string) => boolean)
368
- }
369
-
370
- type jsonPrimitive = string | number | boolean | null
371
- type jsonObject = { [x: string]: jsonPrimitive | jsonObject | jsonArray }
372
- type jsonArray = Array<jsonPrimitive | jsonObject | jsonArray>
373
- type JsonCompatible = jsonObject | jsonArray
374
-
375
- interface PartialMatcher {
376
- sample?: any
377
- asymmetricMatch?(...args: any[]): boolean
3
+ export type Replacer = [searchValue, replaceValue]
4
+
5
+ declare global {
6
+ namespace ExpectWebdriverIO {
7
+ function expect<T = unknown, R extends void | Promise<void> = void | Promise<void>>(
8
+ actual: T
9
+ ): Matchers<R, T>
10
+ function setOptions(options: DefaultOptions): void
11
+ function getConfig(): any
12
+ const matchers: Record<
13
+ string,
14
+ (
15
+ actual: any,
16
+ ...expected: any[]
17
+ ) => Promise<{
18
+ pass: boolean
19
+ message(): string
20
+ }>
21
+ >
22
+
23
+ interface DefaultOptions {
24
+ /**
25
+ * time in ms to wait for expectation to succeed. Default: 3000
26
+ */
27
+ wait?: number
28
+
29
+ /**
30
+ * interval between attempts. Default: 100
31
+ */
32
+ interval?: number
33
+ }
34
+
35
+ interface CommandOptions extends DefaultOptions {
36
+ /**
37
+ * user message to prepend before assertion error
38
+ */
39
+ message?: string
40
+ }
41
+
42
+ interface HTMLOptions extends StringOptions {
43
+ /**
44
+ * return the HTML with the selector tag included
45
+ */
46
+ includeSelectorTag?: boolean
47
+ }
48
+
49
+ interface StringOptions extends CommandOptions {
50
+ /**
51
+ * apply `toLowerCase` to both actual and expected values
52
+ */
53
+ ignoreCase?: boolean
54
+
55
+ /**
56
+ * apply `trim` to actual value
57
+ */
58
+ trim?: boolean
59
+
60
+ /**
61
+ * expect actual value to contain expected value.
62
+ * Otherwise strict equal
63
+ */
64
+ containing?: boolean
65
+
66
+ /**
67
+ * expect actual value to start with the expected value
68
+ * Otherwise strict equal
69
+ */
70
+ atStart?: boolean
71
+
72
+ /**
73
+ * expect actual value to end with the expected value
74
+ * Otherwise strict equal
75
+ */
76
+ atEnd?: boolean
77
+
78
+ /**
79
+ * expect actual value to have the expected value at the given index (index starts at 0 not 1)
80
+ * Otherwise strict equal
81
+ */
82
+ atIndex?: number
83
+
84
+ /**
85
+ * replace the actual value (example: strip newlines from the value) and expect it to match the expected value
86
+ * Otherwise strict equal
87
+ */
88
+ replace?: Replacer | Replacer[]
89
+
90
+ /**
91
+ * might be helpful to force converting property value to string
92
+ */
93
+ asString?: boolean
94
+ }
95
+
96
+ interface NumberOptions extends CommandOptions {
97
+ /**
98
+ * equals
99
+ */
100
+ eq?: number
101
+ /**
102
+ * less than or equals
103
+ */
104
+ lte?: number
105
+
106
+ /**
107
+ * greater than or equals
108
+ */
109
+ gte?: number
110
+ }
111
+
112
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
113
+ interface Matchers<R, T> {
114
+ // ===== $ or $$ =====
115
+ /**
116
+ * `WebdriverIO.Element` -> `isDisplayed`
117
+ */
118
+ toBeDisplayed(options?: ExpectWebdriverIO.CommandOptions): R
119
+
120
+ /**
121
+ * `WebdriverIO.Element` -> `isExisting`
122
+ */
123
+ toExist(options?: ExpectWebdriverIO.CommandOptions): R
124
+ /**
125
+ * `WebdriverIO.Element` -> `isExisting`
126
+ */
127
+ toBePresent(options?: ExpectWebdriverIO.CommandOptions): R
128
+ /**
129
+ * `WebdriverIO.Element` -> `isExisting`
130
+ */
131
+ toBeExisting(options?: ExpectWebdriverIO.CommandOptions): R
132
+
133
+ /**
134
+ * `WebdriverIO.Element` -> `getAttribute`
135
+ */
136
+ toHaveAttribute(
137
+ attribute: string,
138
+ value?: string | RegExp,
139
+ options?: ExpectWebdriverIO.StringOptions
140
+ ): R
141
+ /**
142
+ * `WebdriverIO.Element` -> `getAttribute`
143
+ */
144
+ toHaveAttr(
145
+ attribute: string,
146
+ value?: string | RegExp,
147
+ options?: ExpectWebdriverIO.StringOptions
148
+ ): R
149
+
150
+ /**
151
+ * `WebdriverIO.Element` -> `getAttribute`
152
+ * Element's attribute includes the value.
153
+ */
154
+ toHaveAttributeContaining(
155
+ attribute: string,
156
+ contains: string | RegExp,
157
+ options?: ExpectWebdriverIO.StringOptions
158
+ ): R
159
+ /**
160
+ * `WebdriverIO.Element` -> `getAttribute`
161
+ * Element's attribute includes the value.
162
+ */
163
+ toHaveAttrContaining(
164
+ attribute: string,
165
+ contains: string | RegExp,
166
+ options?: ExpectWebdriverIO.StringOptions
167
+ ): R
168
+
169
+ /**
170
+ * `WebdriverIO.Element` -> `getAttribute` class
171
+ * @deprecated since v1.3.1 - use `toHaveElementClass` instead.
172
+ */
173
+ toHaveClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
174
+
175
+ /**
176
+ * `WebdriverIO.Element` -> `getAttribute` class
177
+ */
178
+ toHaveElementClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
179
+
180
+ /**
181
+ * `WebdriverIO.Element` -> `getAttribute` class
182
+ * @deprecated since v1.3.1 - use `toHaveElementClassContaining` instead.
183
+ * Element's class includes the className.
184
+ */
185
+ toHaveClassContaining(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
186
+
187
+ /**
188
+ * `WebdriverIO.Element` -> `getAttribute` class
189
+ * Element's class includes the className.
190
+ */
191
+ toHaveElementClassContaining(
192
+ className: string | RegExp,
193
+ options?: ExpectWebdriverIO.StringOptions
194
+ ): R
195
+
196
+ /**
197
+ * `WebdriverIO.Element` -> `getProperty`
198
+ */
199
+ toHaveElementProperty(
200
+ property: string | RegExp,
201
+ value?: any,
202
+ options?: ExpectWebdriverIO.StringOptions
203
+ ): R
204
+
205
+ /**
206
+ * `WebdriverIO.Element` -> `getProperty` value
207
+ */
208
+ toHaveValue(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
209
+ /**
210
+ * `WebdriverIO.Element` -> `getProperty` value
211
+ * Element's value includes the value.
212
+ */
213
+ toHaveValueContaining(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
214
+
215
+ /**
216
+ * `WebdriverIO.Element` -> `isClickable`
217
+ */
218
+ toBeClickable(options?: ExpectWebdriverIO.StringOptions): R
219
+
220
+ /**
221
+ * `WebdriverIO.Element` -> `!isEnabled`
222
+ */
223
+ toBeDisabled(options?: ExpectWebdriverIO.StringOptions): R
224
+
225
+ /**
226
+ * `WebdriverIO.Element` -> `isDisplayedInViewport`
227
+ */
228
+ toBeDisplayedInViewport(options?: ExpectWebdriverIO.StringOptions): R
229
+
230
+ /**
231
+ * `WebdriverIO.Element` -> `isEnabled`
232
+ */
233
+ toBeEnabled(options?: ExpectWebdriverIO.StringOptions): R
234
+
235
+ /**
236
+ * `WebdriverIO.Element` -> `isFocused`
237
+ */
238
+ toBeFocused(options?: ExpectWebdriverIO.StringOptions): R
239
+
240
+ /**
241
+ * `WebdriverIO.Element` -> `isSelected`
242
+ */
243
+ toBeSelected(options?: ExpectWebdriverIO.StringOptions): R
244
+
245
+ /**
246
+ * `WebdriverIO.Element` -> `isSelected`
247
+ */
248
+ toBeChecked(options?: ExpectWebdriverIO.StringOptions): R
249
+
250
+ /**
251
+ * `WebdriverIO.Element` -> `$$('./*').length`
252
+ * supports less / greater then or equals to be passed in options
253
+ */
254
+ toHaveChildren(
255
+ size?: number | ExpectWebdriverIO.NumberOptions,
256
+ options?: ExpectWebdriverIO.NumberOptions
257
+ ): R
258
+
259
+ /**
260
+ * `WebdriverIO.Element` -> `getAttribute` href
261
+ */
262
+ toHaveHref(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
263
+ /**
264
+ * `WebdriverIO.Element` -> `getAttribute` href
265
+ */
266
+ toHaveLink(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
267
+
268
+ /**
269
+ * `WebdriverIO.Element` -> `getAttribute` href
270
+ * Element's href includes the value provided
271
+ */
272
+ toHaveHrefContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
273
+ /**
274
+ * `WebdriverIO.Element` -> `getAttribute` href
275
+ * Element's href includes the value provided
276
+ */
277
+ toHaveLinkContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
278
+
279
+ /**
280
+ * `WebdriverIO.Element` -> `getProperty` value
281
+ */
282
+ toHaveId(id: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
283
+
284
+ /**
285
+ * `WebdriverIO.Element` -> `getText`
286
+ * Element's text equals the text provided
287
+ */
288
+ toHaveText(
289
+ text: string | RegExp | Array<string | RegExp>,
290
+ options?: ExpectWebdriverIO.StringOptions
291
+ ): R
292
+ /**
293
+ * `WebdriverIO.Element` -> `getText`
294
+ * Element's text includes the text provided
295
+ */
296
+ toHaveTextContaining(
297
+ text: string | RegExp | Array<string | RegExp>,
298
+ options?: ExpectWebdriverIO.StringOptions
299
+ ): R
300
+
301
+ /**
302
+ * `WebdriverIO.Element` -> `getHTML`
303
+ * Element's html equals the html provided
304
+ */
305
+ toHaveHTML(
306
+ html: string | RegExp | Array<string | RegExp>,
307
+ options?: ExpectWebdriverIO.HTMLOptions
308
+ ): R
309
+ /**
310
+ * `WebdriverIO.Element` -> `getHTML`
311
+ * Element's html includes the html provided
312
+ */
313
+ toHaveHTMLContaining(
314
+ html: string | RegExp | Array<string | RegExp>,
315
+ options?: ExpectWebdriverIO.HTMLOptions
316
+ ): R
317
+
318
+ /**
319
+ * `WebdriverIO.Element` -> `getComputedLabel`
320
+ * Element's computed label equals the computed label provided
321
+ */
322
+ toHaveComputedLabel(
323
+ computedLabel: string | RegExp | Array<string | RegExp>,
324
+ options?: ExpectWebdriverIO.StringOptions
325
+ ): R
326
+ /**
327
+ * `WebdriverIO.Element` -> `getComputedLabel`
328
+ * Element's computed label includes the computed label provided
329
+ */
330
+ toHaveComputedLabelContaining(
331
+ computedLabel: string | RegExp | Array<string | RegExp>,
332
+ options?: ExpectWebdriverIO.StringOptions
333
+ ): R
334
+
335
+ /**
336
+ * `WebdriverIO.Element` -> `getComputedRole`
337
+ * Element's computed role equals the computed role provided
338
+ */
339
+ toHaveComputedRole(
340
+ computedRole: string | RegExp | Array<string | RegExp>,
341
+ options?: ExpectWebdriverIO.StringOptions
342
+ ): R
343
+ /**
344
+ * `WebdriverIO.Element` -> `getComputedRole`
345
+ * Element's computed role includes the computed role provided
346
+ */
347
+ toHaveComputedRoleContaining(
348
+ computedRole: string | RegExp | Array<string | RegExp>,
349
+ options?: ExpectWebdriverIO.StringOptions
350
+ ): R
351
+
352
+ /**
353
+ * `WebdriverIO.Element` -> `getSize('width')`
354
+ * Element's width equals the width provided
355
+ */
356
+ toHaveWidth(width: number, options?: ExpectWebdriverIO.CommandOptions): R
357
+
358
+ /**
359
+ * `WebdriverIO.Element` -> `getSize('height')`
360
+ * Element's height equals the height provided
361
+ */
362
+ toHaveHeight(height: number, options?: ExpectWebdriverIO.CommandOptions): R
363
+
364
+ /**
365
+ * `WebdriverIO.Element` -> `getSize()`
366
+ * Element's size equals the size provided
367
+ */
368
+ toHaveHeight(
369
+ size: { height: number; width: number },
370
+ options?: ExpectWebdriverIO.CommandOptions
371
+ ): R
372
+
373
+ /**
374
+ * `WebdriverIO.Element` -> `getAttribute("style")`
375
+ */
376
+ toHaveStyle(style: { [key: string]: string }, options?: ExpectWebdriverIO.StringOptions): R
377
+
378
+ // ===== browser only =====
379
+ /**
380
+ * `WebdriverIO.Browser` -> `getUrl`
381
+ */
382
+ toHaveUrl(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
383
+
384
+ // ===== browser only =====
385
+ /**
386
+ * `WebdriverIO.Browser` -> `getUrl`
387
+ * Browser's url includes the provided text
388
+ */
389
+ toHaveUrlContaining(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
390
+
391
+ /**
392
+ * `WebdriverIO.Browser` -> `getTitle`
393
+ */
394
+ toHaveTitle(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
395
+
396
+ // ===== browser only =====
397
+ /**
398
+ * `WebdriverIO.Browser` -> `getTitle`
399
+ * Browser's title includes the provided text
400
+ */
401
+ toHaveTitleContaining(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
402
+
403
+ // ===== $$ only =====
404
+ /**
405
+ * `WebdriverIO.ElementArray` -> `$$('...').length`
406
+ * supports less / greater then or equals to be passed in options
407
+ */
408
+ toBeElementsArrayOfSize(
409
+ size: number | ExpectWebdriverIO.NumberOptions,
410
+ options?: ExpectWebdriverIO.NumberOptions
411
+ ): R
412
+
413
+ // ==== network mock ====
414
+
415
+ /**
416
+ * Check that `WebdriverIO.Mock` was called
417
+ */
418
+ toBeRequested(options?: ExpectWebdriverIO.CommandOptions): R
419
+
420
+ /**
421
+ * Check that `WebdriverIO.Mock` was called N times
422
+ */
423
+ toBeRequestedTimes(
424
+ times: number | ExpectWebdriverIO.NumberOptions,
425
+ options?: ExpectWebdriverIO.NumberOptions
426
+ ): R
427
+
428
+ /**
429
+ * Check that `WebdriverIO.Mock` was called with the specific parameters
430
+ */
431
+ toBeRequestedWith(requestedWith: RequestedWith, options?: ExpectWebdriverIO.CommandOptions): R
432
+ }
433
+
434
+ type RequestedWith = {
435
+ url?: string | ExpectWebdriverIO.PartialMatcher | ((url: string) => boolean)
436
+ method?: string | Array<string>
437
+ statusCode?: number | Array<number>
438
+ requestHeaders?:
439
+ | Record<string, string>
440
+ | ExpectWebdriverIO.PartialMatcher
441
+ | ((headers: Record<string, string>) => boolean)
442
+ responseHeaders?:
443
+ | Record<string, string>
444
+ | ExpectWebdriverIO.PartialMatcher
445
+ | ((headers: Record<string, string>) => boolean)
446
+ postData?:
447
+ | string
448
+ | ExpectWebdriverIO.JsonCompatible
449
+ | ExpectWebdriverIO.PartialMatcher
450
+ | ((r: string | undefined) => boolean)
451
+ response?:
452
+ | string
453
+ | ExpectWebdriverIO.JsonCompatible
454
+ | ExpectWebdriverIO.PartialMatcher
455
+ | ((r: string) => boolean)
456
+ }
457
+
458
+ type jsonPrimitive = string | number | boolean | null
459
+ type jsonObject = { [x: string]: jsonPrimitive | jsonObject | jsonArray }
460
+ type jsonArray = Array<jsonPrimitive | jsonObject | jsonArray>
461
+ type JsonCompatible = jsonObject | jsonArray
462
+
463
+ interface PartialMatcher {
464
+ sample?: any
465
+ asymmetricMatch?(...args: any[]): boolean
466
+ }
378
467
  }
379
468
  }
380
469