@appium/fake-driver 5.1.3 → 5.1.5

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.
Files changed (40) hide show
  1. package/build/lib/commands/alert.d.ts +58 -310
  2. package/build/lib/commands/alert.d.ts.map +1 -1
  3. package/build/lib/commands/alert.js +58 -69
  4. package/build/lib/commands/alert.js.map +1 -1
  5. package/build/lib/commands/contexts.d.ts +81 -330
  6. package/build/lib/commands/contexts.d.ts.map +1 -1
  7. package/build/lib/commands/contexts.js +75 -84
  8. package/build/lib/commands/contexts.js.map +1 -1
  9. package/build/lib/commands/element.d.ts +146 -315
  10. package/build/lib/commands/element.d.ts.map +1 -1
  11. package/build/lib/commands/element.js +134 -98
  12. package/build/lib/commands/element.js.map +1 -1
  13. package/build/lib/commands/find.d.ts +83 -327
  14. package/build/lib/commands/find.d.ts.map +1 -1
  15. package/build/lib/commands/find.js +93 -97
  16. package/build/lib/commands/find.js.map +1 -1
  17. package/build/lib/commands/general.d.ts +174 -332
  18. package/build/lib/commands/general.d.ts.map +1 -1
  19. package/build/lib/commands/general.js +119 -90
  20. package/build/lib/commands/general.js.map +1 -1
  21. package/build/lib/commands/index.d.ts +5 -1523
  22. package/build/lib/commands/index.d.ts.map +1 -1
  23. package/build/lib/commands/index.js +14 -14
  24. package/build/lib/commands/index.js.map +1 -1
  25. package/build/lib/driver.d.ts +80 -15
  26. package/build/lib/driver.d.ts.map +1 -1
  27. package/build/lib/driver.js +74 -24
  28. package/build/lib/driver.js.map +1 -1
  29. package/build/lib/types.d.ts +1 -24
  30. package/build/lib/types.d.ts.map +1 -1
  31. package/lib/commands/alert.js +58 -67
  32. package/lib/commands/contexts.js +72 -81
  33. package/lib/commands/element.js +135 -94
  34. package/lib/commands/find.js +94 -98
  35. package/lib/commands/general.js +119 -91
  36. package/lib/commands/index.js +5 -13
  37. package/lib/driver.js +76 -20
  38. package/lib/types.ts +1 -29
  39. package/package.json +4 -3
  40. package/build/tsconfig.tsbuildinfo +0 -1
@@ -1,101 +1,92 @@
1
1
  import _ from 'lodash';
2
2
  import {errors} from 'appium/driver';
3
3
 
4
- /**
5
- *
6
- * @template {Class<import('../types').IFakeDriver>} T
7
- * @param {T} Base
8
- */
9
- export function ContextsMixin(Base) {
4
+ export default {
10
5
  /**
11
- * @implements {IContextsCommands}
6
+ * @this {FakeDriver}
12
7
  */
13
- class ContextsCommands extends Base {
14
- getRawContexts() {
15
- let contexts = {NATIVE_APP: null, PROXY: null};
16
- let wvs = this.appModel?.getWebviews() ?? [];
17
- for (let i = 1; i < wvs.length + 1; i++) {
18
- contexts[`WEBVIEW_${i}`] = wvs[i - 1];
19
- }
20
- return contexts;
8
+ getRawContexts() {
9
+ let contexts = {NATIVE_APP: null, PROXY: null};
10
+ let wvs = this.appModel?.getWebviews() ?? [];
11
+ for (let i = 1; i < wvs.length + 1; i++) {
12
+ contexts[`WEBVIEW_${i}`] = wvs[i - 1];
21
13
  }
14
+ return contexts;
15
+ },
22
16
 
23
- assertWebviewContext() {
24
- if (this.curContext === 'NATIVE_APP') {
25
- throw new errors.InvalidContextError();
26
- }
17
+ /**
18
+ * @this {FakeDriver}
19
+ */
20
+ assertWebviewContext() {
21
+ if (this.curContext === 'NATIVE_APP') {
22
+ throw new errors.InvalidContextError();
27
23
  }
24
+ },
28
25
 
29
- // do not add a description to this method's docstring
30
- /*
31
- * @returns {Promise<string>}
32
- */
33
- async getCurrentContext() {
34
- return this.curContext;
35
- }
26
+ /**
27
+ * @returns {Promise<string>}
28
+ * @this {FakeDriver}
29
+ */
30
+ async getCurrentContext() {
31
+ return this.curContext;
32
+ },
36
33
 
37
- /**
38
- * Get the list of available contexts
39
- *
40
- * @returns {Promise<string[]>}
41
- */
42
- async getContexts() {
43
- return _.keys(this.getRawContexts());
44
- }
34
+ /**
35
+ * Get the list of available contexts
36
+ *
37
+ * @returns {Promise<string[]>}
38
+ * @this {FakeDriver}
39
+ */
40
+ async getContexts() {
41
+ return _.keys(this.getRawContexts());
42
+ },
45
43
 
46
- /**
47
- * Set the current context
48
- *
49
- * @param {string} context - name of the context
50
- * @returns {Promise<void>}
51
- */
52
- async setContext(context) {
53
- let contexts = this.getRawContexts();
54
- if (context in contexts) {
55
- this.curContext = context;
56
- if (context === 'NATIVE_APP') {
57
- this.appModel.deactivateWebview();
58
- this._proxyActive = false;
59
- } else if (context === 'PROXY') {
60
- this._proxyActive = true;
61
- } else {
62
- this.appModel.activateWebview(contexts[context]);
63
- this._proxyActive = false;
64
- }
44
+ /**
45
+ * Set the current context
46
+ *
47
+ * @param {string} context - name of the context
48
+ * @returns {Promise<void>}
49
+ * @this {FakeDriver}
50
+ */
51
+ async setContext(context) {
52
+ let contexts = this.getRawContexts();
53
+ if (context in contexts) {
54
+ this.curContext = context;
55
+ if (context === 'NATIVE_APP') {
56
+ this.appModel.deactivateWebview();
57
+ this._proxyActive = false;
58
+ } else if (context === 'PROXY') {
59
+ this._proxyActive = true;
65
60
  } else {
66
- throw new errors.NoSuchContextError();
61
+ this.appModel.activateWebview(contexts[context]);
62
+ this._proxyActive = false;
67
63
  }
64
+ } else {
65
+ throw new errors.NoSuchContextError();
68
66
  }
67
+ },
69
68
 
70
- /**
71
- * Set the active frame
72
- *
73
- * @param {number} frameId
74
- * @returns {Promise<void>}
75
- */
76
- async setFrame(frameId) {
77
- this.assertWebviewContext();
78
- if (frameId === null) {
79
- this.appModel.deactivateFrame();
80
- } else {
81
- let nodes = this.appModel.xpathQuery(`//iframe[@id="${frameId}"]`);
82
- if (!nodes.length) {
83
- throw new errors.NoSuchFrameError();
84
- }
85
- this.appModel.activateFrame(nodes[0]);
69
+ /**
70
+ * Set the active frame
71
+ *
72
+ * @param {number} frameId
73
+ * @returns {Promise<void>}
74
+ * @this {FakeDriver}
75
+ */
76
+ async setFrame(frameId) {
77
+ this.assertWebviewContext();
78
+ if (frameId === null) {
79
+ this.appModel.deactivateFrame();
80
+ } else {
81
+ let nodes = this.appModel.xpathQuery(`//iframe[@id="${frameId}"]`);
82
+ if (!nodes.length) {
83
+ throw new errors.NoSuchFrameError();
86
84
  }
85
+ this.appModel.activateFrame(nodes[0]);
87
86
  }
88
- }
89
-
90
- return ContextsCommands;
91
- }
92
-
93
- /**
94
- * @typedef {import('../driver').FakeDriverCore} FakeDriverCore
95
- * @typedef {import('../types').IContextsCommands} IContextsCommands
96
- */
87
+ },
88
+ };
97
89
 
98
90
  /**
99
- * @template T,[U={}],[V=Array<any>]
100
- * @typedef {import('@appium/types').Class<T,U,V>} Class
91
+ * @typedef {import('../driver').FakeDriver} FakeDriver
101
92
  */
@@ -1,120 +1,161 @@
1
1
  import _ from 'lodash';
2
2
  import {errors} from 'appium/driver';
3
-
4
- /**
5
- * @template {Class<import('../types').IContextsCommands & import('../types').IAlertCommands>} T
6
- * @param {T} Base
7
- */
8
- export function ElementMixin(Base) {
3
+ export default {
9
4
  /**
10
- * @implements {IElementCommands}
5
+ * @this {FakeDriver}
11
6
  */
12
- class ElementCommands extends Base {
13
- getElements(elIds) {
14
- for (let elId of elIds) {
15
- if (!_.has(this.elMap, elId)) {
16
- throw new errors.StaleElementReferenceError();
17
- }
7
+ getElements(elIds) {
8
+ for (let elId of elIds) {
9
+ if (!_.has(this.elMap, elId)) {
10
+ throw new errors.StaleElementReferenceError();
18
11
  }
19
- return elIds.map((e) => this.elMap[e]);
20
12
  }
13
+ return elIds.map((e) => this.elMap[e]);
14
+ },
21
15
 
22
- getElement(elId) {
23
- return this.getElements([elId])[0];
24
- }
16
+ /**
17
+ * @this {FakeDriver}
18
+ */
19
+ getElement(elId) {
20
+ return this.getElements([elId])[0];
21
+ },
25
22
 
26
- async getName(elementId) {
27
- let el = this.getElement(elementId);
28
- return el.tagName;
29
- }
23
+ /**
24
+ * @this {FakeDriver}
25
+ */
26
+ async getName(elementId) {
27
+ let el = this.getElement(elementId);
28
+ return el.tagName;
29
+ },
30
30
 
31
- async elementDisplayed(elementId) {
32
- let el = this.getElement(elementId);
33
- return el.isVisible();
34
- }
31
+ /**
32
+ * @this {FakeDriver}
33
+ */
34
+ async elementDisplayed(elementId) {
35
+ let el = this.getElement(elementId);
36
+ return el.isVisible();
37
+ },
35
38
 
36
- async elementEnabled(elementId) {
37
- let el = this.getElement(elementId);
38
- return el.isEnabled();
39
- }
39
+ /**
40
+ * @this {FakeDriver}
41
+ */
42
+ async elementEnabled(elementId) {
43
+ let el = this.getElement(elementId);
44
+ return el.isEnabled();
45
+ },
40
46
 
41
- async elementSelected(elementId) {
42
- let el = this.getElement(elementId);
43
- return el.isSelected();
44
- }
47
+ /**
48
+ * @this {FakeDriver}
49
+ */
50
+ async elementSelected(elementId) {
51
+ let el = this.getElement(elementId);
52
+ return el.isSelected();
53
+ },
45
54
 
46
- async setValue(keys, elementId) {
47
- let value = keys;
48
- if (keys instanceof Array) {
49
- value = keys.join('');
50
- }
51
- let el = this.getElement(elementId);
52
- if (el.type !== 'MockInputField') {
53
- throw new errors.InvalidElementStateError();
54
- }
55
- el.setAttr('value', value);
55
+ /**
56
+ * @this {FakeDriver}
57
+ */
58
+ async setValue(keys, elementId) {
59
+ let value = keys;
60
+ if (keys instanceof Array) {
61
+ value = keys.join('');
56
62
  }
57
-
58
- async getText(elementId) {
59
- let el = this.getElement(elementId);
60
- return el.getAttr('value');
63
+ let el = this.getElement(elementId);
64
+ if (el.type !== 'MockInputField') {
65
+ throw new errors.InvalidElementStateError();
61
66
  }
67
+ el.setAttr('value', value);
68
+ },
62
69
 
63
- async clear(elementId) {
64
- await this.setValue('', elementId);
65
- }
70
+ /**
71
+ * @this {FakeDriver}
72
+ */
73
+ async getText(elementId) {
74
+ let el = this.getElement(elementId);
75
+ return el.getAttr('value');
76
+ },
66
77
 
67
- /**
68
- * This comment should be displayed instead of the one from ExternalDriver
69
- * @param {string} elementId
70
- */
71
- async click(elementId) {
72
- this.assertNoAlert();
73
- let el = this.getElement(elementId);
74
- if (!el.isVisible()) {
75
- throw new errors.InvalidElementStateError();
76
- }
77
- el.click();
78
- this.focusedElId = elementId;
79
- }
78
+ /**
79
+ * @this {FakeDriver}
80
+ */
81
+ async clear(elementId) {
82
+ await this.setValue('', elementId);
83
+ },
80
84
 
81
- async getAttribute(attr, elementId) {
82
- let el = this.getElement(elementId);
83
- return el.getAttr(attr);
84
- }
85
- getElementRect(elementId) {
86
- let el = this.getElement(elementId);
87
- return el.getElementRect();
88
- }
89
- getSize(elementId) {
90
- let el = this.getElement(elementId);
91
- return el.getSize();
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();
92
95
  }
96
+ el.click();
97
+ this.focusedElId = elementId;
98
+ },
93
99
 
94
- equalsElement(el1Id, el2Id) {
95
- let el1 = this.getElement(el1Id);
96
- let el2 = this.getElement(el2Id);
97
- return el1.equals(el2);
98
- }
100
+ /**
101
+ * @this {FakeDriver}
102
+ */
103
+ async getAttribute(attr, elementId) {
104
+ let el = this.getElement(elementId);
105
+ return el.getAttr(attr);
106
+ },
99
107
 
100
- async getCssProperty(prop, elementId) {
101
- this.assertWebviewContext();
102
- let el = this.getElement(elementId);
103
- return el.getCss(prop);
104
- }
108
+ /**
109
+ * @this {FakeDriver}
110
+ */
111
+ getElementRect(elementId) {
112
+ let el = this.getElement(elementId);
113
+ return el.getElementRect();
114
+ },
105
115
 
106
- getLocationInView = this.getLocation;
107
- }
116
+ /**
117
+ * @this {FakeDriver}
118
+ */
119
+ getSize(elementId) {
120
+ let el = this.getElement(elementId);
121
+ return el.getSize();
122
+ },
108
123
 
109
- return ElementCommands;
110
- }
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
+ },
111
132
 
112
- /**
113
- * @typedef {import('../driver').FakeDriverCore} FakeDriverCore
114
- * @typedef {import('../types').IElementCommands} IElementCommands
115
- */
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
+ };
116
158
 
117
159
  /**
118
- * @template T,[U={}],[V=Array<any>]
119
- * @typedef {import('@appium/types').Class<T,U,V>} Class
160
+ * @typedef {import('../driver').FakeDriver} FakeDriver
120
161
  */
@@ -2,121 +2,117 @@ import _ from 'lodash';
2
2
  import {errors} from 'appium/driver';
3
3
  import {FakeElement} from '../fake-element';
4
4
 
5
- /**
6
- * @template {Class<import('../types').IElementCommands>} T
7
- * @param {T} Base
8
- */
9
- export function FindMixin(Base) {
5
+ export default {
10
6
  /**
11
- * @implements {IFindCommands}
7
+ * @this {FakeDriver}
12
8
  */
13
- class FindCommands extends Base {
14
- getExistingElementForNode(node) {
15
- for (let [id, el] of _.toPairs(this.elMap)) {
16
- if (el.node === node) {
17
- return id;
18
- }
9
+ getExistingElementForNode(node) {
10
+ for (let [id, el] of _.toPairs(this.elMap)) {
11
+ if (el.node === node) {
12
+ return id;
19
13
  }
20
- return null;
21
14
  }
15
+ return null;
16
+ },
22
17
 
23
- wrapNewEl(obj) {
24
- // first check and see if we already have a ref to this element
25
- let existingElId = this.getExistingElementForNode(obj);
26
- if (existingElId) {
27
- return {ELEMENT: existingElId};
28
- }
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
+ }
29
27
 
30
- // otherwise add the element to the map
31
- this.maxElId++;
32
- this.elMap[this.maxElId.toString()] = new FakeElement(obj, this.appModel);
33
- return {ELEMENT: this.maxElId.toString()};
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();
34
56
  }
35
- /**
36
- * @template {boolean} Mult
37
- * @template [Ctx=any]
38
- * @param {string} strategy
39
- * @param {string} selector
40
- * @param {Mult} mult
41
- * @param {Ctx} [context]
42
- * @returns {Promise<Mult extends true ? Element[] : Element>}
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);
57
+ if (selector === 'badsel') {
58
+ throw new errors.InvalidSelectorError();
59
+ }
60
+ let els = this.appModel[qMap[strategy]](selector, context);
61
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]);
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));
72
68
  }
73
- } else if (mult) {
74
- retval = [];
69
+ retval = allEls;
75
70
  } else {
76
- throw new errors.NoSuchElementError();
71
+ retval = this.wrapNewEl(els[0]);
77
72
  }
78
- return /** @type {Mult extends true ? Element[] : Element} */ (retval);
73
+ } else if (mult) {
74
+ retval = [];
75
+ } else {
76
+ throw new errors.NoSuchElementError();
79
77
  }
78
+ return /** @type {Mult extends true ? Element[] : Element} */ (retval);
79
+ },
80
80
 
81
- /**
82
- * This should override whatever's in ExternalDriver
83
- * @param {string} strategy Strategy
84
- * @param {string} selector Selector
85
- */
86
- async findElement(strategy, selector) {
87
- return this.findElOrEls(strategy, selector, false);
88
- }
89
-
90
- async findElements(strategy, selector) {
91
- return this.findElOrEls(strategy, selector, true);
92
- }
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
+ },
93
90
 
94
- async findElementFromElement(strategy, selector, elementId) {
95
- let el = this.getElement(elementId);
96
- return this.findElOrEls(strategy, selector, false, el.xmlFragment);
97
- }
91
+ /**
92
+ * @this {FakeDriver}
93
+ */
94
+ async findElements(strategy, selector) {
95
+ return this.findElOrEls(strategy, selector, true);
96
+ },
98
97
 
99
- async findElementsFromElement(strategy, selector, elementId) {
100
- let el = this.getElement(elementId);
101
- return this.findElOrEls(strategy, selector, true, el.xmlFragment);
102
- }
103
- }
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
+ },
104
105
 
105
- return FindCommands;
106
- }
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
+ };
107
114
 
108
115
  /**
109
- * @typedef {import('../driver').FakeDriverCore} FakeDriverCore
110
116
  * @typedef {import('@appium/types').Element} Element
111
-
112
- */
113
-
114
- /**
115
- * @template T,[U={}],[V=Array<any>]
116
- * @typedef {import('@appium/types').Class<T,U,V>} Class
117
- */
118
-
119
- /**
120
- * @template [Ctx=any]
121
- * @typedef {import('@appium/types').IFindCommands<Ctx>} IFindCommands
117
+ * @typedef {import('../driver').FakeDriver} FakeDriver
122
118
  */