@appium/fake-driver 6.0.2 → 6.1.0

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 (112) hide show
  1. package/LICENSE +201 -0
  2. package/build/lib/commands/alert.d.ts +10 -13
  3. package/build/lib/commands/alert.d.ts.map +1 -1
  4. package/build/lib/commands/alert.js +39 -46
  5. package/build/lib/commands/alert.js.map +1 -1
  6. package/build/lib/commands/contexts.d.ts +9 -13
  7. package/build/lib/commands/contexts.d.ts.map +1 -1
  8. package/build/lib/commands/contexts.js +55 -62
  9. package/build/lib/commands/contexts.js.map +1 -1
  10. package/build/lib/commands/element.d.ts +23 -26
  11. package/build/lib/commands/element.d.ts.map +1 -1
  12. package/build/lib/commands/element.js +100 -89
  13. package/build/lib/commands/element.js.map +1 -1
  14. package/build/lib/commands/find.d.ts +14 -17
  15. package/build/lib/commands/find.d.ts.map +1 -1
  16. package/build/lib/commands/find.js +66 -63
  17. package/build/lib/commands/find.js.map +1 -1
  18. package/build/lib/commands/general.d.ts +25 -28
  19. package/build/lib/commands/general.d.ts.map +1 -1
  20. package/build/lib/commands/general.js +90 -75
  21. package/build/lib/commands/general.js.map +1 -1
  22. package/build/lib/desired-caps.d.ts +14 -0
  23. package/build/lib/desired-caps.d.ts.map +1 -0
  24. package/build/lib/desired-caps.js +16 -0
  25. package/build/lib/desired-caps.js.map +1 -0
  26. package/build/lib/doctor/common.d.ts +11 -0
  27. package/build/lib/doctor/common.d.ts.map +1 -0
  28. package/build/lib/doctor/common.js +25 -0
  29. package/build/lib/doctor/common.js.map +1 -0
  30. package/build/lib/doctor/fake1.d.ts +3 -0
  31. package/build/lib/doctor/fake1.d.ts.map +1 -0
  32. package/build/lib/doctor/fake1.js +6 -0
  33. package/build/lib/doctor/fake1.js.map +1 -0
  34. package/build/lib/doctor/fake2.d.ts +3 -0
  35. package/build/lib/doctor/fake2.d.ts.map +1 -0
  36. package/build/lib/doctor/fake2.js +6 -0
  37. package/build/lib/doctor/fake2.js.map +1 -0
  38. package/build/lib/driver.d.ts +128 -156
  39. package/build/lib/driver.d.ts.map +1 -1
  40. package/build/lib/driver.js +146 -154
  41. package/build/lib/driver.js.map +1 -1
  42. package/build/lib/fake-app.d.ts +37 -45
  43. package/build/lib/fake-app.d.ts.map +1 -1
  44. package/build/lib/fake-app.js +57 -34
  45. package/build/lib/fake-app.js.map +1 -1
  46. package/build/lib/fake-driver-schema.d.ts +16 -11
  47. package/build/lib/fake-driver-schema.d.ts.map +1 -1
  48. package/build/lib/fake-driver-schema.js +2 -17
  49. package/build/lib/fake-driver-schema.js.map +1 -1
  50. package/build/lib/fake-element.d.ts +27 -26
  51. package/build/lib/fake-element.d.ts.map +1 -1
  52. package/build/lib/fake-element.js +19 -19
  53. package/build/lib/fake-element.js.map +1 -1
  54. package/build/lib/index.d.ts +2 -3
  55. package/build/lib/index.d.ts.map +1 -1
  56. package/build/lib/index.js +2 -6
  57. package/build/lib/index.js.map +1 -1
  58. package/build/lib/logger.d.ts +1 -2
  59. package/build/lib/logger.d.ts.map +1 -1
  60. package/build/lib/logger.js +2 -2
  61. package/build/lib/logger.js.map +1 -1
  62. package/build/lib/scripts/fake-error.d.ts.map +1 -1
  63. package/build/lib/scripts/fake-error.js.map +1 -1
  64. package/build/lib/scripts/fake-stdin.d.ts.map +1 -1
  65. package/build/lib/scripts/fake-stdin.js.map +1 -1
  66. package/build/lib/scripts/fake-success.d.ts.map +1 -1
  67. package/build/lib/scripts/fake-success.js +3 -6
  68. package/build/lib/scripts/fake-success.js.map +1 -1
  69. package/build/lib/server.d.ts +2 -1
  70. package/build/lib/server.d.ts.map +1 -1
  71. package/build/lib/server.js +3 -5
  72. package/build/lib/server.js.map +1 -1
  73. package/build/lib/types.d.ts +1 -1
  74. package/build/lib/types.d.ts.map +1 -1
  75. package/lib/commands/alert.ts +31 -61
  76. package/lib/commands/contexts.ts +50 -73
  77. package/lib/commands/element.ts +122 -135
  78. package/lib/commands/find.ts +100 -115
  79. package/lib/commands/general.ts +122 -127
  80. package/lib/desired-caps.ts +16 -0
  81. package/lib/doctor/common.ts +26 -0
  82. package/lib/doctor/fake1.ts +3 -0
  83. package/lib/doctor/fake2.ts +3 -0
  84. package/lib/driver.ts +321 -0
  85. package/lib/fake-app.ts +234 -0
  86. package/lib/fake-driver-schema.ts +43 -0
  87. package/lib/fake-element.ts +128 -0
  88. package/lib/{index.js → index.ts} +5 -9
  89. package/lib/logger.ts +3 -0
  90. package/lib/scripts/{fake-success.js → fake-success.ts} +1 -1
  91. package/lib/{server.js → server.ts} +3 -4
  92. package/lib/types.ts +1 -1
  93. package/package.json +9 -12
  94. package/tsconfig.json +2 -1
  95. package/build/lib/commands/index.d.ts +0 -14
  96. package/build/lib/commands/index.d.ts.map +0 -1
  97. package/build/lib/commands/index.js +0 -16
  98. package/build/lib/commands/index.js.map +0 -1
  99. package/build/lib/commands/mixin.d.ts +0 -11
  100. package/build/lib/commands/mixin.d.ts.map +0 -1
  101. package/build/lib/commands/mixin.js +0 -16
  102. package/build/lib/commands/mixin.js.map +0 -1
  103. package/lib/commands/index.ts +0 -14
  104. package/lib/commands/mixin.ts +0 -13
  105. package/lib/driver.js +0 -356
  106. package/lib/fake-app.js +0 -190
  107. package/lib/fake-driver-schema.js +0 -35
  108. package/lib/fake-element.js +0 -117
  109. package/lib/logger.js +0 -5
  110. package/test/fixtures/app.xml +0 -38
  111. /package/lib/scripts/{fake-error.js → fake-error.ts} +0 -0
  112. /package/lib/scripts/{fake-stdin.js → fake-stdin.ts} +0 -0
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.startServer = startServer;
7
- const logger_1 = __importDefault(require("./logger"));
4
+ const logger_1 = require("./logger");
8
5
  const driver_1 = require("appium/driver");
9
6
  const driver_2 = require("./driver");
7
+ /** Start HTTP server with FakeDriver and default WebDriver routes. */
10
8
  async function startServer(port, hostname) {
11
9
  const d = new driver_2.FakeDriver();
12
10
  const server = await (0, driver_1.server)({
@@ -14,7 +12,7 @@ async function startServer(port, hostname) {
14
12
  port,
15
13
  hostname,
16
14
  });
17
- logger_1.default.info(`FakeDriver server listening on http://${hostname}:${port}`);
15
+ logger_1.log.info(`FakeDriver server listening on http://${hostname}:${port}`);
18
16
  return server;
19
17
  }
20
18
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../lib/server.js"],"names":[],"mappings":";;;;;AAeQ,kCAAW;AAfnB,sDAA2B;AAC3B,0CAA6E;AAC7E,qCAAoC;AAEpC,KAAK,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ;IACvC,MAAM,CAAC,GAAG,IAAI,mBAAU,EAAE,CAAC;IAC3B,MAAM,MAAM,GAAG,MAAM,IAAA,eAAU,EAAC;QAC9B,wBAAwB,EAAE,IAAA,iCAAwB,EAAC,CAAC,CAAC;QACrD,IAAI;QACJ,QAAQ;KACT,CAAC,CAAC;IACH,gBAAG,CAAC,IAAI,CAAC,yCAAyC,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;IACtE,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../lib/server.ts"],"names":[],"mappings":";;AAKA,kCASC;AAdD,qCAA6B;AAC7B,0CAA6E;AAC7E,qCAAoC;AAEpC,sEAAsE;AAC/D,KAAK,UAAU,WAAW,CAAC,IAAY,EAAE,QAAgB;IAC9D,MAAM,CAAC,GAAG,IAAI,mBAAU,EAAE,CAAC;IAC3B,MAAM,MAAM,GAAG,MAAM,IAAA,eAAU,EAAC;QAC9B,wBAAwB,EAAE,IAAA,iCAAwB,EAAC,CAAC,CAAC;QACrD,IAAI;QACJ,QAAQ;KACT,CAAC,CAAC;IACH,YAAG,CAAC,IAAI,CAAC,yCAAyC,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;IACtE,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { DriverCaps, W3CDriverCaps } from '@appium/types';
2
- import type { FakeDriverConstraints } from './driver';
2
+ import type { FakeDriverConstraints } from './desired-caps';
3
3
  /**
4
4
  * W3C-style caps for {@link FakeDriver}
5
5
  * @public
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,UAAU,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC,qBAAqB,CAAC,CAAC;AAErE;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,qBAAqB,CAAC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,gBAAgB,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC,qBAAqB,CAAC,CAAC;AAErE;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,qBAAqB,CAAC,CAAC"}
@@ -1,70 +1,40 @@
1
- import {FakeDriver} from '../driver';
1
+ import type {FakeDriver} from '../driver';
2
2
  import {errors} from 'appium/driver';
3
- import {mixin} from './mixin';
4
3
 
5
- interface FakeDriverAlertMixin {
6
- assertNoAlert(): void;
7
- assertAlert(): void;
8
-
9
- getAlertText(): Promise<string>;
10
-
11
- setAlertText(text: string): Promise<void>;
12
-
13
- postAcceptAlert(): Promise<void>;
14
- postDismissAlert(): Promise<void>;
4
+ /** Throw if an alert is currently open (blocks other commands). */
5
+ export function assertNoAlert(this: FakeDriver): void {
6
+ if (this.appModel.hasAlert()) {
7
+ throw new errors.UnexpectedAlertOpenError();
8
+ }
15
9
  }
16
10
 
17
- declare module '../driver' {
18
- interface FakeDriver extends FakeDriverAlertMixin {}
11
+ /** Throw if no alert is open (required before get/set alert text, accept, etc.). */
12
+ export function assertAlert(this: FakeDriver): void {
13
+ if (!this.appModel.hasAlert()) {
14
+ throw new errors.NoAlertOpenError();
15
+ }
19
16
  }
20
17
 
21
- const AlertMixin: FakeDriverAlertMixin = {
22
- assertNoAlert(this: FakeDriver) {
23
- if (this.appModel.hasAlert()) {
24
- throw new errors.UnexpectedAlertOpenError();
25
- }
26
- },
27
-
28
- assertAlert(this: FakeDriver) {
29
- if (!this.appModel.hasAlert()) {
30
- throw new errors.NoAlertOpenError();
31
- }
32
- },
33
-
34
- /**
35
- * Get the text of an alert
36
- */
37
- async getAlertText(this: FakeDriver) {
38
- this.assertAlert();
39
- return this.appModel.alertText();
40
- },
41
-
42
- /**
43
- * Set the text of an alert
44
- */
45
- async setAlertText(this: FakeDriver, text: string) {
46
- this.assertAlert();
47
- try {
48
- this.appModel.setAlertText(text);
49
- } catch {
50
- throw new errors.InvalidElementStateError();
51
- }
52
- },
18
+ export async function getAlertText(this: FakeDriver): Promise<string> {
19
+ this.assertAlert();
20
+ return this.appModel.alertText();
21
+ }
53
22
 
54
- /**
55
- * Accept an alert
56
- */
57
- async postAcceptAlert(this: FakeDriver) {
58
- this.assertAlert();
59
- this.appModel.handleAlert();
60
- },
23
+ export async function setAlertText(this: FakeDriver, text: string): Promise<void> {
24
+ this.assertAlert();
25
+ try {
26
+ this.appModel.setAlertText(text);
27
+ } catch {
28
+ throw new errors.InvalidElementStateError();
29
+ }
30
+ }
61
31
 
62
- /**
63
- * Dismiss an alert
64
- */
65
- async postDismissAlert(this: FakeDriver) {
66
- return this.postAcceptAlert();
67
- },
68
- };
32
+ export async function postAcceptAlert(this: FakeDriver): Promise<void> {
33
+ this.assertAlert();
34
+ this.appModel.handleAlert();
35
+ }
69
36
 
70
- mixin(AlertMixin);
37
+ /** In this fake, dismiss is the same as accept. */
38
+ export async function postDismissAlert(this: FakeDriver): Promise<void> {
39
+ return this.postAcceptAlert();
40
+ }
@@ -1,84 +1,61 @@
1
1
  import _ from 'lodash';
2
- import {FakeDriver} from '../driver';
2
+ import type {Document as XMLDocument} from '@xmldom/xmldom';
3
+ import type {FakeDriver} from '../driver';
4
+ import type {FakeWebView} from '../fake-app';
3
5
  import {errors} from 'appium/driver';
4
- import {mixin} from './mixin';
5
- interface FakeDriverContextsMixin {
6
- getRawContexts(): Record<string, any>;
7
- assertWebviewContext(): void;
8
- getCurrentContext(): Promise<string>;
9
- getContexts(): Promise<string[]>;
10
- setContext(context: string): Promise<void>;
11
- setFrame(frame: number | null): Promise<void>;
12
- }
13
- declare module '../driver' {
14
- interface FakeDriver extends FakeDriverContextsMixin {}
15
- }
16
6
 
17
- const ContextsMixin: FakeDriverContextsMixin = {
18
- getRawContexts(this: FakeDriver) {
19
- const contexts = {NATIVE_APP: null, PROXY: null};
20
- const wvs = this.appModel.getWebviews() ?? [];
21
- for (let i = 1; i < wvs.length + 1; i++) {
22
- contexts[`WEBVIEW_${i}`] = wvs[i - 1];
23
- }
24
- return contexts;
25
- },
7
+ /** NATIVE_APP, PROXY, and WEBVIEW_1, WEBVIEW_2, ... from app model. */
8
+ export function getRawContexts(this: FakeDriver): Record<string, unknown> {
9
+ const contexts: Record<string, unknown> = {NATIVE_APP: null, PROXY: null};
10
+ const wvs = this.appModel.getWebviews() ?? [];
11
+ for (let i = 1; i < wvs.length + 1; i++) {
12
+ contexts[`WEBVIEW_${i}`] = wvs[i - 1];
13
+ }
14
+ return contexts;
15
+ }
26
16
 
27
- assertWebviewContext(this: FakeDriver) {
28
- if (this.curContext === 'NATIVE_APP') {
29
- throw new errors.InvalidContextError();
30
- }
31
- },
17
+ /** Throw if current context is NATIVE_APP (e.g. CSS/title require a webview). */
18
+ export function assertWebviewContext(this: FakeDriver): void {
19
+ if (this.curContext === 'NATIVE_APP') {
20
+ throw new errors.InvalidContextError();
21
+ }
22
+ }
32
23
 
33
- async getCurrentContext(this: FakeDriver): Promise<string> {
34
- return this.curContext;
35
- },
24
+ export async function getCurrentContext(this: FakeDriver): Promise<string> {
25
+ return this.curContext;
26
+ }
36
27
 
37
- /**
38
- * Get the list of available contexts
39
- */
40
- async getContexts(this: FakeDriver) {
41
- return _.keys(this.getRawContexts());
42
- },
28
+ export async function getContexts(this: FakeDriver): Promise<string[]> {
29
+ return _.keys(this.getRawContexts());
30
+ }
43
31
 
44
- /**
45
- * Set the current context
46
- *
47
- * @param context - name of the context
48
- */
49
- async setContext(this: FakeDriver, context: string) {
50
- const contexts = this.getRawContexts();
51
- if (context in contexts) {
52
- this.curContext = context;
53
- if (context === 'NATIVE_APP') {
54
- this.appModel.deactivateWebview();
55
- this._proxyActive = false;
56
- } else if (context === 'PROXY') {
57
- this._proxyActive = true;
58
- } else {
59
- this.appModel.activateWebview(contexts[context]);
60
- this._proxyActive = false;
61
- }
32
+ export async function setContext(this: FakeDriver, context: string): Promise<void> {
33
+ const contexts = this.getRawContexts();
34
+ if (context in contexts) {
35
+ this.curContext = context;
36
+ if (context === 'NATIVE_APP') {
37
+ this.appModel.deactivateWebview();
38
+ this._proxyActive = false;
39
+ } else if (context === 'PROXY') {
40
+ this._proxyActive = true;
62
41
  } else {
63
- throw new errors.NoSuchContextError();
42
+ this.appModel.activateWebview(contexts[context] as FakeWebView);
43
+ this._proxyActive = false;
64
44
  }
65
- },
45
+ } else {
46
+ throw new errors.NoSuchContextError();
47
+ }
48
+ }
66
49
 
67
- /**
68
- * Set the active frame
69
- */
70
- async setFrame(this: FakeDriver, frameId: number | null) {
71
- this.assertWebviewContext();
72
- if (frameId === null) {
73
- this.appModel.deactivateFrame();
74
- } else {
75
- const nodes = this.appModel.xpathQuery(`//iframe[@id="${frameId}"]`);
76
- if (!_.isArray(nodes) || _.isEmpty(nodes)) {
77
- throw new errors.NoSuchFrameError();
78
- }
79
- this.appModel.activateFrame(nodes[0]);
50
+ export async function setFrame(this: FakeDriver, frameId: number | null): Promise<void> {
51
+ this.assertWebviewContext();
52
+ if (frameId === null) {
53
+ this.appModel.deactivateFrame();
54
+ } else {
55
+ const nodes = this.appModel.xpathQuery(`//iframe[@id="${frameId}"]`);
56
+ if (!_.isArray(nodes) || _.isEmpty(nodes)) {
57
+ throw new errors.NoSuchFrameError();
80
58
  }
81
- },
82
- };
83
-
84
- mixin(ContextsMixin);
59
+ this.appModel.activateFrame(nodes[0] as XMLDocument);
60
+ }
61
+ }
@@ -1,138 +1,125 @@
1
1
  import _ from 'lodash';
2
2
  import {errors} from 'appium/driver';
3
- import {FakeDriver} from '../driver';
4
- import {Position, Rect, Size} from '@appium/types';
5
- import {FakeElement} from '../fake-element';
6
- import {mixin} from './mixin';
7
-
8
- interface FakeDriverElementsMixin {
9
- getElements(elementIds: string[]): FakeElement[];
10
- getElement(elementId: string): FakeElement;
11
- getName(elementId: string): Promise<string>;
12
- elementDisplayed(elementId: string): Promise<boolean>;
13
- elementEnabled(elementId: string): Promise<boolean>;
14
- elementSelected(elementId: string): Promise<boolean>;
15
- setValue(keys: string | string[], value: string): Promise<void>;
16
- getText(elementId: string): Promise<string>;
17
- clear(elementId: string): Promise<void>;
18
- click(elementId: string): Promise<void>;
19
-
20
- getAttribute(elementId: string, attributeName: string): Promise<string>;
21
- getElementRect(elementId: string): Promise<Rect>;
22
- getSize(elementId: string): Promise<Size>;
23
- equalsElement(elementId: string, otherElementId: string): Promise<boolean>;
24
- getCssProperty(elementId: string, propertyName: string): Promise<string>;
25
- getLocation(elementId: string): Promise<Position>;
26
- getLocationInView(elementId: string): Promise<Position>;
27
- }
28
-
29
- declare module '../driver' {
30
- interface FakeDriver extends FakeDriverElementsMixin {}
31
- }
32
-
33
- const ElementsMixin: FakeDriverElementsMixin = {
34
- getElements(this: FakeDriver, elementIds: string[]) {
35
- for (const elId of elementIds) {
36
- if (!_.has(this.elMap, elId)) {
37
- throw new errors.StaleElementReferenceError();
38
- }
3
+ import type {FakeDriver} from '../driver';
4
+ import type {Position, Rect, Size} from '@appium/types';
5
+ import type {FakeElement} from '../fake-element';
6
+
7
+ /** Resolve element ids to FakeElements; throws StaleElementReferenceError if any id is missing. */
8
+ export function getElements(this: FakeDriver, elementIds: string[]): FakeElement[] {
9
+ for (const elId of elementIds) {
10
+ if (!_.has(this.elMap, elId)) {
11
+ throw new errors.StaleElementReferenceError();
39
12
  }
40
- return elementIds.map((e) => this.elMap[e]);
41
- },
42
-
43
- getElement(this: FakeDriver, elementId: string) {
44
- return this.getElements([elementId])[0];
45
- },
46
-
47
- async getName(this: FakeDriver, elementId: string) {
48
- const el = this.getElement(elementId);
49
- return el.tagName;
50
- },
51
-
52
- async elementDisplayed(this: FakeDriver, elementId: string) {
53
- const el = this.getElement(elementId);
54
- return el.isVisible();
55
- },
56
-
57
- async elementEnabled(this: FakeDriver, elementId: string) {
58
- const el = this.getElement(elementId);
59
- return el.isEnabled();
60
- },
61
-
62
- async elementSelected(this: FakeDriver, elementId: string) {
63
- const el = this.getElement(elementId);
64
- return el.isSelected();
65
- },
66
-
67
- async setValue(this: FakeDriver, keys: string | string[], elementId: string) {
68
- let value = keys;
69
- if (keys instanceof Array) {
70
- value = keys.join('');
71
- }
72
- const el = this.getElement(elementId);
73
- if (el.type !== 'MockInputField') {
74
- throw new errors.InvalidElementStateError();
75
- }
76
- el.setAttr('value', value);
77
- },
78
-
79
- async getText(this: FakeDriver, elementId: string) {
80
- const el = this.getElement(elementId);
81
- return el.getAttr('value');
82
- },
83
-
84
- async clear(this: FakeDriver, elementId: string) {
85
- await this.setValue('', elementId);
86
- },
87
-
88
- /**
89
- * This comment should be displayed instead of the one from ExternalDriver
90
- */
91
- async click(this: FakeDriver, elementId: string) {
92
- this.assertNoAlert();
93
- const el = this.getElement(elementId);
94
- if (!el.isVisible()) {
95
- throw new errors.InvalidElementStateError();
96
- }
97
- el.click();
98
- this.focusedElId = elementId;
99
- },
100
-
101
- async getAttribute(this: FakeDriver, attr: string, elementId: string) {
102
- const el = this.getElement(elementId);
103
- return el.getAttr(attr);
104
- },
105
-
106
- async getElementRect(this: FakeDriver, elementId: string) {
107
- const el = this.getElement(elementId);
108
- return el.getElementRect();
109
- },
110
-
111
- async getSize(this: FakeDriver, elementId: string) {
112
- const el = this.getElement(elementId);
113
- return el.getSize();
114
- },
115
-
116
- async equalsElement(this: FakeDriver, elementIdA: string, elementIdB: string) {
117
- const el1 = this.getElement(elementIdA);
118
- const el2 = this.getElement(elementIdB);
119
- return el1.equals(el2);
120
- },
121
-
122
- async getCssProperty(this: FakeDriver, prop: string, elementId: string) {
123
- this.assertWebviewContext();
124
- const el = this.getElement(elementId);
125
- return el.getCss(prop) ?? '';
126
- },
127
-
128
- async getLocation(this: FakeDriver, elementId: string) {
129
- const el = this.getElement(elementId);
130
- return el.getLocation();
131
- },
132
-
133
- async getLocationInView(this: FakeDriver, elementId: string) {
134
- return this.getLocation(elementId);
135
- },
136
- };
137
-
138
- mixin(ElementsMixin);
13
+ }
14
+ return elementIds.map((e) => this.elMap[e]);
15
+ }
16
+
17
+ export function getElement(this: FakeDriver, elementId: string): FakeElement {
18
+ return this.getElements([elementId])[0];
19
+ }
20
+
21
+ export async function getName(this: FakeDriver, elementId: string): Promise<string> {
22
+ const el = this.getElement(elementId);
23
+ return el.tagName;
24
+ }
25
+
26
+ export async function elementDisplayed(this: FakeDriver, elementId: string): Promise<boolean> {
27
+ const el = this.getElement(elementId);
28
+ return el.isVisible();
29
+ }
30
+
31
+ export async function elementEnabled(this: FakeDriver, elementId: string): Promise<boolean> {
32
+ const el = this.getElement(elementId);
33
+ return el.isEnabled();
34
+ }
35
+
36
+ export async function elementSelected(this: FakeDriver, elementId: string): Promise<boolean> {
37
+ const el = this.getElement(elementId);
38
+ return el.isSelected();
39
+ }
40
+
41
+ export async function setValue(
42
+ this: FakeDriver,
43
+ keys: string | string[],
44
+ elementId: string
45
+ ): Promise<void> {
46
+ const value = _.isArray(keys) ? keys.join('') : keys;
47
+ const el = this.getElement(elementId);
48
+ // Only MockInputField supports value in the fake app XML.
49
+ if (el.type !== 'MockInputField') {
50
+ throw new errors.InvalidElementStateError();
51
+ }
52
+ el.setAttr('value', value);
53
+ }
54
+
55
+ export async function getText(this: FakeDriver, elementId: string): Promise<string> {
56
+ const el = this.getElement(elementId);
57
+ return el.getAttr('value');
58
+ }
59
+
60
+ export async function clear(this: FakeDriver, elementId: string): Promise<void> {
61
+ await this.setValue('', elementId);
62
+ }
63
+
64
+ export async function click(this: FakeDriver, elementId: string): Promise<void> {
65
+ this.assertNoAlert();
66
+ const el = this.getElement(elementId);
67
+ if (!el.isVisible()) {
68
+ throw new errors.InvalidElementStateError();
69
+ }
70
+ el.click();
71
+ this.focusedElId = elementId;
72
+ }
73
+
74
+ /** Protocol order: attribute name, then element id (from route /attribute/:name). */
75
+ export async function getAttribute(
76
+ this: FakeDriver,
77
+ attributeName: string,
78
+ elementId: string
79
+ ): Promise<string> {
80
+ const el = this.getElement(elementId);
81
+ return el.getAttr(attributeName);
82
+ }
83
+
84
+ export async function getElementRect(this: FakeDriver, elementId: string): Promise<Rect> {
85
+ const el = this.getElement(elementId);
86
+ return el.getElementRect();
87
+ }
88
+
89
+ export async function getSize(this: FakeDriver, elementId: string): Promise<Size> {
90
+ const el = this.getElement(elementId);
91
+ return el.getSize();
92
+ }
93
+
94
+ export async function equalsElement(
95
+ this: FakeDriver,
96
+ elementIdA: string,
97
+ elementIdB: string
98
+ ): Promise<boolean> {
99
+ const el1 = this.getElement(elementIdA);
100
+ const el2 = this.getElement(elementIdB);
101
+ return el1.equals(el2);
102
+ }
103
+
104
+ /** Protocol order: property name, then element id. Requires webview context. */
105
+ export async function getCssProperty(
106
+ this: FakeDriver,
107
+ propertyName: string,
108
+ elementId: string
109
+ ): Promise<string> {
110
+ this.assertWebviewContext();
111
+ const el = this.getElement(elementId);
112
+ return el.getCss(propertyName) ?? '';
113
+ }
114
+
115
+ export async function getLocation(this: FakeDriver, elementId: string): Promise<Position> {
116
+ const el = this.getElement(elementId);
117
+ return el.getLocation();
118
+ }
119
+
120
+ export async function getLocationInView(
121
+ this: FakeDriver,
122
+ elementId: string
123
+ ): Promise<Position> {
124
+ return this.getLocation(elementId);
125
+ }