@appium/fake-driver 3.2.12 → 4.0.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/lib/fake-app.js CHANGED
@@ -1,15 +1,15 @@
1
- import { fs } from '@appium/support';
2
- import { readFileSync } from 'fs';
1
+ import {fs} from 'appium/support';
2
+ import {readFileSync} from 'fs';
3
3
  import path from 'path';
4
4
  import XMLDom from '@xmldom/xmldom';
5
5
  import xpath from 'xpath';
6
6
  import log from './logger';
7
- import { FakeElement } from './fake-element';
7
+ import {FakeElement} from './fake-element';
8
8
 
9
9
  const SCREENSHOT = path.join(__dirname, 'screen.png');
10
10
 
11
11
  class FakeApp {
12
- constructor () {
12
+ constructor() {
13
13
  this.dom = null;
14
14
  this.activeDom = null;
15
15
  this.activeWebview = null;
@@ -24,7 +24,7 @@ class FakeApp {
24
24
  this.actionLog = [];
25
25
  }
26
26
 
27
- get title () {
27
+ get title() {
28
28
  let nodes = this.xpathQuery('//title');
29
29
  if (nodes.length < 1) {
30
30
  throw new Error('No title!');
@@ -32,43 +32,43 @@ class FakeApp {
32
32
  return nodes[0].firstChild.data;
33
33
  }
34
34
 
35
- get currentGeoLocation () {
35
+ get currentGeoLocation() {
36
36
  return {
37
37
  latitude: this.lat,
38
- longitude: this.long
38
+ longitude: this.long,
39
39
  };
40
40
  }
41
41
 
42
- get orientation () {
42
+ get orientation() {
43
43
  return this.currentOrientation;
44
44
  }
45
45
 
46
- set orientation (o) {
46
+ set orientation(o) {
47
47
  this.currentOrientation = o;
48
48
  }
49
49
 
50
- get width () {
50
+ get width() {
51
51
  if (this._width === null) {
52
52
  this.setDims();
53
53
  }
54
54
  return this._width;
55
55
  }
56
56
 
57
- get height () {
57
+ get height() {
58
58
  if (this._width === null) {
59
59
  this.setDims();
60
60
  }
61
61
  return this._width;
62
62
  }
63
63
 
64
- setDims () {
64
+ setDims() {
65
65
  const nodes = this.xpathQuery('//app');
66
66
  const app = new FakeElement(nodes[0], this);
67
67
  this._width = parseInt(app.nodeAttrs.width, 10);
68
68
  this._height = parseInt(app.nodeAttrs.height, 10);
69
69
  }
70
70
 
71
- async loadApp (appPath) {
71
+ async loadApp(appPath) {
72
72
  log.info(`Loading Mock app model at ${appPath}`);
73
73
  let data = await fs.readFile(appPath);
74
74
  log.info('Parsing Mock app XML');
@@ -80,47 +80,45 @@ class FakeApp {
80
80
  this.activeDom = this.dom;
81
81
  }
82
82
 
83
- getWebviews () {
83
+ getWebviews() {
84
84
  return this.xpathQuery('//MockWebView/*[1]').map((n) => new FakeWebView(n));
85
85
  }
86
86
 
87
- activateWebview (wv) {
87
+ activateWebview(wv) {
88
88
  this.activeWebview = wv;
89
89
  let fragment = new XMLDom.XMLSerializer().serializeToString(wv.node);
90
- this.activeDom = new XMLDom.DOMParser().parseFromString(fragment,
91
- 'application/xml');
90
+ this.activeDom = new XMLDom.DOMParser().parseFromString(fragment, 'application/xml');
92
91
  }
93
92
 
94
- deactivateWebview () {
93
+ deactivateWebview() {
95
94
  this.activeWebview = null;
96
95
  this.activeDom = this.dom;
97
96
  }
98
97
 
99
- activateFrame (frame) {
98
+ activateFrame(frame) {
100
99
  this.activeFrame = frame;
101
100
  let fragment = new XMLDom.XMLSerializer().serializeToString(frame);
102
- this.activeDom = new XMLDom.DOMParser().parseFromString(fragment,
103
- 'application/xml');
101
+ this.activeDom = new XMLDom.DOMParser().parseFromString(fragment, 'application/xml');
104
102
  }
105
103
 
106
- deactivateFrame () {
104
+ deactivateFrame() {
107
105
  this.activeFrame = null;
108
106
  this.activateWebview(this.activeWebview);
109
107
  }
110
108
 
111
- xpathQuery (sel, ctx) {
109
+ xpathQuery(sel, ctx) {
112
110
  return xpath.select(sel, ctx || this.activeDom);
113
111
  }
114
112
 
115
- idQuery (id, ctx) {
113
+ idQuery(id, ctx) {
116
114
  return this.xpathQuery(`//*[@id="${id}"]`, ctx);
117
115
  }
118
116
 
119
- classQuery (className, ctx) {
117
+ classQuery(className, ctx) {
120
118
  return this.xpathQuery(`//${className}`, ctx);
121
119
  }
122
120
 
123
- cssQuery (css, ctx) {
121
+ cssQuery(css, ctx) {
124
122
  if (css.startsWith('#')) {
125
123
  return this.idQuery(css.slice(1), ctx);
126
124
  }
@@ -130,18 +128,18 @@ class FakeApp {
130
128
  return this.classQuery(css, ctx);
131
129
  }
132
130
 
133
- hasAlert () {
131
+ hasAlert() {
134
132
  return this.activeAlert !== null;
135
133
  }
136
134
 
137
- setAlertText (text) {
135
+ setAlertText(text) {
138
136
  if (!this.activeAlert.hasPrompt()) {
139
137
  throw new Error('No prompt to set text of');
140
138
  }
141
139
  this.activeAlert.setAttr('prompt', text);
142
140
  }
143
141
 
144
- showAlert (alertId) {
142
+ showAlert(alertId) {
145
143
  let nodes = this.xpathQuery(`//alert[@id="${alertId}"]`);
146
144
  if (nodes.length < 1) {
147
145
  throw new Error(`Alert ${alertId} doesn't exist!`);
@@ -149,25 +147,23 @@ class FakeApp {
149
147
  this.activeAlert = new FakeElement(nodes[0], this);
150
148
  }
151
149
 
152
- alertText () {
153
- return this.activeAlert.getAttr('prompt') ||
154
- this.activeAlert.nodeAttrs.text;
150
+ alertText() {
151
+ return this.activeAlert.getAttr('prompt') || this.activeAlert.nodeAttrs.text;
155
152
  }
156
153
 
157
- handleAlert () {
154
+ handleAlert() {
158
155
  this.activeAlert = null;
159
156
  }
160
157
 
161
- getScreenshot () {
158
+ getScreenshot() {
162
159
  return readFileSync(SCREENSHOT, 'base64');
163
160
  }
164
-
165
161
  }
166
162
 
167
163
  class FakeWebView {
168
- constructor (node) {
164
+ constructor(node) {
169
165
  this.node = node;
170
166
  }
171
167
  }
172
168
 
173
- export { FakeApp };
169
+ export {FakeApp};
@@ -14,7 +14,6 @@
14
14
  // }
15
15
  // }
16
16
 
17
-
18
17
  export default {
19
18
  type: 'object',
20
19
  title: 'Fake Driver Configuration',
@@ -30,7 +29,7 @@ export default {
30
29
  sillyWebServerHost: {
31
30
  type: 'string',
32
31
  description: 'The host to use for the fake web server',
33
- default: 'sillyhost'
34
- }
35
- }
32
+ default: 'sillyhost',
33
+ },
34
+ },
36
35
  };
@@ -2,7 +2,7 @@ import _ from 'lodash';
2
2
  import XMLDom from '@xmldom/xmldom';
3
3
 
4
4
  class FakeElement {
5
- constructor (xmlNode, app) {
5
+ constructor(xmlNode, app) {
6
6
  this.app = app;
7
7
  this.node = xmlNode;
8
8
  this.nodeAttrs = {};
@@ -15,7 +15,7 @@ class FakeElement {
15
15
  this.parseCss();
16
16
  }
17
17
 
18
- parseCss () {
18
+ parseCss() {
19
19
  if (this.nodeAttrs.style) {
20
20
  let segments = this.nodeAttrs.style.split(';');
21
21
  for (let s of segments) {
@@ -27,49 +27,49 @@ class FakeElement {
27
27
  }
28
28
  }
29
29
 
30
- get tagName () {
30
+ get tagName() {
31
31
  return this.node.tagName;
32
32
  }
33
33
 
34
- setAttr (k, v) {
34
+ setAttr(k, v) {
35
35
  this.attrs[k] = v;
36
36
  }
37
37
 
38
- getAttr (k) {
38
+ getAttr(k) {
39
39
  return this.attrs[k] || '';
40
40
  }
41
41
 
42
- isVisible () {
42
+ isVisible() {
43
43
  return this.nodeAttrs.visible !== 'false';
44
44
  }
45
45
 
46
- isEnabled () {
46
+ isEnabled() {
47
47
  return this.nodeAttrs.enabled !== 'false';
48
48
  }
49
49
 
50
- isSelected () {
50
+ isSelected() {
51
51
  return this.nodeAttrs.selected === 'true';
52
52
  }
53
53
 
54
- getLocation () {
54
+ getLocation() {
55
55
  return {
56
56
  x: parseFloat(this.nodeAttrs.left || 0),
57
- y: parseFloat(this.nodeAttrs.top || 0)
57
+ y: parseFloat(this.nodeAttrs.top || 0),
58
58
  };
59
59
  }
60
60
 
61
- getElementRect () {
61
+ getElementRect() {
62
62
  return {...this.getLocation(), ...this.getSize()};
63
63
  }
64
64
 
65
- getSize () {
65
+ getSize() {
66
66
  return {
67
67
  width: parseFloat(this.nodeAttrs.width || 0),
68
- height: parseFloat(this.nodeAttrs.height || 0)
68
+ height: parseFloat(this.nodeAttrs.height || 0),
69
69
  };
70
70
  }
71
71
 
72
- click () {
72
+ click() {
73
73
  let curClicks = this.getAttr('clicks') || 0;
74
74
  this.setAttr('clicks', curClicks + 1);
75
75
  let alertId = this.nodeAttrs.showAlert;
@@ -78,26 +78,25 @@ class FakeElement {
78
78
  }
79
79
  }
80
80
 
81
- equals (other) {
81
+ equals(other) {
82
82
  return this.node === other.node;
83
83
  }
84
84
 
85
- hasPrompt () {
85
+ hasPrompt() {
86
86
  return this.nodeAttrs.hasPrompt === 'true';
87
87
  }
88
88
 
89
- getCss (prop) {
89
+ getCss(prop) {
90
90
  if (_.has(this.css, prop)) {
91
91
  return this.css[prop];
92
92
  }
93
93
  return null;
94
94
  }
95
95
 
96
- get xmlFragment () {
96
+ get xmlFragment() {
97
97
  let frag = new XMLDom.XMLSerializer().serializeToString(this.node);
98
98
  return new XMLDom.DOMParser().parseFromString(frag, 'application/xml');
99
99
  }
100
-
101
100
  }
102
101
 
103
- export { FakeElement };
102
+ export {FakeElement};
package/lib/index.js CHANGED
@@ -3,13 +3,13 @@
3
3
  import * as driver from './driver';
4
4
  import * as server from './server';
5
5
 
6
- const { FakeDriver } = driver;
7
- const { startServer } = server;
6
+ const {FakeDriver} = driver;
7
+ const {startServer} = server;
8
8
 
9
9
  const DEFAULT_HOST = 'localhost';
10
10
  const DEFAULT_PORT = 4774;
11
11
 
12
- async function main () {
12
+ async function main() {
13
13
  const getArgValue = (argName) => {
14
14
  const argIndex = process.argv.indexOf(argName);
15
15
  return argIndex > 0 ? process.argv[argIndex + 1] : null;
@@ -19,4 +19,4 @@ async function main () {
19
19
  return await startServer(port, host);
20
20
  }
21
21
 
22
- export { FakeDriver, startServer, main };
22
+ export {FakeDriver, startServer, main};
package/lib/logger.js CHANGED
@@ -1,5 +1,4 @@
1
- import { logger } from '@appium/support';
2
-
1
+ import {logger} from 'appium/support';
3
2
 
4
3
  const log = logger.getLogger('FakeDriver');
5
4
 
package/lib/server.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import log from './logger';
2
- import { server as baseServer, routeConfiguringFunction } from '@appium/base-driver';
3
- import { FakeDriver } from './driver';
2
+ import {server as baseServer, routeConfiguringFunction} from 'appium/driver';
3
+ import {FakeDriver} from './driver';
4
4
 
5
-
6
- async function startServer (port, hostname) {
5
+ async function startServer(port, hostname) {
7
6
  const d = new FakeDriver();
8
7
  const server = await baseServer({
9
8
  routeConfiguringFunction: routeConfiguringFunction(d),
@@ -14,4 +13,4 @@ async function startServer (port, hostname) {
14
13
  return server;
15
14
  }
16
15
 
17
- export { startServer };
16
+ export {startServer};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/fake-driver",
3
- "version": "3.2.12",
3
+ "version": "4.0.1",
4
4
  "description": "Mock driver used internally by Appium for testing. Ignore",
5
5
  "keywords": [
6
6
  "automation",
@@ -40,14 +40,13 @@
40
40
  "dev": "npm run build -- --watch",
41
41
  "fix": "npm run lint -- --fix",
42
42
  "lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore .",
43
+ "prepare": "npm run build",
43
44
  "test": "npm run test:unit",
44
45
  "test:e2e": "mocha --timeout 20s --slow 10s \"./test/e2e/**/*.spec.js\"",
45
46
  "test:unit": "mocha \"./test/unit/**/*.spec.js\""
46
47
  },
47
48
  "dependencies": {
48
- "@appium/base-driver": "^8.5.2",
49
- "@appium/support": "^2.57.4",
50
- "@babel/runtime": "7.17.9",
49
+ "@babel/runtime": "7.18.3",
51
50
  "@xmldom/xmldom": "0.8.2",
52
51
  "asyncbox": "2.9.2",
53
52
  "bluebird": "3.7.2",
@@ -55,8 +54,11 @@
55
54
  "source-map-support": "0.5.21",
56
55
  "xpath": "0.0.32"
57
56
  },
57
+ "peerDependencies": {
58
+ "appium": "^2.0.0-beta.35"
59
+ },
58
60
  "engines": {
59
- "node": ">=12",
61
+ "node": ">=14",
60
62
  "npm": ">=6"
61
63
  },
62
64
  "publishConfig": {
@@ -76,5 +78,5 @@
76
78
  "fake-success": "./build/lib/scripts/fake-success.js"
77
79
  }
78
80
  },
79
- "gitHead": "f15f11bc14d777185ed908a7840657b089cb1049"
81
+ "gitHead": "62b97417fcb7b0c0e2d6bab30bf9406e09bfb2ed"
80
82
  }