@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
@@ -0,0 +1,128 @@
1
+ import _ from 'lodash';
2
+ import XMLDom from '@xmldom/xmldom';
3
+ import type {Document as XMLDocument, Node as XMLNode} from '@xmldom/xmldom';
4
+ import type {FakeApp} from './fake-app';
5
+
6
+ export interface XmlNodeLike {
7
+ tagName: string;
8
+ attributes: {name: string; value: string}[];
9
+ }
10
+
11
+ /** Wrapper around an XML node from the fake app DOM; supports attrs, css, visibility, click, alerts. */
12
+ export class FakeElement {
13
+ readonly app: FakeApp;
14
+ readonly type: string;
15
+ readonly nodeAttrs: Record<string, string>;
16
+ readonly node: XmlNodeLike;
17
+ attrs: Record<string, string>;
18
+ css: Record<string, string>;
19
+
20
+ constructor(xmlNode: XmlNodeLike, app: FakeApp) {
21
+ this.app = app;
22
+ this.node = xmlNode;
23
+ this.nodeAttrs = {};
24
+ this.type = xmlNode.tagName;
25
+ this.attrs = {};
26
+ this.css = {};
27
+ // Support both DOM Attr (name/value) and nodeName/nodeValue (e.g. @xmldom/xmldom).
28
+ const attrs = this.node.attributes as unknown as Array<{
29
+ name?: string; nodeName?: string; value?: string; nodeValue?: string
30
+ }>;
31
+ for (const attr of _.values(attrs)) {
32
+ const name = attr.name ?? attr.nodeName ?? '';
33
+ const value = attr.value ?? attr.nodeValue ?? '';
34
+ if (name) {
35
+ this.nodeAttrs[name] = value;
36
+ }
37
+ }
38
+ this.parseCss();
39
+ }
40
+
41
+ private parseCss(): void {
42
+ if (this.nodeAttrs.style) {
43
+ const segments = this.nodeAttrs.style.split(';');
44
+ for (const s of segments) {
45
+ let [prop, val] = s.split(':');
46
+ prop = prop.trim();
47
+ val = val.trim();
48
+ this.css[prop] = val;
49
+ }
50
+ }
51
+ }
52
+
53
+ get tagName(): string {
54
+ return this.node.tagName;
55
+ }
56
+
57
+ setAttr(k: string, v: string): void {
58
+ this.attrs[k] = v;
59
+ }
60
+
61
+ getAttr(k: string): string {
62
+ return this.attrs[k] || '';
63
+ }
64
+
65
+ isVisible(): boolean {
66
+ return this.nodeAttrs.visible !== 'false';
67
+ }
68
+
69
+ isEnabled(): boolean {
70
+ return this.nodeAttrs.enabled !== 'false';
71
+ }
72
+
73
+ isSelected(): boolean {
74
+ return this.nodeAttrs.selected === 'true';
75
+ }
76
+
77
+ getLocation(): {x: number; y: number} {
78
+ return {
79
+ x: parseFloat(this.nodeAttrs.left || '0'),
80
+ y: parseFloat(this.nodeAttrs.top || '0'),
81
+ };
82
+ }
83
+
84
+ getElementRect(): {x: number; y: number; width: number; height: number} {
85
+ return {...this.getLocation(), ...this.getSize()};
86
+ }
87
+
88
+ getSize(): {width: number; height: number} {
89
+ return {
90
+ width: parseFloat(this.nodeAttrs.width || '0'),
91
+ height: parseFloat(this.nodeAttrs.height || '0'),
92
+ };
93
+ }
94
+
95
+ click(): void {
96
+ const curClicks = Number(this.getAttr('clicks') || 0);
97
+ this.setAttr('clicks', String(curClicks + 1));
98
+ const alertId = this.nodeAttrs.showAlert;
99
+ if (alertId) {
100
+ this.app.showAlert(alertId);
101
+ }
102
+ }
103
+
104
+ equals(other: FakeElement): boolean {
105
+ return this.node === other.node;
106
+ }
107
+
108
+ hasPrompt(): boolean {
109
+ return this.nodeAttrs.hasPrompt === 'true';
110
+ }
111
+
112
+ getCss(prop: string): string | null {
113
+ if (_.has(this.css, prop)) {
114
+ return this.css[prop];
115
+ }
116
+ return null;
117
+ }
118
+
119
+ get xmlFragment(): XMLDocument {
120
+ const frag = new XMLDom.XMLSerializer().serializeToString(
121
+ this.node as unknown as XMLNode
122
+ );
123
+ return new XMLDom.DOMParser().parseFromString(
124
+ frag,
125
+ XMLDom.MIME_TYPE.XML_TEXT
126
+ ) as XMLDocument;
127
+ }
128
+ }
@@ -4,19 +4,15 @@ import {startServer} from './server';
4
4
  const DEFAULT_HOST = 'localhost';
5
5
  const DEFAULT_PORT = 4774;
6
6
 
7
- async function main() {
8
- const getArgValue = (/** @type {string} */ argName) => {
7
+ export async function main() {
8
+ const getArgValue = (argName: string): string | null => {
9
9
  const argIndex = process.argv.indexOf(argName);
10
- return argIndex > 0 ? process.argv[argIndex + 1] : null;
10
+ return argIndex > 0 ? process.argv[argIndex + 1] ?? null : null;
11
11
  };
12
12
  const port = parseInt(String(getArgValue('--port')), 10) || DEFAULT_PORT;
13
13
  const host = getArgValue('--host') || DEFAULT_HOST;
14
14
  return await startServer(port, host);
15
15
  }
16
16
 
17
- export {FakeDriver, startServer, main};
18
-
19
- /**
20
- * @typedef {import('./types').W3CFakeDriverCaps} W3CFakeDriverCaps
21
- * @typedef {import('./types').FakeDriverCaps} FakeDriverCaps
22
- */
17
+ export {FakeDriver, startServer};
18
+ export type {FakeDriverCaps, W3CFakeDriverCaps} from './types';
package/lib/logger.ts ADDED
@@ -0,0 +1,3 @@
1
+ import {logger} from 'appium/support';
2
+
3
+ export const log = logger.getLogger('FakeDriver');
@@ -1,4 +1,4 @@
1
- import log from '../logger';
1
+ import {log} from '../logger';
2
2
 
3
3
  log.info('Successfully ran the script');
4
4
 
@@ -1,8 +1,9 @@
1
- import log from './logger';
1
+ import {log} from './logger';
2
2
  import {server as baseServer, routeConfiguringFunction} from 'appium/driver';
3
3
  import {FakeDriver} from './driver';
4
4
 
5
- async function startServer(port, hostname) {
5
+ /** Start HTTP server with FakeDriver and default WebDriver routes. */
6
+ export async function startServer(port: number, hostname: string) {
6
7
  const d = new FakeDriver();
7
8
  const server = await baseServer({
8
9
  routeConfiguringFunction: routeConfiguringFunction(d),
@@ -12,5 +13,3 @@ async function startServer(port, hostname) {
12
13
  log.info(`FakeDriver server listening on http://${hostname}:${port}`);
13
14
  return server;
14
15
  }
15
-
16
- export {startServer};
package/lib/types.ts CHANGED
@@ -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
  /**
5
5
  * W3C-style caps for {@link FakeDriver}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/fake-driver",
3
- "version": "6.0.2",
3
+ "version": "6.1.0",
4
4
  "description": "Mock driver used internally by Appium for testing. Ignore",
5
5
  "keywords": [
6
6
  "automation",
@@ -28,23 +28,20 @@
28
28
  },
29
29
  "files": [
30
30
  "lib",
31
- "build",
32
- "test/fixtures",
33
- "tsconfig.json",
34
- "!build/tsconfig.tsbuildinfo",
35
- "!build/test"
31
+ "build/lib",
32
+ "tsconfig.json"
36
33
  ],
37
34
  "scripts": {
38
35
  "build": "cpy lib/screen.png build",
39
36
  "clean": "npx rimraf build/lib/screen.png",
40
37
  "test": "npm run test:unit",
41
- "test:e2e": "mocha --exit --timeout 20s --slow 10s \"./test/e2e/**/*.spec.js\"",
38
+ "test:e2e": "mocha --exit --timeout 20s --slow 10s \"./test/e2e/**/*.spec.ts\"",
42
39
  "test:smoke": "node ./build/lib/index.js",
43
- "test:unit": "mocha --exit --timeout 10s --slow 5s \"./test/unit/**/*.spec.js\""
40
+ "test:unit": "mocha --exit --timeout 10s --slow 5s \"./test/unit/**/*.spec.ts\""
44
41
  },
45
42
  "dependencies": {
46
43
  "@xmldom/xmldom": "0.9.8",
47
- "bluebird": "3.7.2",
44
+ "asyncbox": "6.1.0",
48
45
  "lodash": "4.17.23",
49
46
  "xpath": "0.0.34"
50
47
  },
@@ -74,12 +71,12 @@
74
71
  },
75
72
  "doctor": {
76
73
  "checks": [
77
- "./doctor/fake1.js",
78
- "./doctor/fake2.js"
74
+ "./build/lib/doctor/fake1.js",
75
+ "./build/lib/doctor/fake2.js"
79
76
  ]
80
77
  }
81
78
  },
82
79
  "main": "./build/lib/index.js",
83
80
  "types": "./build/lib/index.d.ts",
84
- "gitHead": "f7b20335eab4022e5cbbb627ec86866a994444f8"
81
+ "gitHead": "980a121804ae006db879fb6860f627ac36174c15"
85
82
  }
package/tsconfig.json CHANGED
@@ -3,6 +3,7 @@
3
3
  "compilerOptions": {
4
4
  "outDir": "build",
5
5
  "checkJs": true,
6
+ "types": ["mocha", "chai", "chai-as-promised", "node"],
6
7
  "paths": {
7
8
  "@appium/types": ["../types"],
8
9
  "appium/support": ["../appium/support"],
@@ -10,7 +11,7 @@
10
11
  "@appium/driver-test-support": ["../driver-test-support"]
11
12
  }
12
13
  },
13
- "include": ["lib"],
14
+ "include": ["lib", "test"],
14
15
  "references": [
15
16
  {"path": "../types"},
16
17
  {"path": "../support"},
@@ -1,14 +0,0 @@
1
- /**
2
- * Export all of the "stuff" from these mixin files. The mixins themselves are not exported,
3
- * but any types/interfaces that they export (e.g., options objects for some command) are exported.
4
- *
5
- * Mixins must not use `Object.assign()` and are expected to use the `mixin` function in the sibling
6
- * `mixin` module.
7
- * @module
8
- */
9
- import './alert';
10
- import './contexts';
11
- import './element';
12
- import './find';
13
- import './general';
14
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/commands/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,SAAS,CAAC;AACjB,OAAO,YAAY,CAAC;AACpB,OAAO,WAAW,CAAC;AACnB,OAAO,QAAQ,CAAC;AAChB,OAAO,WAAW,CAAC"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- /**
3
- * Export all of the "stuff" from these mixin files. The mixins themselves are not exported,
4
- * but any types/interfaces that they export (e.g., options objects for some command) are exported.
5
- *
6
- * Mixins must not use `Object.assign()` and are expected to use the `mixin` function in the sibling
7
- * `mixin` module.
8
- * @module
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- require("./alert");
12
- require("./contexts");
13
- require("./element");
14
- require("./find");
15
- require("./general");
16
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/commands/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAEH,mBAAiB;AACjB,sBAAoB;AACpB,qBAAmB;AACnB,kBAAgB;AAChB,qBAAmB"}
@@ -1,11 +0,0 @@
1
- import { FakeDriver } from '../driver';
2
- /**
3
- * This function assigns a mixin `T` to the `FakeDriver` class' prototype.
4
- * While each mixin has its own interface which is (in isolation) unrelated to `FakeDriver`, the constraint
5
- * on this generic type `T` is that it must be a partial of `FakeDriver`'s interface. This enforces
6
- * that it does not conflict with the existing interface of `FakeDriver`. In that way, you can
7
- * think of it as a type guard.
8
- * @param mixin Mixin implementation
9
- */
10
- export declare function mixin<T extends Partial<FakeDriver>>(mixin: T): void;
11
- //# sourceMappingURL=mixin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mixin.d.ts","sourceRoot":"","sources":["../../../lib/commands/mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,WAAW,CAAC;AAErC;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAEnE"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mixin = mixin;
4
- const driver_1 = require("../driver");
5
- /**
6
- * This function assigns a mixin `T` to the `FakeDriver` class' prototype.
7
- * While each mixin has its own interface which is (in isolation) unrelated to `FakeDriver`, the constraint
8
- * on this generic type `T` is that it must be a partial of `FakeDriver`'s interface. This enforces
9
- * that it does not conflict with the existing interface of `FakeDriver`. In that way, you can
10
- * think of it as a type guard.
11
- * @param mixin Mixin implementation
12
- */
13
- function mixin(mixin) {
14
- Object.assign(driver_1.FakeDriver.prototype, mixin);
15
- }
16
- //# sourceMappingURL=mixin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mixin.js","sourceRoot":"","sources":["../../../lib/commands/mixin.ts"],"names":[],"mappings":";;AAUA,sBAEC;AAZD,sCAAqC;AAErC;;;;;;;GAOG;AACH,SAAgB,KAAK,CAAgC,KAAQ;IAC3D,MAAM,CAAC,MAAM,CAAC,mBAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC"}
@@ -1,14 +0,0 @@
1
- /**
2
- * Export all of the "stuff" from these mixin files. The mixins themselves are not exported,
3
- * but any types/interfaces that they export (e.g., options objects for some command) are exported.
4
- *
5
- * Mixins must not use `Object.assign()` and are expected to use the `mixin` function in the sibling
6
- * `mixin` module.
7
- * @module
8
- */
9
-
10
- import './alert';
11
- import './contexts';
12
- import './element';
13
- import './find';
14
- import './general';
@@ -1,13 +0,0 @@
1
- import {FakeDriver} from '../driver';
2
-
3
- /**
4
- * This function assigns a mixin `T` to the `FakeDriver` class' prototype.
5
- * While each mixin has its own interface which is (in isolation) unrelated to `FakeDriver`, the constraint
6
- * on this generic type `T` is that it must be a partial of `FakeDriver`'s interface. This enforces
7
- * that it does not conflict with the existing interface of `FakeDriver`. In that way, you can
8
- * think of it as a type guard.
9
- * @param mixin Mixin implementation
10
- */
11
- export function mixin<T extends Partial<FakeDriver>>(mixin: T): void {
12
- Object.assign(FakeDriver.prototype, mixin);
13
- }