forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initializers.js
41 lines (32 loc) · 1.32 KB
/
initializers.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
import SelectorBuilder from '../../../client-functions/selectors/selector-builder';
import { ActionSelectorError } from '../../../errors/test-run';
import { APIError } from '../../../errors/runtime';
import { ExecuteSelectorCommand } from '../observation';
import { executeJsExpression } from '../../execute-js-expression';
import { isJSExpression } from '../utils';
export function initUploadSelector (name, val, initOptions) {
initOptions.skipVisibilityCheck = true;
return initSelector(name, val, initOptions);
}
export function initTypeSelector (name, val, initOptions) {
initOptions.needError = true;
initOptions.strictError = true;
return initSelector(name, val, initOptions);
}
export function initSelector (name, val, { testRun, ...options }) {
if (val instanceof ExecuteSelectorCommand)
return val;
try {
if (isJSExpression(val))
val = executeJsExpression(val.value, testRun, options);
const { skipVisibilityCheck, ...builderOptions } = options;
const builder = new SelectorBuilder(val, {
visibilityCheck: !skipVisibilityCheck,
...builderOptions,
}, { instantiation: 'Selector' });
return builder.getCommand([]);
}
catch (err) {
throw new ActionSelectorError(name, err, err instanceof APIError);
}
}