-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfinder.ts
124 lines (118 loc) · 4.05 KB
/
finder.ts
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// @ts-ignore
import { command } from 'webdriver';
import path from 'path';
export async function registerCommands() {
const utils = await import(
path.join(
require.resolve('webdriverio').replace('cjs/index.js', ''),
'utils',
'getElementObject.js',
)
);
function handler(multi: boolean = false) {
return async function (value: string) {
let findElement;
let args = ['key', value];
let suffix = multi ? 'elements' : 'element';
if (this['elementId']) {
args = [this['elementId'], 'key', value];
findElement = command(
'POST',
`/session/:sessionId/element/:elementId/${suffix}`,
{
command: 'flutterFinderByKey',
description: 'a new WebDriver command',
ref: 'https://vendor.com/commands/#myNewCommand',
variables: [
{
name: 'elementId',
type: 'string',
description: 'a valid parameter',
required: true,
},
],
parameters: [
{
name: 'using',
type: 'string',
description: 'a valid parameter',
required: true,
},
{
name: 'value',
type: 'string',
description: 'a valid parameter',
required: true,
},
],
returns: {
type: 'object',
name: 'element',
description:
"A JSON representation of an element object, e.g. `{ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT_1' }`.",
},
},
);
} else {
findElement = command('POST', `/session/:sessionId/${suffix}`, {
command: 'flutterFinderByKey',
description: 'a new WebDriver command',
ref: 'https://vendor.com/commands/#myNewCommand',
variables: [],
parameters: [
{
name: 'using',
type: 'string',
description: 'a valid parameter',
required: true,
},
{
name: 'value',
type: 'string',
description: 'a valid parameter',
required: true,
},
{
name: 'context',
type: 'string',
description: 'a valid parameter',
required: false,
},
],
returns: {
type: 'object',
name: 'element',
description:
"A JSON representation of an element object, e.g. `{ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT_1' }`.",
},
});
}
const response = await findElement.call(browser, ...args);
console.log(utils.getElement);
try {
if (multi) {
return response.map((element: any) =>
utils.getElement.call(this, null, element),
);
} else {
return utils.getElement.call(this, null, response);
}
} catch (e) {
console.log(e);
}
};
}
browser.addCommand('flutterFinderByKey$', handler());
browser.addCommand('flutterFinderByKey$', handler(), true);
browser.addCommand('flutterFinderByKey$$', handler(true));
browser.addCommand('flutterFinderByKey$$', handler(true), true);
/**
*
* 1. Element visible
* 2. Element not visible
* 3. element enable/disabled
* 4. Element count
* 6.
*
*/
}