@appium/fake-driver 5.2.0 → 5.2.2
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.
- package/LICENSE +1 -1
- package/build/lib/commands/alert.d.ts +12 -40
- package/build/lib/commands/alert.d.ts.map +1 -1
- package/build/lib/commands/alert.js +3 -23
- package/build/lib/commands/alert.js.map +1 -1
- package/build/lib/commands/contexts.d.ts +12 -42
- package/build/lib/commands/contexts.d.ts.map +1 -1
- package/build/lib/commands/contexts.js +8 -28
- package/build/lib/commands/contexts.js.map +1 -1
- package/build/lib/commands/element.d.ts +25 -74
- package/build/lib/commands/element.d.ts.map +1 -1
- package/build/lib/commands/element.js +24 -76
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/find.d.ts +16 -44
- package/build/lib/commands/find.d.ts.map +1 -1
- package/build/lib/commands/find.js +21 -45
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/general.d.ts +25 -88
- package/build/lib/commands/general.d.ts.map +1 -1
- package/build/lib/commands/general.js +3 -61
- package/build/lib/commands/general.js.map +1 -1
- package/build/lib/commands/index.d.ts +13 -5
- package/build/lib/commands/index.d.ts.map +1 -1
- package/build/lib/commands/index.js +13 -14
- package/build/lib/commands/index.js.map +1 -1
- package/build/lib/commands/mixin.d.ts +11 -0
- package/build/lib/commands/mixin.d.ts.map +1 -0
- package/build/lib/commands/mixin.js +17 -0
- package/build/lib/commands/mixin.js.map +1 -0
- package/build/lib/driver.d.ts +37 -111
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +11 -73
- package/build/lib/driver.js.map +1 -1
- package/build/lib/fake-app.d.ts +9 -7
- package/build/lib/fake-app.d.ts.map +1 -1
- package/build/lib/fake-app.js +2 -0
- package/build/lib/fake-app.js.map +1 -1
- package/build/lib/fake-element.d.ts +12 -4
- package/build/lib/fake-element.d.ts.map +1 -1
- package/build/lib/fake-element.js +11 -4
- package/build/lib/fake-element.js.map +1 -1
- package/build/lib/scripts/fake-error.d.ts +1 -0
- package/build/lib/scripts/fake-error.js +11 -1
- package/build/lib/scripts/fake-error.js.map +1 -1
- package/build/lib/scripts/fake-stdin.d.ts +2 -0
- package/build/lib/scripts/fake-stdin.d.ts.map +1 -0
- package/build/lib/scripts/fake-stdin.js +13 -0
- package/build/lib/scripts/fake-stdin.js.map +1 -0
- package/lib/commands/alert.ts +70 -0
- package/lib/commands/{contexts.js → contexts.ts} +26 -34
- package/lib/commands/element.ts +138 -0
- package/lib/commands/find.ts +137 -0
- package/lib/commands/general.ts +115 -0
- package/lib/commands/{index.js → index.ts} +14 -5
- package/lib/commands/mixin.ts +13 -0
- package/lib/driver.js +41 -78
- package/lib/fake-app.js +3 -3
- package/lib/fake-element.js +21 -6
- package/lib/scripts/fake-error.js +8 -1
- package/lib/scripts/fake-stdin.js +9 -0
- package/package.json +4 -3
- package/lib/commands/alert.js +0 -73
- package/lib/commands/element.js +0 -161
- package/lib/commands/find.js +0 -118
- package/lib/commands/general.js +0 -147
package/lib/driver.js
CHANGED
|
@@ -2,7 +2,6 @@ import B from 'bluebird';
|
|
|
2
2
|
import {BaseDriver, errors} from 'appium/driver';
|
|
3
3
|
import {deprecatedCommandsLogged} from '@appium/base-driver/build/lib/protocol/protocol';
|
|
4
4
|
import {FakeApp} from './fake-app';
|
|
5
|
-
import {alert, contexts, element, find, general} from './commands';
|
|
6
5
|
|
|
7
6
|
const FAKE_DRIVER_CONSTRAINTS = /** @type {const} */ ({
|
|
8
7
|
app: {
|
|
@@ -15,22 +14,50 @@ const FAKE_DRIVER_CONSTRAINTS = /** @type {const} */ ({
|
|
|
15
14
|
});
|
|
16
15
|
|
|
17
16
|
/**
|
|
17
|
+
* Constraints for {@linkcode FakeDriver}'s capabilites
|
|
18
18
|
* @typedef {typeof FAKE_DRIVER_CONSTRAINTS} FakeDriverConstraints
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
+
* @template [Thing=any]
|
|
22
23
|
* @extends {BaseDriver<FakeDriverConstraints>}
|
|
23
24
|
* @implements {ExternalDriver<FakeDriverConstraints>}
|
|
24
25
|
*/
|
|
25
26
|
export class FakeDriver extends BaseDriver {
|
|
26
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @type {FakeDriverConstraints}
|
|
29
|
+
* @readonly
|
|
30
|
+
*/
|
|
31
|
+
desiredCapConstraints;
|
|
27
32
|
|
|
28
33
|
/** @type {string} */
|
|
29
34
|
curContext;
|
|
30
35
|
|
|
31
|
-
|
|
36
|
+
/** @type {FakeApp} */
|
|
37
|
+
appModel;
|
|
38
|
+
|
|
39
|
+
/** @type {boolean} */
|
|
40
|
+
_proxyActive;
|
|
41
|
+
|
|
42
|
+
/** @type {boolean} */
|
|
43
|
+
shook;
|
|
44
|
+
|
|
45
|
+
/** @type {string?} */
|
|
46
|
+
focusedElId;
|
|
47
|
+
|
|
48
|
+
/** @type {Thing?} */
|
|
49
|
+
fakeThing;
|
|
50
|
+
|
|
51
|
+
/** @type {number} */
|
|
52
|
+
maxElId;
|
|
32
53
|
|
|
33
|
-
|
|
54
|
+
/** @type {Record<string,import('./fake-element').FakeElement>} */
|
|
55
|
+
elMap;
|
|
56
|
+
|
|
57
|
+
constructor(
|
|
58
|
+
opts = /** @type {import('@appium/types').DriverOpts<FakeDriverConstraints>} */ ({}),
|
|
59
|
+
shouldValidateCaps = true
|
|
60
|
+
) {
|
|
34
61
|
super(opts, shouldValidateCaps);
|
|
35
62
|
this.curContext = 'NATIVE_APP';
|
|
36
63
|
this.elMap = {};
|
|
@@ -39,6 +66,8 @@ export class FakeDriver extends BaseDriver {
|
|
|
39
66
|
this.fakeThing = null;
|
|
40
67
|
this._proxyActive = false;
|
|
41
68
|
this.shook = false;
|
|
69
|
+
this.appModel = new FakeApp();
|
|
70
|
+
this.desiredCapConstraints = FAKE_DRIVER_CONSTRAINTS;
|
|
42
71
|
}
|
|
43
72
|
|
|
44
73
|
proxyActive() {
|
|
@@ -112,7 +141,7 @@ export class FakeDriver extends BaseDriver {
|
|
|
112
141
|
/**
|
|
113
142
|
* Set the 'thing' value (so that it can be retrieved later)
|
|
114
143
|
*
|
|
115
|
-
* @param {
|
|
144
|
+
* @param {Thing} thing
|
|
116
145
|
* @returns {Promise<null>}
|
|
117
146
|
*/
|
|
118
147
|
async setFakeThing(thing) {
|
|
@@ -201,86 +230,16 @@ export class FakeDriver extends BaseDriver {
|
|
|
201
230
|
res.send(JSON.stringify(cliArgs));
|
|
202
231
|
});
|
|
203
232
|
}
|
|
204
|
-
|
|
205
|
-
/*********
|
|
206
|
-
* ALERT *
|
|
207
|
-
*********/
|
|
208
|
-
assertNoAlert = alert.assertNoAlert;
|
|
209
|
-
assertAlert = alert.assertAlert;
|
|
210
|
-
getAlertText = alert.getAlertText;
|
|
211
|
-
setAlertText = alert.setAlertText;
|
|
212
|
-
postAcceptAlert = alert.postAcceptAlert;
|
|
213
|
-
postDismissAlert = alert.postDismissAlert;
|
|
214
|
-
|
|
215
|
-
/************
|
|
216
|
-
* CONTEXTS *
|
|
217
|
-
************/
|
|
218
|
-
getRawContexts = contexts.getRawContexts;
|
|
219
|
-
assertWebviewContext = contexts.assertWebviewContext;
|
|
220
|
-
getCurrentContext = contexts.getCurrentContext;
|
|
221
|
-
getContexts = contexts.getContexts;
|
|
222
|
-
setContext = contexts.setContext;
|
|
223
|
-
setFrame = contexts.setFrame;
|
|
224
|
-
|
|
225
|
-
/************
|
|
226
|
-
* ELEMENTS *
|
|
227
|
-
************/
|
|
228
|
-
getElements = element.getElements;
|
|
229
|
-
getElement = element.getElement;
|
|
230
|
-
getName = element.getName;
|
|
231
|
-
elementDisplayed = element.elementDisplayed;
|
|
232
|
-
elementEnabled = element.elementEnabled;
|
|
233
|
-
elementSelected = element.elementSelected;
|
|
234
|
-
setValue = element.setValue;
|
|
235
|
-
getText = element.getText;
|
|
236
|
-
clear = element.clear;
|
|
237
|
-
click = element.click;
|
|
238
|
-
getAttribute = element.getAttribute;
|
|
239
|
-
getElementRect = element.getElementRect;
|
|
240
|
-
getSize = element.getSize;
|
|
241
|
-
equalsElement = element.equalsElement;
|
|
242
|
-
getCssProperty = element.getCssProperty;
|
|
243
|
-
getLocation = element.getLocation;
|
|
244
|
-
getLocationInView = element.getLocationInView;
|
|
245
|
-
|
|
246
|
-
/********
|
|
247
|
-
* FIND *
|
|
248
|
-
********/
|
|
249
|
-
getExistingElementForNode = find.getExistingElementForNode;
|
|
250
|
-
wrapNewEl = find.wrapNewEl;
|
|
251
|
-
findElOrEls = find.findElOrEls;
|
|
252
|
-
findElement = find.findElement;
|
|
253
|
-
findElements = find.findElements;
|
|
254
|
-
findElementFromElement = find.findElementFromElement;
|
|
255
|
-
findElementsFromElement = find.findElementsFromElement;
|
|
256
|
-
|
|
257
|
-
/***********
|
|
258
|
-
* GENERAL *
|
|
259
|
-
***********/
|
|
260
|
-
title = general.title;
|
|
261
|
-
keys = general.keys;
|
|
262
|
-
setGeoLocation = general.setGeoLocation;
|
|
263
|
-
getGeoLocation = general.getGeoLocation;
|
|
264
|
-
getPageSource = general.getPageSource;
|
|
265
|
-
getOrientation = general.getOrientation;
|
|
266
|
-
setOrientation = general.setOrientation;
|
|
267
|
-
getScreenshot = general.getScreenshot;
|
|
268
|
-
getWindowSize = general.getWindowSize;
|
|
269
|
-
getWindowRect = general.getWindowRect;
|
|
270
|
-
performActions = general.performActions;
|
|
271
|
-
getLog = general.getLog;
|
|
272
|
-
mobileShake = general.mobileShake;
|
|
273
|
-
doubleClick = general.doubleClick;
|
|
274
|
-
execute = general.execute;
|
|
275
|
-
fakeAddition = general.fakeAddition;
|
|
276
|
-
releaseActions = general.releaseActions;
|
|
277
233
|
}
|
|
278
234
|
|
|
235
|
+
import './commands';
|
|
236
|
+
|
|
279
237
|
export default FakeDriver;
|
|
280
238
|
|
|
281
239
|
/**
|
|
282
240
|
* @typedef {import('./types').FakeDriverCaps} FakeDriverCaps
|
|
283
241
|
* @typedef {import('./types').W3CFakeDriverCaps} W3CFakeDriverCaps
|
|
242
|
+
* @typedef {import('@appium/types').Element} Element
|
|
284
243
|
*/
|
|
285
244
|
|
|
286
245
|
/**
|
|
@@ -292,3 +251,7 @@ export default FakeDriver;
|
|
|
292
251
|
* @template {import('@appium/types').Constraints} C
|
|
293
252
|
* @typedef {import('@appium/types').ExternalDriver<C>} ExternalDriver
|
|
294
253
|
*/
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @typedef {import('@appium/types').Orientation} Orientation
|
|
257
|
+
*/
|
package/lib/fake-app.js
CHANGED
|
@@ -8,7 +8,7 @@ import {FakeElement} from './fake-element';
|
|
|
8
8
|
|
|
9
9
|
const SCREENSHOT = path.join(__dirname, 'screen.png');
|
|
10
10
|
|
|
11
|
-
class FakeApp {
|
|
11
|
+
export class FakeApp {
|
|
12
12
|
constructor() {
|
|
13
13
|
this.dom = null;
|
|
14
14
|
this.activeDom = null;
|
|
@@ -20,7 +20,9 @@ class FakeApp {
|
|
|
20
20
|
this._width = null;
|
|
21
21
|
this._height = null;
|
|
22
22
|
this.rawXml = '';
|
|
23
|
+
/** @type {import('./driver').Orientation} */
|
|
23
24
|
this.currentOrientation = 'PORTRAIT';
|
|
25
|
+
/** @type {import('@appium/types').ActionSequence[][]} */
|
|
24
26
|
this.actionLog = [];
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -176,8 +178,6 @@ class FakeWebView {
|
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
|
|
179
|
-
export {FakeApp};
|
|
180
|
-
|
|
181
181
|
/**
|
|
182
182
|
* @typedef {Element & {data: any}} ElementWithData
|
|
183
183
|
*/
|
package/lib/fake-element.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import XMLDom from '@xmldom/xmldom';
|
|
3
3
|
|
|
4
|
-
class FakeElement {
|
|
4
|
+
export class FakeElement {
|
|
5
|
+
/** @type {FakeApp} */
|
|
6
|
+
app;
|
|
7
|
+
|
|
8
|
+
/** @type {string} */
|
|
9
|
+
type;
|
|
10
|
+
|
|
11
|
+
/** @type {Record<string,string>} */
|
|
12
|
+
nodeAttrs;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {any} xmlNode
|
|
16
|
+
* @param {FakeApp} app
|
|
17
|
+
*/
|
|
5
18
|
constructor(xmlNode, app) {
|
|
6
19
|
this.app = app;
|
|
7
20
|
this.node = xmlNode;
|
|
@@ -53,8 +66,8 @@ class FakeElement {
|
|
|
53
66
|
|
|
54
67
|
getLocation() {
|
|
55
68
|
return {
|
|
56
|
-
x: parseFloat(this.nodeAttrs.left || 0),
|
|
57
|
-
y: parseFloat(this.nodeAttrs.top || 0),
|
|
69
|
+
x: parseFloat(this.nodeAttrs.left || '0'),
|
|
70
|
+
y: parseFloat(this.nodeAttrs.top || '0'),
|
|
58
71
|
};
|
|
59
72
|
}
|
|
60
73
|
|
|
@@ -64,8 +77,8 @@ class FakeElement {
|
|
|
64
77
|
|
|
65
78
|
getSize() {
|
|
66
79
|
return {
|
|
67
|
-
width: parseFloat(this.nodeAttrs.width || 0),
|
|
68
|
-
height: parseFloat(this.nodeAttrs.height || 0),
|
|
80
|
+
width: parseFloat(this.nodeAttrs.width || '0'),
|
|
81
|
+
height: parseFloat(this.nodeAttrs.height || '0'),
|
|
69
82
|
};
|
|
70
83
|
}
|
|
71
84
|
|
|
@@ -99,4 +112,6 @@ class FakeElement {
|
|
|
99
112
|
}
|
|
100
113
|
}
|
|
101
114
|
|
|
102
|
-
|
|
115
|
+
/**
|
|
116
|
+
* @typedef {import('./fake-app').FakeApp} FakeApp
|
|
117
|
+
*/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import readline from 'node:readline';
|
|
2
|
+
|
|
3
|
+
const rl = readline.createInterface({input: process.stdin, output: process.stderr});
|
|
4
|
+
|
|
5
|
+
rl.question('Press ENTER to continue: ', () => {
|
|
6
|
+
rl.close();
|
|
7
|
+
// eslint-disable-next-line no-console
|
|
8
|
+
console.error('You did it!');
|
|
9
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/fake-driver",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2",
|
|
4
4
|
"description": "Mock driver used internally by Appium for testing. Ignore",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -75,12 +75,13 @@
|
|
|
75
75
|
"schema": "./build/lib/fake-driver-schema.js",
|
|
76
76
|
"scripts": {
|
|
77
77
|
"fake-error": "./build/lib/scripts/fake-error.js",
|
|
78
|
-
"fake-success": "./build/lib/scripts/fake-success.js"
|
|
78
|
+
"fake-success": "./build/lib/scripts/fake-success.js",
|
|
79
|
+
"fake-stdin": "./build/lib/scripts/fake-stdin.js"
|
|
79
80
|
}
|
|
80
81
|
},
|
|
81
82
|
"typedoc": {
|
|
82
83
|
"entryPoint": "./lib/index.js"
|
|
83
84
|
},
|
|
84
85
|
"types": "./build/lib/index.d.ts",
|
|
85
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "d514ebdd7ebd27bb236509d0a3d580f0f18a34e5"
|
|
86
87
|
}
|
package/lib/commands/alert.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import {errors} from 'appium/driver';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
/**
|
|
5
|
-
* @this {FakeDriver}
|
|
6
|
-
*/
|
|
7
|
-
assertNoAlert() {
|
|
8
|
-
if (this.appModel.hasAlert()) {
|
|
9
|
-
throw new errors.UnexpectedAlertOpenError();
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @this {FakeDriver}
|
|
15
|
-
*/
|
|
16
|
-
assertAlert() {
|
|
17
|
-
if (!this.appModel.hasAlert()) {
|
|
18
|
-
throw new errors.NoAlertOpenError();
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Get the text of an alert
|
|
24
|
-
*
|
|
25
|
-
* @returns {Promise<string>}
|
|
26
|
-
* @this {FakeDriver}
|
|
27
|
-
*/
|
|
28
|
-
async getAlertText() {
|
|
29
|
-
this.assertAlert();
|
|
30
|
-
return this.appModel.alertText();
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Set the text of an alert
|
|
35
|
-
*
|
|
36
|
-
* @param {string} text
|
|
37
|
-
* @returns {Promise<void>}
|
|
38
|
-
* @this {FakeDriver}
|
|
39
|
-
*/
|
|
40
|
-
async setAlertText(text) {
|
|
41
|
-
this.assertAlert();
|
|
42
|
-
try {
|
|
43
|
-
this.appModel.setAlertText(text);
|
|
44
|
-
} catch (e) {
|
|
45
|
-
throw new errors.InvalidElementStateError();
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Accept an alert
|
|
51
|
-
*
|
|
52
|
-
* @returns {Promise<void>}
|
|
53
|
-
* @this {FakeDriver}
|
|
54
|
-
*/
|
|
55
|
-
async postAcceptAlert() {
|
|
56
|
-
this.assertAlert();
|
|
57
|
-
this.appModel.handleAlert();
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Dismiss an alert
|
|
62
|
-
*
|
|
63
|
-
* @returns {Promise<void>}
|
|
64
|
-
* @this {FakeDriver}
|
|
65
|
-
*/
|
|
66
|
-
async postDismissAlert() {
|
|
67
|
-
return this.postAcceptAlert();
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @typedef {import('../driver').FakeDriver} FakeDriver
|
|
73
|
-
*/
|
package/lib/commands/element.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import {errors} from 'appium/driver';
|
|
3
|
-
export default {
|
|
4
|
-
/**
|
|
5
|
-
* @this {FakeDriver}
|
|
6
|
-
*/
|
|
7
|
-
getElements(elIds) {
|
|
8
|
-
for (let elId of elIds) {
|
|
9
|
-
if (!_.has(this.elMap, elId)) {
|
|
10
|
-
throw new errors.StaleElementReferenceError();
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return elIds.map((e) => this.elMap[e]);
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @this {FakeDriver}
|
|
18
|
-
*/
|
|
19
|
-
getElement(elId) {
|
|
20
|
-
return this.getElements([elId])[0];
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @this {FakeDriver}
|
|
25
|
-
*/
|
|
26
|
-
async getName(elementId) {
|
|
27
|
-
let el = this.getElement(elementId);
|
|
28
|
-
return el.tagName;
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @this {FakeDriver}
|
|
33
|
-
*/
|
|
34
|
-
async elementDisplayed(elementId) {
|
|
35
|
-
let el = this.getElement(elementId);
|
|
36
|
-
return el.isVisible();
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @this {FakeDriver}
|
|
41
|
-
*/
|
|
42
|
-
async elementEnabled(elementId) {
|
|
43
|
-
let el = this.getElement(elementId);
|
|
44
|
-
return el.isEnabled();
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @this {FakeDriver}
|
|
49
|
-
*/
|
|
50
|
-
async elementSelected(elementId) {
|
|
51
|
-
let el = this.getElement(elementId);
|
|
52
|
-
return el.isSelected();
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @this {FakeDriver}
|
|
57
|
-
*/
|
|
58
|
-
async setValue(keys, elementId) {
|
|
59
|
-
let value = keys;
|
|
60
|
-
if (keys instanceof Array) {
|
|
61
|
-
value = keys.join('');
|
|
62
|
-
}
|
|
63
|
-
let el = this.getElement(elementId);
|
|
64
|
-
if (el.type !== 'MockInputField') {
|
|
65
|
-
throw new errors.InvalidElementStateError();
|
|
66
|
-
}
|
|
67
|
-
el.setAttr('value', value);
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @this {FakeDriver}
|
|
72
|
-
*/
|
|
73
|
-
async getText(elementId) {
|
|
74
|
-
let el = this.getElement(elementId);
|
|
75
|
-
return el.getAttr('value');
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @this {FakeDriver}
|
|
80
|
-
*/
|
|
81
|
-
async clear(elementId) {
|
|
82
|
-
await this.setValue('', elementId);
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* This comment should be displayed instead of the one from ExternalDriver
|
|
87
|
-
* @param {string} elementId
|
|
88
|
-
* @this {FakeDriver}
|
|
89
|
-
*/
|
|
90
|
-
async click(elementId) {
|
|
91
|
-
this.assertNoAlert();
|
|
92
|
-
let el = this.getElement(elementId);
|
|
93
|
-
if (!el.isVisible()) {
|
|
94
|
-
throw new errors.InvalidElementStateError();
|
|
95
|
-
}
|
|
96
|
-
el.click();
|
|
97
|
-
this.focusedElId = elementId;
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* @this {FakeDriver}
|
|
102
|
-
*/
|
|
103
|
-
async getAttribute(attr, elementId) {
|
|
104
|
-
let el = this.getElement(elementId);
|
|
105
|
-
return el.getAttr(attr);
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @this {FakeDriver}
|
|
110
|
-
*/
|
|
111
|
-
getElementRect(elementId) {
|
|
112
|
-
let el = this.getElement(elementId);
|
|
113
|
-
return el.getElementRect();
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @this {FakeDriver}
|
|
118
|
-
*/
|
|
119
|
-
getSize(elementId) {
|
|
120
|
-
let el = this.getElement(elementId);
|
|
121
|
-
return el.getSize();
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @this {FakeDriver}
|
|
126
|
-
*/
|
|
127
|
-
equalsElement(el1Id, el2Id) {
|
|
128
|
-
let el1 = this.getElement(el1Id);
|
|
129
|
-
let el2 = this.getElement(el2Id);
|
|
130
|
-
return el1.equals(el2);
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @this {FakeDriver}
|
|
135
|
-
*/
|
|
136
|
-
async getCssProperty(prop, elementId) {
|
|
137
|
-
this.assertWebviewContext();
|
|
138
|
-
let el = this.getElement(elementId);
|
|
139
|
-
return el.getCss(prop);
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @param {string} elementId
|
|
144
|
-
* @this {FakeDriver}
|
|
145
|
-
*/
|
|
146
|
-
async getLocation(elementId) {
|
|
147
|
-
const el = this.getElement(elementId);
|
|
148
|
-
return el.getLocation();
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @this {FakeDriver}
|
|
153
|
-
*/
|
|
154
|
-
async getLocationInView(elementId) {
|
|
155
|
-
return this.getLocation(elementId);
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @typedef {import('../driver').FakeDriver} FakeDriver
|
|
161
|
-
*/
|
package/lib/commands/find.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import {errors} from 'appium/driver';
|
|
3
|
-
import {FakeElement} from '../fake-element';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
/**
|
|
7
|
-
* @this {FakeDriver}
|
|
8
|
-
*/
|
|
9
|
-
getExistingElementForNode(node) {
|
|
10
|
-
for (let [id, el] of _.toPairs(this.elMap)) {
|
|
11
|
-
if (el.node === node) {
|
|
12
|
-
return id;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @this {FakeDriver}
|
|
20
|
-
*/
|
|
21
|
-
wrapNewEl(obj) {
|
|
22
|
-
// first check and see if we already have a ref to this element
|
|
23
|
-
let existingElId = this.getExistingElementForNode(obj);
|
|
24
|
-
if (existingElId) {
|
|
25
|
-
return {ELEMENT: existingElId};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// otherwise add the element to the map
|
|
29
|
-
this.maxElId++;
|
|
30
|
-
this.elMap[this.maxElId.toString()] = new FakeElement(obj, this.appModel);
|
|
31
|
-
return {ELEMENT: this.maxElId.toString()};
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @template {boolean} Mult
|
|
36
|
-
* @template [Ctx=any]
|
|
37
|
-
* @param {string} strategy
|
|
38
|
-
* @param {string} selector
|
|
39
|
-
* @param {Mult} mult
|
|
40
|
-
* @param {Ctx} [context]
|
|
41
|
-
* @returns {Promise<Mult extends true ? Element[] : Element>}
|
|
42
|
-
* @this {FakeDriver}
|
|
43
|
-
*/
|
|
44
|
-
async findElOrEls(strategy, selector, mult, context) {
|
|
45
|
-
let qMap = {
|
|
46
|
-
xpath: 'xpathQuery',
|
|
47
|
-
id: 'idQuery',
|
|
48
|
-
'accessibility id': 'idQuery',
|
|
49
|
-
'class name': 'classQuery',
|
|
50
|
-
'tag name': 'classQuery',
|
|
51
|
-
'css selector': 'cssQuery',
|
|
52
|
-
};
|
|
53
|
-
// TODO this error checking should probably be part of MJSONWP?
|
|
54
|
-
if (!_.includes(_.keys(qMap), strategy)) {
|
|
55
|
-
throw new errors.UnknownCommandError();
|
|
56
|
-
}
|
|
57
|
-
if (selector === 'badsel') {
|
|
58
|
-
throw new errors.InvalidSelectorError();
|
|
59
|
-
}
|
|
60
|
-
let els = this.appModel[qMap[strategy]](selector, context);
|
|
61
|
-
|
|
62
|
-
let retval;
|
|
63
|
-
if (els.length) {
|
|
64
|
-
if (mult) {
|
|
65
|
-
let allEls = [];
|
|
66
|
-
for (let el of els) {
|
|
67
|
-
allEls.push(this.wrapNewEl(el));
|
|
68
|
-
}
|
|
69
|
-
retval = allEls;
|
|
70
|
-
} else {
|
|
71
|
-
retval = this.wrapNewEl(els[0]);
|
|
72
|
-
}
|
|
73
|
-
} else if (mult) {
|
|
74
|
-
retval = [];
|
|
75
|
-
} else {
|
|
76
|
-
throw new errors.NoSuchElementError();
|
|
77
|
-
}
|
|
78
|
-
return /** @type {Mult extends true ? Element[] : Element} */ (retval);
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* This should override whatever's in ExternalDriver
|
|
83
|
-
* @param {string} strategy Strategy
|
|
84
|
-
* @param {string} selector Selector
|
|
85
|
-
* @this {FakeDriver}
|
|
86
|
-
*/
|
|
87
|
-
async findElement(strategy, selector) {
|
|
88
|
-
return this.findElOrEls(strategy, selector, false);
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @this {FakeDriver}
|
|
93
|
-
*/
|
|
94
|
-
async findElements(strategy, selector) {
|
|
95
|
-
return this.findElOrEls(strategy, selector, true);
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @this {FakeDriver}
|
|
100
|
-
*/
|
|
101
|
-
async findElementFromElement(strategy, selector, elementId) {
|
|
102
|
-
let el = this.getElement(elementId);
|
|
103
|
-
return this.findElOrEls(strategy, selector, false, el.xmlFragment);
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* @this {FakeDriver}
|
|
108
|
-
*/
|
|
109
|
-
async findElementsFromElement(strategy, selector, elementId) {
|
|
110
|
-
let el = this.getElement(elementId);
|
|
111
|
-
return this.findElOrEls(strategy, selector, true, el.xmlFragment);
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @typedef {import('@appium/types').Element} Element
|
|
117
|
-
* @typedef {import('../driver').FakeDriver} FakeDriver
|
|
118
|
-
*/
|