@appium/fake-driver 5.1.5 → 5.2.1
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 -77
- 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 -81
- 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 -145
- 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 -84
- 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 -173
- 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 +26 -13
- 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 +38 -93
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +27 -74
- 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/build/lib/types.d.ts +2 -2
- package/build/lib/types.d.ts.map +1 -1
- 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 +43 -79
- 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/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
|
-
*/
|
package/lib/commands/general.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import {errors} from 'appium/driver';
|
|
2
|
-
|
|
3
|
-
const ORIENTATIONS = new Set(['LANDSCAPE', 'PORTRAIT']);
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
/**
|
|
7
|
-
* @this {FakeDriver}
|
|
8
|
-
*/
|
|
9
|
-
async title() {
|
|
10
|
-
this.assertWebviewContext();
|
|
11
|
-
return this.appModel.title;
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @this {FakeDriver}
|
|
16
|
-
*/
|
|
17
|
-
async keys(value) {
|
|
18
|
-
if (!this.focusedElId) {
|
|
19
|
-
throw new errors.InvalidElementStateError();
|
|
20
|
-
}
|
|
21
|
-
await this.setValue(value, this.focusedElId);
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @this {FakeDriver}
|
|
26
|
-
*/
|
|
27
|
-
async setGeoLocation(location) {
|
|
28
|
-
// TODO test this adequately once WD bug is fixed
|
|
29
|
-
this.appModel.lat = location.latitude;
|
|
30
|
-
this.appModel.long = location.longitude;
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @this {FakeDriver}
|
|
35
|
-
*/
|
|
36
|
-
async getGeoLocation() {
|
|
37
|
-
return this.appModel.currentGeoLocation;
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @this {FakeDriver}
|
|
42
|
-
*/
|
|
43
|
-
async getPageSource() {
|
|
44
|
-
return this.appModel.rawXml;
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @this {FakeDriver}
|
|
49
|
-
*/
|
|
50
|
-
async getOrientation() {
|
|
51
|
-
return this.appModel.orientation;
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @param {import('../types').FakeDriverCaps['orientation']} o
|
|
57
|
-
* @this {FakeDriver}
|
|
58
|
-
*/
|
|
59
|
-
async setOrientation(o) {
|
|
60
|
-
if (!ORIENTATIONS.has(o)) {
|
|
61
|
-
throw new errors.UnknownError('Orientation must be LANDSCAPE or PORTRAIT');
|
|
62
|
-
}
|
|
63
|
-
this.appModel.orientation = o;
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @this {FakeDriver}
|
|
68
|
-
*/
|
|
69
|
-
async getScreenshot() {
|
|
70
|
-
return this.appModel.getScreenshot();
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @this {FakeDriver}
|
|
75
|
-
*/
|
|
76
|
-
async getWindowSize() {
|
|
77
|
-
return {width: this.appModel.width, height: this.appModel.height};
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @this {FakeDriver}
|
|
82
|
-
*/
|
|
83
|
-
async getWindowRect() {
|
|
84
|
-
return {width: this.appModel.width, height: this.appModel.height, x: 0, y: 0};
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
*
|
|
89
|
-
* @this {FakeDriver}
|
|
90
|
-
*/
|
|
91
|
-
async performActions(actions) {
|
|
92
|
-
this.appModel.actionLog.push(actions);
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @this {FakeDriver}
|
|
97
|
-
*/
|
|
98
|
-
async releaseActions() {},
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* @this {FakeDriver}
|
|
102
|
-
*/
|
|
103
|
-
async getLog(type) {
|
|
104
|
-
switch (type) {
|
|
105
|
-
case 'actions':
|
|
106
|
-
return this.appModel.actionLog;
|
|
107
|
-
default:
|
|
108
|
-
throw new Error(`Don't understand log type '${type}'`);
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @this {FakeDriver}
|
|
114
|
-
*/
|
|
115
|
-
async mobileShake() {
|
|
116
|
-
this.shook = true;
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @this {FakeDriver}
|
|
121
|
-
*/
|
|
122
|
-
async doubleClick() {},
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @this {FakeDriver}
|
|
126
|
-
*/
|
|
127
|
-
async execute(script, args) {
|
|
128
|
-
return await this.executeMethod(script, args);
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Add two or maybe even three numbers
|
|
133
|
-
*
|
|
134
|
-
* @param {number} num1
|
|
135
|
-
* @param {number} num2
|
|
136
|
-
* @param {number} [num3]
|
|
137
|
-
* @returns {Promise<number>}
|
|
138
|
-
* @this {FakeDriver}
|
|
139
|
-
*/
|
|
140
|
-
async fakeAddition(num1, num2, num3 = 0) {
|
|
141
|
-
return num1 + num2 + (num3 ?? 0);
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* @typedef {import('../driver').FakeDriver} FakeDriver
|
|
147
|
-
*/
|