@appium/fake-driver 4.2.2 → 5.0.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.
- package/build/lib/commands/alert.d.ts +345 -13
- package/build/lib/commands/alert.d.ts.map +1 -1
- package/build/lib/commands/alert.js +80 -53
- package/build/lib/commands/alert.js.map +1 -1
- package/build/lib/commands/contexts.d.ts +359 -14
- package/build/lib/commands/contexts.d.ts.map +1 -1
- package/build/lib/commands/contexts.js +102 -86
- package/build/lib/commands/contexts.js.map +1 -1
- package/build/lib/commands/element.d.ts +326 -22
- package/build/lib/commands/element.d.ts.map +1 -1
- package/build/lib/commands/element.js +108 -123
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/find.d.ts +338 -18
- package/build/lib/commands/find.d.ts.map +1 -1
- package/build/lib/commands/find.js +113 -107
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/general.d.ts +364 -28
- package/build/lib/commands/general.d.ts.map +1 -1
- package/build/lib/commands/general.js +97 -106
- package/build/lib/commands/general.js.map +1 -1
- package/build/lib/commands/index.d.ts +1598 -2
- package/build/lib/commands/index.d.ts.map +1 -1
- package/build/lib/commands/index.js +97 -18
- package/build/lib/commands/index.js.map +1 -1
- package/build/lib/driver.d.ts +117 -33
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +170 -145
- package/build/lib/driver.js.map +1 -1
- package/build/lib/fake-app.d.ts +15 -6
- package/build/lib/fake-app.d.ts.map +1 -1
- package/build/lib/fake-app.js +155 -194
- package/build/lib/fake-app.js.map +1 -1
- package/build/lib/fake-driver-schema.js +34 -26
- package/build/lib/fake-driver-schema.js.map +1 -1
- package/build/lib/fake-element.js +87 -121
- package/build/lib/fake-element.js.map +1 -1
- package/build/lib/index.d.ts +4 -5
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +15 -36
- package/build/lib/index.js.map +1 -1
- package/build/lib/logger.d.ts +1 -1
- package/build/lib/logger.d.ts.map +1 -1
- package/build/lib/logger.js +5 -15
- package/build/lib/logger.js.map +1 -1
- package/build/lib/scripts/fake-error.js +1 -5
- package/build/lib/scripts/fake-error.js.map +1 -1
- package/build/lib/scripts/fake-success.js +8 -11
- package/build/lib/scripts/fake-success.js.map +1 -1
- package/build/lib/server.d.ts +1 -1
- package/build/lib/server.d.ts.map +1 -1
- package/build/lib/server.js +18 -27
- package/build/lib/server.js.map +1 -1
- package/build/lib/types.d.ts +36 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/alert.js +74 -34
- package/lib/commands/contexts.js +90 -52
- package/lib/commands/element.js +111 -98
- package/lib/commands/find.js +101 -77
- package/lib/commands/general.js +106 -75
- package/lib/commands/index.js +13 -17
- package/lib/driver.js +103 -32
- package/lib/fake-app.js +20 -6
- package/lib/index.js +4 -7
- package/lib/types.ts +42 -0
- package/package.json +11 -11
package/lib/commands/general.js
CHANGED
|
@@ -1,82 +1,113 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
1
|
import {errors} from 'appium/driver';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
3
|
+
const ORIENTATIONS = new Set(['LANDSCAPE', 'PORTRAIT']);
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @template {Class<import('../types').IContextsCommands & import('../types').IElementCommands>} T
|
|
7
|
+
* @param {T} Base
|
|
8
|
+
*/
|
|
9
|
+
export function GeneralMixin(Base) {
|
|
10
|
+
/**
|
|
11
|
+
* @implements {IGeneralCommands}
|
|
12
|
+
*/
|
|
13
|
+
class GeneralCommands extends Base {
|
|
14
|
+
async title() {
|
|
15
|
+
this.assertWebviewContext();
|
|
16
|
+
return this.appModel.title;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async keys(value) {
|
|
20
|
+
if (!this.focusedElId) {
|
|
21
|
+
throw new errors.InvalidElementStateError();
|
|
22
|
+
}
|
|
23
|
+
await this.setValue(value, this.focusedElId);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async setGeoLocation(location) {
|
|
27
|
+
// TODO test this adequately once WD bug is fixed
|
|
28
|
+
this.appModel.lat = location.latitude;
|
|
29
|
+
this.appModel.long = location.longitude;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async getGeoLocation() {
|
|
33
|
+
return this.appModel.currentGeoLocation;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async getPageSource() {
|
|
37
|
+
return this.appModel.rawXml;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async getOrientation() {
|
|
41
|
+
return this.appModel.orientation;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {import('../types').FakeDriverCaps['orientation']} o
|
|
47
|
+
*/
|
|
48
|
+
async setOrientation(o) {
|
|
49
|
+
if (!ORIENTATIONS.has(o)) {
|
|
50
|
+
throw new errors.UnknownError('Orientation must be LANDSCAPE or PORTRAIT');
|
|
51
|
+
}
|
|
52
|
+
this.appModel.orientation = o;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async getScreenshot() {
|
|
56
|
+
return this.appModel.getScreenshot();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async getWindowSize() {
|
|
60
|
+
return {width: this.appModel.width, height: this.appModel.height};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async getWindowRect() {
|
|
64
|
+
return {width: this.appModel.width, height: this.appModel.height, x: 0, y: 0};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async performActions(actions) {
|
|
68
|
+
this.appModel.actionLog.push(actions);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async releaseActions() {}
|
|
72
|
+
|
|
73
|
+
async getLog(type) {
|
|
74
|
+
switch (type) {
|
|
75
|
+
case 'actions':
|
|
76
|
+
return this.appModel.actionLog;
|
|
77
|
+
default:
|
|
78
|
+
throw new Error(`Don't understand log type '${type}'`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async execute(script, args) {
|
|
83
|
+
return await this.executeMethod(script, args);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Add two or maybe even three numbers
|
|
88
|
+
*
|
|
89
|
+
* @param {number} num1
|
|
90
|
+
* @param {number} num2
|
|
91
|
+
* @param {number} [num3]
|
|
92
|
+
* @returns {Promise<number>}
|
|
93
|
+
*/
|
|
94
|
+
async fakeAddition(num1, num2, num3 = 0) {
|
|
95
|
+
return num1 + num2 + (num3 ?? 0);
|
|
96
|
+
}
|
|
41
97
|
}
|
|
42
|
-
this.appModel.orientation = o;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
commands.getScreenshot = async function getScreenshot() {
|
|
46
|
-
return this.appModel.getScreenshot();
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
commands.getWindowSize = async function getWindowSize() {
|
|
50
|
-
return {width: this.appModel.width, height: this.appModel.height};
|
|
51
|
-
};
|
|
52
98
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
commands.performActions = async function performActions(actions) {
|
|
58
|
-
this.appModel.actionLog.push(actions);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
commands.releaseActions = async function releaseActions() {};
|
|
62
|
-
|
|
63
|
-
commands.getLog = async function getLog(type) {
|
|
64
|
-
switch (type) {
|
|
65
|
-
case 'actions':
|
|
66
|
-
return this.appModel.actionLog;
|
|
67
|
-
default:
|
|
68
|
-
throw new Error(`Don't understand log type '${type}'`);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
99
|
+
return GeneralCommands;
|
|
100
|
+
}
|
|
71
101
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
102
|
+
/**
|
|
103
|
+
* @typedef {import('../driver').FakeDriverCore} FakeDriverCore
|
|
104
|
+
*/
|
|
75
105
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
106
|
+
/**
|
|
107
|
+
* @template T,[U={}],[V=Array<any>]
|
|
108
|
+
* @typedef {import('@appium/types').Class<T,U,V>} Class
|
|
109
|
+
*/
|
|
79
110
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
/**
|
|
112
|
+
* @typedef {import('../types').IGeneralCommands} IGeneralCommands
|
|
113
|
+
*/
|
package/lib/commands/index.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import {AlertMixin} from './alert';
|
|
2
|
+
import {ContextsMixin} from './contexts';
|
|
3
|
+
import {ElementMixin} from './element';
|
|
4
|
+
import {FindMixin} from './find';
|
|
5
|
+
import {GeneralMixin} from './general';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
alertCommands
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
export default commands;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {import('@appium/types').Class<import('../driver').FakeDriverCore>} Base
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export function FakeDriverMixin(Base) {
|
|
13
|
+
return GeneralMixin(FindMixin(ElementMixin(AlertMixin(ContextsMixin(Base)))));
|
|
14
|
+
}
|
|
19
15
|
|
|
20
16
|
/* // TODO:
|
|
21
17
|
//rest.post('/wd/hub/session/:sessionId?/touch/click', controller.doClick);
|
package/lib/driver.js
CHANGED
|
@@ -1,28 +1,42 @@
|
|
|
1
1
|
import B from 'bluebird';
|
|
2
|
-
import _ from 'lodash';
|
|
3
2
|
import {BaseDriver, errors} from 'appium/driver';
|
|
4
3
|
import {FakeApp} from './fake-app';
|
|
5
|
-
import
|
|
4
|
+
import {FakeDriverMixin} from './commands';
|
|
5
|
+
|
|
6
|
+
const FAKE_DRIVER_CONSTRAINTS = /** @type {const} */ ({
|
|
7
|
+
app: {
|
|
8
|
+
presence: true,
|
|
9
|
+
isString: true,
|
|
10
|
+
},
|
|
11
|
+
uniqueApp: {
|
|
12
|
+
isBoolean: true,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {typeof FAKE_DRIVER_CONSTRAINTS} FakeDriverConstraints
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @extends {BaseDriver<FakeDriverConstraints>}
|
|
22
|
+
* @implements {ExternalDriver<FakeDriverConstraints>}
|
|
23
|
+
*/
|
|
24
|
+
export class FakeDriverCore extends BaseDriver {
|
|
25
|
+
desiredCapConstraints = FAKE_DRIVER_CONSTRAINTS;
|
|
26
|
+
|
|
27
|
+
/** @type {string} */
|
|
28
|
+
curContext;
|
|
29
|
+
|
|
30
|
+
appModel = new FakeApp();
|
|
6
31
|
|
|
7
|
-
class FakeDriver extends BaseDriver {
|
|
8
32
|
constructor(opts = {}, shouldValidateCaps = true) {
|
|
9
33
|
super(opts, shouldValidateCaps);
|
|
10
|
-
this.appModel = null;
|
|
11
34
|
this.curContext = 'NATIVE_APP';
|
|
12
35
|
this.elMap = {};
|
|
13
36
|
this.focusedElId = null;
|
|
14
37
|
this.maxElId = 0;
|
|
15
|
-
this.caps = {};
|
|
16
38
|
this.fakeThing = null;
|
|
17
|
-
this.cliArgs = {};
|
|
18
39
|
this._proxyActive = false;
|
|
19
|
-
|
|
20
|
-
this.desiredCapConstraints = {
|
|
21
|
-
app: {
|
|
22
|
-
presence: true,
|
|
23
|
-
isString: true,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
40
|
}
|
|
27
41
|
|
|
28
42
|
proxyActive() {
|
|
@@ -42,10 +56,22 @@ class FakeDriver extends BaseDriver {
|
|
|
42
56
|
res.status(200).send(JSON.stringify(resBodyObj));
|
|
43
57
|
}
|
|
44
58
|
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
/**
|
|
60
|
+
* @template [T=any]
|
|
61
|
+
* @returns {Promise<T>}
|
|
62
|
+
*/
|
|
63
|
+
async proxyCommand(/*url, method, body*/) {
|
|
64
|
+
return /** @type {T} */ (/** @type {unknown} */ ('proxied via proxyCommand'));
|
|
47
65
|
}
|
|
48
66
|
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @param {W3CFakeDriverCaps} jsonwpDesiredCapabilities
|
|
70
|
+
* @param {W3CFakeDriverCaps} [jsonwpRequiredCaps]
|
|
71
|
+
* @param {W3CFakeDriverCaps} [w3cCapabilities]
|
|
72
|
+
* @param {import('@appium/types').DriverData[]} [otherSessionData]
|
|
73
|
+
* @returns {Promise<[string,FakeDriverCaps]>}
|
|
74
|
+
*/
|
|
49
75
|
async createSession(
|
|
50
76
|
jsonwpDesiredCapabilities,
|
|
51
77
|
jsonwpRequiredCaps,
|
|
@@ -66,16 +92,14 @@ class FakeDriver extends BaseDriver {
|
|
|
66
92
|
}
|
|
67
93
|
}
|
|
68
94
|
|
|
69
|
-
let [sessionId, caps] =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
95
|
+
let [sessionId, caps] = /** @type {[string, FakeDriverCaps]} */ (
|
|
96
|
+
await super.createSession(
|
|
97
|
+
jsonwpDesiredCapabilities,
|
|
98
|
+
jsonwpRequiredCaps,
|
|
99
|
+
w3cCapabilities,
|
|
100
|
+
otherSessionData
|
|
101
|
+
)
|
|
74
102
|
);
|
|
75
|
-
this.appModel = new FakeApp();
|
|
76
|
-
if (_.isArray(caps) === true && caps.length === 1) {
|
|
77
|
-
caps = caps[0];
|
|
78
|
-
}
|
|
79
103
|
this.caps = caps;
|
|
80
104
|
await this.appModel.loadApp(caps.app);
|
|
81
105
|
return [sessionId, caps];
|
|
@@ -92,32 +116,49 @@ class FakeDriver extends BaseDriver {
|
|
|
92
116
|
return this.fakeThing;
|
|
93
117
|
}
|
|
94
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Set the 'thing' value (so that it can be retrieved later)
|
|
121
|
+
*
|
|
122
|
+
* @param {any} thing
|
|
123
|
+
* @returns {Promise<null>}
|
|
124
|
+
*/
|
|
95
125
|
async setFakeThing(thing) {
|
|
96
126
|
await B.delay(1);
|
|
97
127
|
this.fakeThing = thing;
|
|
98
128
|
return null;
|
|
99
129
|
}
|
|
100
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Get the driver args that were sent in via the CLI
|
|
133
|
+
*
|
|
134
|
+
* @returns {Promise<typeof this.cliArgs>}
|
|
135
|
+
*/
|
|
101
136
|
async getFakeDriverArgs() {
|
|
102
137
|
await B.delay(1);
|
|
103
138
|
return this.cliArgs;
|
|
104
139
|
}
|
|
105
140
|
|
|
106
|
-
static newMethodMap = {
|
|
141
|
+
static newMethodMap = /** @type {const} */ ({
|
|
107
142
|
'/session/:sessionId/fakedriver': {
|
|
108
143
|
GET: {command: 'getFakeThing'},
|
|
144
|
+
/**
|
|
145
|
+
* Sets a fake thing
|
|
146
|
+
*/
|
|
109
147
|
POST: {command: 'setFakeThing', payloadParams: {required: ['thing']}},
|
|
110
148
|
},
|
|
111
149
|
'/session/:sessionId/fakedriverargs': {
|
|
112
150
|
GET: {command: 'getFakeDriverArgs'},
|
|
113
151
|
},
|
|
114
|
-
};
|
|
152
|
+
});
|
|
115
153
|
|
|
116
|
-
static executeMethodMap = {
|
|
154
|
+
static executeMethodMap = /** @type {const} */ ({
|
|
117
155
|
'fake: addition': {
|
|
118
156
|
command: 'fakeAddition',
|
|
119
157
|
params: {required: ['num1', 'num2'], optional: ['num3']},
|
|
120
158
|
},
|
|
159
|
+
/**
|
|
160
|
+
* Gets a thing (a fake thing)
|
|
161
|
+
*/
|
|
121
162
|
'fake: getThing': {
|
|
122
163
|
command: 'getFakeThing',
|
|
123
164
|
},
|
|
@@ -125,7 +166,20 @@ class FakeDriver extends BaseDriver {
|
|
|
125
166
|
command: 'setFakeThing',
|
|
126
167
|
params: {required: ['thing']},
|
|
127
168
|
},
|
|
128
|
-
};
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Add two or maybe even three numbers
|
|
173
|
+
*
|
|
174
|
+
* @param {number} num1
|
|
175
|
+
* @param {number} num2
|
|
176
|
+
* @param {number} [num3]
|
|
177
|
+
* @returns {Promise<number>}
|
|
178
|
+
*/
|
|
179
|
+
// eslint-disable-next-line no-unused-vars
|
|
180
|
+
async fakeAddition(num1, num2, num3 = 0) {
|
|
181
|
+
throw new errors.NotImplementedError();
|
|
182
|
+
}
|
|
129
183
|
|
|
130
184
|
static fakeRoute(req, res) {
|
|
131
185
|
res.send(JSON.stringify({fakedriver: 'fakeResponse'}));
|
|
@@ -133,13 +187,30 @@ class FakeDriver extends BaseDriver {
|
|
|
133
187
|
|
|
134
188
|
static async updateServer(expressApp, httpServer, cliArgs) {
|
|
135
189
|
// eslint-disable-line require-await
|
|
136
|
-
expressApp.all('/fakedriver',
|
|
190
|
+
expressApp.all('/fakedriver', FakeDriverCore.fakeRoute);
|
|
137
191
|
expressApp.all('/fakedriverCliArgs', (req, res) => {
|
|
138
192
|
res.send(JSON.stringify(cliArgs));
|
|
139
193
|
});
|
|
140
194
|
}
|
|
141
195
|
}
|
|
142
196
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
197
|
+
/**
|
|
198
|
+
* @extends FakeDriverCore
|
|
199
|
+
*/
|
|
200
|
+
export class FakeDriver extends FakeDriverMixin(FakeDriverCore) {}
|
|
201
|
+
export default FakeDriver;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @typedef {import('./types').FakeDriverCaps} FakeDriverCaps
|
|
205
|
+
* @typedef {import('./types').W3CFakeDriverCaps} W3CFakeDriverCaps
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @template {import('@appium/types').Driver} D
|
|
210
|
+
* @typedef {import('@appium/types').DriverClass<D>} DriverClass
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* @template {import('@appium/types').Constraints} C
|
|
215
|
+
* @typedef {import('@appium/types').ExternalDriver<C>} ExternalDriver
|
|
216
|
+
*/
|
package/lib/fake-app.js
CHANGED
|
@@ -29,9 +29,13 @@ class FakeApp {
|
|
|
29
29
|
if (nodes.length < 1) {
|
|
30
30
|
throw new Error('No title!');
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
const node = /** @type {Node} */ (nodes[0]);
|
|
33
|
+
return /** @type {ElementWithData} */ (node.firstChild).data;
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @type {import('@appium/types').Location}
|
|
38
|
+
*/
|
|
35
39
|
get currentGeoLocation() {
|
|
36
40
|
return {
|
|
37
41
|
latitude: this.lat,
|
|
@@ -47,18 +51,24 @@ class FakeApp {
|
|
|
47
51
|
this.currentOrientation = o;
|
|
48
52
|
}
|
|
49
53
|
|
|
54
|
+
/**
|
|
55
|
+
* @type {number}
|
|
56
|
+
*/
|
|
50
57
|
get width() {
|
|
51
58
|
if (this._width === null) {
|
|
52
59
|
this.setDims();
|
|
53
60
|
}
|
|
54
|
-
return this._width;
|
|
61
|
+
return /** @type {number} */ (this._width);
|
|
55
62
|
}
|
|
56
63
|
|
|
64
|
+
/**
|
|
65
|
+
* @type {number}
|
|
66
|
+
*/
|
|
57
67
|
get height() {
|
|
58
68
|
if (this._width === null) {
|
|
59
69
|
this.setDims();
|
|
60
70
|
}
|
|
61
|
-
return this._width;
|
|
71
|
+
return /** @type {number} */ (this._width);
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
setDims() {
|
|
@@ -133,10 +143,10 @@ class FakeApp {
|
|
|
133
143
|
}
|
|
134
144
|
|
|
135
145
|
setAlertText(text) {
|
|
136
|
-
if (!this.activeAlert
|
|
146
|
+
if (!this.activeAlert?.hasPrompt()) {
|
|
137
147
|
throw new Error('No prompt to set text of');
|
|
138
148
|
}
|
|
139
|
-
this.activeAlert
|
|
149
|
+
this.activeAlert?.setAttr('prompt', text);
|
|
140
150
|
}
|
|
141
151
|
|
|
142
152
|
showAlert(alertId) {
|
|
@@ -148,7 +158,7 @@ class FakeApp {
|
|
|
148
158
|
}
|
|
149
159
|
|
|
150
160
|
alertText() {
|
|
151
|
-
return this.activeAlert
|
|
161
|
+
return this.activeAlert?.getAttr('prompt') || this.activeAlert?.nodeAttrs.text;
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
handleAlert() {
|
|
@@ -167,3 +177,7 @@ class FakeWebView {
|
|
|
167
177
|
}
|
|
168
178
|
|
|
169
179
|
export {FakeApp};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @typedef {Element & {data: any}} ElementWithData
|
|
183
|
+
*/
|
package/lib/index.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
const {FakeDriver} = driver;
|
|
5
|
-
const {startServer} = server;
|
|
1
|
+
import {FakeDriver} from './driver';
|
|
2
|
+
import {startServer} from './server';
|
|
6
3
|
|
|
7
4
|
const DEFAULT_HOST = 'localhost';
|
|
8
5
|
const DEFAULT_PORT = 4774;
|
|
9
6
|
|
|
10
7
|
async function main() {
|
|
11
|
-
const getArgValue = (argName) => {
|
|
8
|
+
const getArgValue = (/** @type {string} */ argName) => {
|
|
12
9
|
const argIndex = process.argv.indexOf(argName);
|
|
13
10
|
return argIndex > 0 ? process.argv[argIndex + 1] : null;
|
|
14
11
|
};
|
|
15
|
-
const port = parseInt(getArgValue('--port'), 10) || DEFAULT_PORT;
|
|
12
|
+
const port = parseInt(String(getArgValue('--port')), 10) || DEFAULT_PORT;
|
|
16
13
|
const host = getArgValue('--host') || DEFAULT_HOST;
|
|
17
14
|
return await startServer(port, host);
|
|
18
15
|
}
|
package/lib/types.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {DriverCaps, ExternalDriver, W3CDriverCaps} from '@appium/types';
|
|
2
|
+
import type {FakeDriverConstraints} from './driver';
|
|
3
|
+
import {FakeApp} from './fake-app';
|
|
4
|
+
import {FakeElement} from './fake-element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* W3C-style caps for {@link FakeDriver}
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type W3CFakeDriverCaps = W3CDriverCaps<FakeDriverConstraints>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Capabilities for {@link FakeDriver}
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type FakeDriverCaps = DriverCaps<FakeDriverConstraints>;
|
|
17
|
+
|
|
18
|
+
export interface IFakeDriver extends ExternalDriver<FakeDriverConstraints> {
|
|
19
|
+
elMap: Record<string, FakeElement>;
|
|
20
|
+
maxElId: number;
|
|
21
|
+
appModel: FakeApp;
|
|
22
|
+
focusedElId: string;
|
|
23
|
+
curContext: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface IGeneralCommands extends IFakeDriver {
|
|
27
|
+
fakeAddition(num1: number, num2: number, num3?: number): Promise<number>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface IContextsCommands extends IFakeDriver {
|
|
31
|
+
assertWebviewContext(): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface IElementCommands extends IFakeDriver {
|
|
35
|
+
getElement(id: string): FakeElement;
|
|
36
|
+
getElements(ids: string[]): FakeElement[];
|
|
37
|
+
setValue(text: string, id: string): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface IAlertCommands extends IFakeDriver {
|
|
41
|
+
assertNoAlert(): void;
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/fake-driver",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Mock driver used internally by Appium for testing. Ignore",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -36,20 +36,17 @@
|
|
|
36
36
|
"test/fixtures"
|
|
37
37
|
],
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build": "
|
|
40
|
-
"
|
|
41
|
-
"fix": "npm run lint -- --fix",
|
|
42
|
-
"lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore .",
|
|
43
|
-
"prepare": "npm run build",
|
|
39
|
+
"build": "cpy lib/screen.png build",
|
|
40
|
+
"clean": "npx rimraf build/lib/screen.png",
|
|
44
41
|
"test": "npm run test:unit",
|
|
45
42
|
"test:e2e": "mocha --timeout 20s --slow 10s \"./test/e2e/**/*.spec.js\"",
|
|
46
43
|
"test:smoke": "node ./build/lib/index.js",
|
|
47
44
|
"test:unit": "mocha \"./test/unit/**/*.spec.js\""
|
|
48
45
|
},
|
|
49
46
|
"dependencies": {
|
|
50
|
-
"@types/bluebird": "3.5.
|
|
51
|
-
"@xmldom/xmldom": "0.8.
|
|
52
|
-
"asyncbox": "2.9.
|
|
47
|
+
"@types/bluebird": "3.5.38",
|
|
48
|
+
"@xmldom/xmldom": "0.8.6",
|
|
49
|
+
"asyncbox": "2.9.4",
|
|
53
50
|
"bluebird": "3.7.2",
|
|
54
51
|
"lodash": "4.17.21",
|
|
55
52
|
"source-map-support": "0.5.21",
|
|
@@ -59,7 +56,7 @@
|
|
|
59
56
|
"appium": "^2.0.0-beta.35"
|
|
60
57
|
},
|
|
61
58
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
59
|
+
"node": "^14.17.0 || ^16.13.0 || >=18.0.0",
|
|
63
60
|
"npm": ">=8"
|
|
64
61
|
},
|
|
65
62
|
"publishConfig": {
|
|
@@ -79,6 +76,9 @@
|
|
|
79
76
|
"fake-success": "./build/lib/scripts/fake-success.js"
|
|
80
77
|
}
|
|
81
78
|
},
|
|
79
|
+
"typedoc": {
|
|
80
|
+
"entryPoint": "./build/lib/index.js"
|
|
81
|
+
},
|
|
82
82
|
"types": "./build/lib/index.d.ts",
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "0823f0b60e40395cd1dc3b72cfa3c0092bc81302"
|
|
84
84
|
}
|