-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathelement.js
158 lines (142 loc) · 4.29 KB
/
element.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* eslint-disable @typescript-eslint/no-unused-vars */
import {errors} from 'appium/driver';
/**
* @this {import('../driver').AndroidDriver}
* @param {string} attribute
* @param {string} elementId
* @returns {Promise<string?>}
*/
export async function getAttribute(attribute, elementId) {
throw new errors.NotImplementedError('Not implemented');
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string} elementId
* @returns {Promise<void>}
*/
export async function click(elementId) {
throw new errors.NotImplementedError('Not implemented');
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string} elementId
* @returns {Promise<string>}
*/
export async function getText(elementId) {
throw new errors.NotImplementedError('Not implemented');
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string} elementId
* @returns {Promise<import('@appium/types').Position>}
*/
export async function getLocation(elementId) {
throw new errors.NotImplementedError('Not implemented');
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string} elementId
* @returns {Promise<import('@appium/types').Size>}
*/
export async function getSize(elementId) {
throw new errors.NotImplementedError('Not implemented');
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string} elementId
* @returns {Promise<string>}
*/
export async function getName(elementId) {
return /** @type {string} */ (await this.getAttribute('className', elementId));
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string} elementId
* @returns {Promise<boolean>}
*/
export async function elementDisplayed(elementId) {
return (await this.getAttribute('displayed', elementId)) === 'true';
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string} elementId
* @returns {Promise<boolean>}
*/
export async function elementEnabled(elementId) {
return (await this.getAttribute('enabled', elementId)) === 'true';
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string} elementId
* @returns {Promise<boolean>}
*/
export async function elementSelected(elementId) {
return (await this.getAttribute('selected', elementId)) === 'true';
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string|string[]} keys
* @param {string} elementId
* @param {boolean} [replace=false]
* @returns {Promise<void>}
*/
export async function setElementValue(keys, elementId, replace = false) {
const text = keys instanceof Array ? keys.join('') : keys;
return await this.doSetElementValue({
elementId,
text: String(text),
replace,
});
}
/**
* Reason for isolating doSetElementValue from setElementValue is for reusing setElementValue
* across android-drivers (like appium-uiautomator2-driver) and to avoid code duplication.
* Other android-drivers (like appium-uiautomator2-driver) need to override doSetElementValue
* to facilitate setElementValue.
*
* @this {import('../driver').AndroidDriver}
* @param {import('./types').DoSetElementValueOpts} params
* @returns {Promise<void>}
*/
export async function doSetElementValue(params) {
throw new errors.NotImplementedError('Not implemented');
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string|string[]} keys
* @param {string} elementId
* @returns {Promise<void>}
*/
export async function setValue(keys, elementId) {
return await this.setElementValue(keys, elementId, false);
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string|string[]} keys
* @param {string} elementId
* @returns {Promise<void>}
*/
export async function replaceValue(keys, elementId) {
return await this.setElementValue(keys, elementId, true);
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string|string[]} keys
* @param {string} elementId
* @returns {Promise<void>}
*/
export async function setValueImmediate(keys, elementId) {
const text = Array.isArray(keys) ? keys.join('') : keys;
// first, make sure we are focused on the element
await this.click(elementId);
// then send through adb
await this.adb.inputText(/** @type {string} */ (text));
}
/**
* @this {import('../driver').AndroidDriver}
* @param {string} elementId
* @returns {Promise<import('@appium/types').Position>}
*/
export async function getLocationInView(elementId) {
return await this.getLocation(elementId);
}