forked from webdriverio/expect-webdriverio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoHaveComputedLabel.ts
More file actions
77 lines (67 loc) · 1.99 KB
/
toHaveComputedLabel.ts
File metadata and controls
77 lines (67 loc) · 1.99 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { DEFAULT_OPTIONS } from '../../constants.js'
import type { WdioElementMaybePromise } from '../../types.js'
import {
compareText,
compareTextWithArray,
enhanceError,
executeCommand,
waitUntil,
wrapExpectedWithArray
} from '../../utils.js'
async function condition(
el: WebdriverIO.Element,
label: string | RegExp | WdioAsymmetricMatcher<string> | Array<string | RegExp>,
options: ExpectWebdriverIO.HTMLOptions
) {
const actualLabel = await el.getComputedLabel()
if (Array.isArray(label)) {
return compareTextWithArray(actualLabel, label, options)
}
return compareText(actualLabel, label, options)
}
export async function toHaveComputedLabel(
received: WdioElementMaybePromise,
expectedValue: string | RegExp | WdioAsymmetricMatcher<string> | Array<string | RegExp>,
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'computed label', verb = 'have' } = this
await options.beforeAssertion?.({
matcherName: 'toHaveComputedLabel',
expectedValue,
options,
})
let el = await received?.getElement()
let actualLabel
const pass = await waitUntil(
async () => {
const result = await executeCommand.call(this, el, condition, options, [expectedValue, options])
el = result.el as WebdriverIO.Element
actualLabel = result.values
return result.success
},
isNot,
options
)
const message = enhanceError(
el,
wrapExpectedWithArray(el, actualLabel, expectedValue),
actualLabel,
this,
verb,
expectation,
'',
options
)
const result: ExpectWebdriverIO.AssertionResult = {
pass,
message: (): string => message
}
await options.afterAssertion?.({
matcherName: 'toHaveComputedLabel',
expectedValue,
options,
result
})
return result
}