@appium/fake-plugin 4.0.5 → 4.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.
- package/build/lib/index.d.ts +2 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +10 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/plugin.d.ts +36 -98
- package/build/lib/plugin.d.ts.map +1 -1
- package/build/lib/plugin.js +38 -63
- package/build/lib/plugin.js.map +1 -1
- package/build/lib/scripts/fake-error.d.ts.map +1 -1
- package/build/lib/scripts/fake-error.js +1 -1
- package/build/lib/scripts/fake-error.js.map +1 -1
- package/build/lib/scripts/fake-success.d.ts.map +1 -1
- package/build/lib/scripts/fake-success.js +2 -5
- package/build/lib/scripts/fake-success.js.map +1 -1
- package/lib/index.ts +6 -0
- package/lib/plugin.ts +222 -0
- package/lib/scripts/fake-error.ts +1 -0
- package/lib/scripts/fake-success.ts +2 -0
- package/package.json +16 -13
- package/tsconfig.json +3 -5
- package/build/lib/logger.d.ts +0 -3
- package/build/lib/logger.d.ts.map +0 -1
- package/build/lib/logger.js +0 -6
- package/build/lib/logger.js.map +0 -1
- package/index.js +0 -3
- package/lib/logger.js +0 -5
- package/lib/plugin.js +0 -204
- package/lib/scripts/fake-error.js +0 -1
- package/lib/scripts/fake-success.js +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FakePlugin = void 0;
|
|
4
|
+
var plugin_1 = require("./plugin");
|
|
5
|
+
Object.defineProperty(exports, "FakePlugin", { enumerable: true, get: function () { return plugin_1.FakePlugin; } });
|
|
6
|
+
// Handle smoke test flag
|
|
7
|
+
if (require.main === module && process.argv[2] === '--smoke-test') {
|
|
8
|
+
process.exit(0);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAA5B,oGAAA,UAAU,OAAA;AAElB,yBAAyB;AACzB,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,cAAc,EAAE,CAAC;IAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
package/build/lib/plugin.d.ts
CHANGED
|
@@ -1,103 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
readonly neverProxy: true;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
static newBidiCommands: {
|
|
25
|
-
readonly 'appium:fake': {
|
|
26
|
-
readonly getPluginThing: {
|
|
27
|
-
readonly command: "getPluginThing";
|
|
28
|
-
};
|
|
29
|
-
readonly setPluginThing: {
|
|
30
|
-
readonly command: "setPluginThing";
|
|
31
|
-
readonly params: {
|
|
32
|
-
readonly required: readonly ["thing"];
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
readonly doSomeMath: {
|
|
36
|
-
readonly command: "doSomeMath";
|
|
37
|
-
readonly params: {
|
|
38
|
-
readonly required: readonly ["num1", "num2"];
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
readonly doSomeMath2: {
|
|
42
|
-
readonly command: "doSomeMath2";
|
|
43
|
-
readonly params: {
|
|
44
|
-
readonly required: readonly ["num1", "num2"];
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
/** @type {string?} */
|
|
50
|
-
static _unexpectedData: string | null;
|
|
51
|
-
static executeMethodMap: {
|
|
52
|
-
readonly 'fake: getThing': {
|
|
53
|
-
readonly command: "getFakeThing";
|
|
54
|
-
};
|
|
55
|
-
readonly 'fake: plugMeIn': {
|
|
56
|
-
readonly command: "plugMeIn";
|
|
57
|
-
readonly params: {
|
|
58
|
-
readonly required: readonly ["socket"];
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
static fakeRoute(req: any, res: any): void;
|
|
63
|
-
static unexpectedData(req: any, res: any): void;
|
|
64
|
-
static updateServer(expressApp: any, httpServer: any, cliArgs: any): Promise<void>;
|
|
65
|
-
/**
|
|
66
|
-
* @param {string} name
|
|
67
|
-
* @param {Record<string,unknown>} cliArgs
|
|
68
|
-
*/
|
|
69
|
-
constructor(name: string, cliArgs: Record<string, unknown>);
|
|
70
|
-
/**
|
|
71
|
-
* @type {string}
|
|
72
|
-
* @readonly
|
|
73
|
-
*/
|
|
74
|
-
readonly fakeThing: string;
|
|
75
|
-
/**
|
|
76
|
-
* @type {any}
|
|
77
|
-
*/
|
|
78
|
-
pluginThing: any;
|
|
79
|
-
_clockRunning: boolean;
|
|
1
|
+
import { BasePlugin } from 'appium/plugin';
|
|
2
|
+
import type { Request, Response, Application } from 'express';
|
|
3
|
+
import type { AppiumServer, BidiModuleMap, ExecuteMethodMap, ExternalDriver, MethodMap } from '@appium/types';
|
|
4
|
+
/** Driver as seen by this plugin; may include plugin-specific session data */
|
|
5
|
+
export type DriverLike = ExternalDriver & {
|
|
6
|
+
fakeSessionData?: unknown;
|
|
7
|
+
};
|
|
8
|
+
export declare class FakePlugin extends BasePlugin {
|
|
9
|
+
private readonly fakeThing;
|
|
10
|
+
private pluginThing;
|
|
11
|
+
protected _clockRunning: boolean;
|
|
12
|
+
private static _unexpectedData;
|
|
13
|
+
static newMethodMap: MethodMap<FakePlugin>;
|
|
14
|
+
static newBidiCommands: BidiModuleMap;
|
|
15
|
+
static executeMethodMap: ExecuteMethodMap<FakePlugin>;
|
|
16
|
+
constructor(name: string, cliArgs?: Record<string, unknown>);
|
|
17
|
+
static fakeRoute(_req: Request, res: Response): void;
|
|
18
|
+
static unexpectedData(_req: Request, res: Response): void;
|
|
19
|
+
static updateServer(expressApp: Application, _httpServer: AppiumServer, cliArgs: Record<string, unknown>): Promise<void>;
|
|
80
20
|
startClock(): Promise<void>;
|
|
81
|
-
doSomeMath(next:
|
|
82
|
-
doSomeMath2(
|
|
21
|
+
doSomeMath(next: () => Promise<number>, _driver: DriverLike, num1: number, num2: number): Promise<number>;
|
|
22
|
+
doSomeMath2(_next: () => Promise<unknown>, _driver: DriverLike, num1: number, num2: number): Promise<number>;
|
|
83
23
|
getFakeThing(): Promise<string>;
|
|
84
|
-
getPluginThing(): Promise<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* @param {import('@appium/types').Driver} driver
|
|
88
|
-
* @param {any} thing
|
|
89
|
-
*/
|
|
90
|
-
setPluginThing(next: () => Promise<any>, driver: import("@appium/types").Driver, thing: any): Promise<void>;
|
|
91
|
-
plugMeIn(next: any, driver: any, socket: string): Promise<string>;
|
|
24
|
+
getPluginThing(): Promise<unknown>;
|
|
25
|
+
setPluginThing(_next: () => Promise<unknown>, _driver: DriverLike, thing: unknown): Promise<void>;
|
|
26
|
+
plugMeIn(_next: () => Promise<unknown>, _driver: DriverLike, socket: string): Promise<string>;
|
|
92
27
|
getFakePluginArgs(): Promise<Record<string, unknown>>;
|
|
93
|
-
getPageSource(
|
|
94
|
-
findElement(next:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
28
|
+
getPageSource(_next: () => Promise<string>, _driver: DriverLike, ...args: unknown[]): Promise<string>;
|
|
29
|
+
findElement(next: () => Promise<{
|
|
30
|
+
fake?: boolean;
|
|
31
|
+
} & Record<string, unknown>>, _driver: DriverLike, ...args: unknown[]): Promise<{
|
|
32
|
+
fake?: boolean;
|
|
33
|
+
} & Record<string, unknown>>;
|
|
34
|
+
getFakeSessionData(_next: () => Promise<unknown>, driver: DriverLike): Promise<unknown>;
|
|
35
|
+
setFakeSessionData(_next: () => Promise<unknown>, driver: DriverLike, ...args: unknown[]): Promise<null>;
|
|
36
|
+
getWindowHandle(next: () => Promise<string>): Promise<string>;
|
|
37
|
+
onUnexpectedShutdown(_driver: DriverLike, cause: Error | string): Promise<void>;
|
|
38
|
+
execute(next: () => Promise<unknown>, driver: DriverLike, script: string, args: unknown[]): Promise<unknown>;
|
|
39
|
+
deleteSession(next: () => Promise<unknown>): Promise<unknown>;
|
|
101
40
|
}
|
|
102
|
-
import { BasePlugin } from 'appium/plugin';
|
|
103
41
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC,OAAO,KAAK,EAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAC,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,SAAS,EACV,MAAM,eAAe,CAAC;AAEvB,8EAA8E;AAC9E,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG;IAAC,eAAe,CAAC,EAAE,OAAO,CAAA;CAAC,CAAC;AAEtE,qBAAa,UAAW,SAAQ,UAAU;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,WAAW,CAAiB;IACpC,SAA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E,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EAAE,GACd,OAAO,CAAC,OAAO,CAAC;IAIb,aAAa,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAIpE"}
|
package/build/lib/plugin.js
CHANGED
|
@@ -1,33 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// @ts-check
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
3
|
exports.FakePlugin = void 0;
|
|
8
4
|
const plugin_1 = require("appium/plugin");
|
|
9
|
-
const
|
|
5
|
+
const asyncbox_1 = require("asyncbox");
|
|
10
6
|
class FakePlugin extends plugin_1.BasePlugin {
|
|
11
|
-
/**
|
|
12
|
-
* @type {string}
|
|
13
|
-
* @readonly
|
|
14
|
-
*/
|
|
15
7
|
fakeThing;
|
|
16
|
-
/**
|
|
17
|
-
* @type {any}
|
|
18
|
-
*/
|
|
19
8
|
pluginThing = null;
|
|
20
9
|
_clockRunning = true;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* @param {Record<string,unknown>} cliArgs
|
|
24
|
-
*/
|
|
25
|
-
constructor(name, cliArgs) {
|
|
26
|
-
super(name, cliArgs);
|
|
27
|
-
this.fakeThing = 'PLUGIN_FAKE_THING';
|
|
28
|
-
this.startClock();
|
|
29
|
-
}
|
|
30
|
-
static newMethodMap = /** @type {const} */ ({
|
|
10
|
+
static _unexpectedData = null;
|
|
11
|
+
static newMethodMap = {
|
|
31
12
|
'/session/:sessionId/fake_data': {
|
|
32
13
|
GET: { command: 'getFakeSessionData', neverProxy: true },
|
|
33
14
|
POST: {
|
|
@@ -39,8 +20,8 @@ class FakePlugin extends plugin_1.BasePlugin {
|
|
|
39
20
|
'/session/:sessionId/fakepluginargs': {
|
|
40
21
|
GET: { command: 'getFakePluginArgs', neverProxy: true },
|
|
41
22
|
},
|
|
42
|
-
}
|
|
43
|
-
static newBidiCommands =
|
|
23
|
+
};
|
|
24
|
+
static newBidiCommands = {
|
|
44
25
|
'appium:fake': {
|
|
45
26
|
getPluginThing: {
|
|
46
27
|
command: 'getPluginThing',
|
|
@@ -63,29 +44,30 @@ class FakePlugin extends plugin_1.BasePlugin {
|
|
|
63
44
|
required: ['num1', 'num2'],
|
|
64
45
|
},
|
|
65
46
|
},
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
static _unexpectedData = null;
|
|
70
|
-
static executeMethodMap = /** @type {const} */ ({
|
|
71
|
-
// this execute method overrides fake-drivers fake: getThing, for testing
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
static executeMethodMap = {
|
|
72
50
|
'fake: getThing': {
|
|
73
51
|
command: 'getFakeThing',
|
|
74
52
|
},
|
|
75
|
-
// this is a totally new execute method
|
|
76
53
|
'fake: plugMeIn': {
|
|
77
54
|
command: 'plugMeIn',
|
|
78
55
|
params: { required: ['socket'] },
|
|
79
56
|
},
|
|
80
|
-
}
|
|
81
|
-
|
|
57
|
+
};
|
|
58
|
+
constructor(name, cliArgs = {}) {
|
|
59
|
+
super(name, cliArgs);
|
|
60
|
+
this.fakeThing = 'PLUGIN_FAKE_THING';
|
|
61
|
+
this.startClock();
|
|
62
|
+
}
|
|
63
|
+
static fakeRoute(_req, res) {
|
|
82
64
|
res.send(JSON.stringify({ fake: 'fakeResponse' }));
|
|
83
65
|
}
|
|
84
|
-
static unexpectedData(
|
|
66
|
+
static unexpectedData(_req, res) {
|
|
85
67
|
res.send(JSON.stringify(FakePlugin._unexpectedData));
|
|
86
68
|
FakePlugin._unexpectedData = null;
|
|
87
69
|
}
|
|
88
|
-
static async updateServer(expressApp,
|
|
70
|
+
static async updateServer(expressApp, _httpServer, cliArgs) {
|
|
89
71
|
expressApp.all('/fake', FakePlugin.fakeRoute);
|
|
90
72
|
expressApp.all('/unexpected', FakePlugin.unexpectedData);
|
|
91
73
|
expressApp.all('/cliArgs', (req, res) => {
|
|
@@ -94,24 +76,23 @@ class FakePlugin extends plugin_1.BasePlugin {
|
|
|
94
76
|
}
|
|
95
77
|
async startClock() {
|
|
96
78
|
while (this._clockRunning) {
|
|
97
|
-
await
|
|
79
|
+
await (0, asyncbox_1.sleep)(250);
|
|
98
80
|
this.eventEmitter.emit('bidiEvent', {
|
|
99
81
|
method: 'appium:clock.currentTime',
|
|
100
82
|
params: { time: Date.now() },
|
|
101
83
|
});
|
|
102
84
|
}
|
|
103
85
|
}
|
|
104
|
-
async doSomeMath(next,
|
|
105
|
-
const sum = await next();
|
|
106
|
-
return
|
|
86
|
+
async doSomeMath(next, _driver, num1, num2) {
|
|
87
|
+
const sum = await next();
|
|
88
|
+
return num1 * num2 + sum;
|
|
107
89
|
}
|
|
108
|
-
async doSomeMath2(
|
|
109
|
-
|
|
110
|
-
await bluebird_1.default.delay(1);
|
|
90
|
+
async doSomeMath2(_next, _driver, num1, num2) {
|
|
91
|
+
await (0, asyncbox_1.sleep)(1);
|
|
111
92
|
return num1 * num2;
|
|
112
93
|
}
|
|
113
94
|
async getFakeThing() {
|
|
114
|
-
await
|
|
95
|
+
await (0, asyncbox_1.sleep)(1);
|
|
115
96
|
return this.fakeThing;
|
|
116
97
|
}
|
|
117
98
|
async getPluginThing() {
|
|
@@ -121,39 +102,34 @@ class FakePlugin extends plugin_1.BasePlugin {
|
|
|
121
102
|
});
|
|
122
103
|
return this.pluginThing;
|
|
123
104
|
}
|
|
124
|
-
|
|
125
|
-
* @param {() => Promise<any>} next
|
|
126
|
-
* @param {import('@appium/types').Driver} driver
|
|
127
|
-
* @param {any} thing
|
|
128
|
-
*/
|
|
129
|
-
async setPluginThing(next, driver, thing) {
|
|
105
|
+
async setPluginThing(_next, _driver, thing) {
|
|
130
106
|
this.pluginThing = thing;
|
|
131
107
|
}
|
|
132
|
-
async plugMeIn(
|
|
133
|
-
await
|
|
108
|
+
async plugMeIn(_next, _driver, socket) {
|
|
109
|
+
await (0, asyncbox_1.sleep)(1);
|
|
134
110
|
return `Plugged in to ${socket}`;
|
|
135
111
|
}
|
|
136
112
|
async getFakePluginArgs() {
|
|
137
|
-
await
|
|
113
|
+
await (0, asyncbox_1.sleep)(1);
|
|
138
114
|
return this.cliArgs;
|
|
139
115
|
}
|
|
140
|
-
async getPageSource(
|
|
141
|
-
await
|
|
116
|
+
async getPageSource(_next, _driver, ...args) {
|
|
117
|
+
await (0, asyncbox_1.sleep)(10);
|
|
142
118
|
return `<Fake>${JSON.stringify(args)}</Fake>`;
|
|
143
119
|
}
|
|
144
|
-
async findElement(next,
|
|
120
|
+
async findElement(next, _driver, ...args) {
|
|
145
121
|
this.log.info(`Before findElement is run with args ${JSON.stringify(args)}`);
|
|
146
122
|
const originalRes = await next();
|
|
147
|
-
this.log.info(
|
|
123
|
+
this.log.info('After findElement is run');
|
|
148
124
|
originalRes.fake = true;
|
|
149
125
|
return originalRes;
|
|
150
126
|
}
|
|
151
|
-
async getFakeSessionData(
|
|
152
|
-
await
|
|
153
|
-
return driver.fakeSessionData
|
|
127
|
+
async getFakeSessionData(_next, driver) {
|
|
128
|
+
await (0, asyncbox_1.sleep)(1);
|
|
129
|
+
return driver.fakeSessionData ?? null;
|
|
154
130
|
}
|
|
155
|
-
async setFakeSessionData(
|
|
156
|
-
await
|
|
131
|
+
async setFakeSessionData(_next, driver, ...args) {
|
|
132
|
+
await (0, asyncbox_1.sleep)(1);
|
|
157
133
|
driver.fakeSessionData = args[0];
|
|
158
134
|
return null;
|
|
159
135
|
}
|
|
@@ -161,7 +137,7 @@ class FakePlugin extends plugin_1.BasePlugin {
|
|
|
161
137
|
const handle = await next();
|
|
162
138
|
return `<<${handle}>>`;
|
|
163
139
|
}
|
|
164
|
-
async onUnexpectedShutdown(
|
|
140
|
+
async onUnexpectedShutdown(_driver, cause) {
|
|
165
141
|
this._clockRunning = false;
|
|
166
142
|
FakePlugin._unexpectedData = `Session ended because ${cause}`;
|
|
167
143
|
}
|
|
@@ -174,5 +150,4 @@ class FakePlugin extends plugin_1.BasePlugin {
|
|
|
174
150
|
}
|
|
175
151
|
}
|
|
176
152
|
exports.FakePlugin = FakePlugin;
|
|
177
|
-
exports.default = FakePlugin;
|
|
178
153
|
//# sourceMappingURL=plugin.js.map
|
package/build/lib/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../lib/plugin.ts"],"names":[],"mappings":";;;AAAA,0CAAyC;AACzC,uCAA+B;AAa/B,MAAa,UAAW,SAAQ,mBAAU;IACvB,SAAS,CAAS;IAC3B,WAAW,GAAY,IAAI,CAAC;IAC1B,aAAa,GAAY,IAAI,CAAC;IAChC,MAAM,CAAC,eAAe,GAAkB,IAAI,CAAC;IAErD,MAAM,CAAC,YAAY,GAA0B;QAC3C,+BAA+B,EAAE;YAC/B,GAAG,EAAE,EAAC,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,IAAI,EAAC;YACtD,IAAI,EAAE;gBACJ,OAAO,EAAE,oBAAoB;gBAC7B,aAAa,EAAE,EAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAC;gBACnC,UAAU,EAAE,IAAI;aACjB;SACF;QACD,oCAAoC,EAAE;YACpC,GAAG,EAAE,EAAC,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,IAAI,EAAC;SACtD;KACF,CAAC;IAEF,MAAM,CAAC,eAAe,GAAkB;QACtC,aAAa,EAAE;YACb,cAAc,EAAE;gBACd,OAAO,EAAE,gBAAgB;aAC1B;YACD,cAAc,EAAE;gBACd,OAAO,EAAE,gBAAgB;gBACzB,MAAM,EAAE;oBACN,QAAQ,EAAE,CAAC,OAAO,CAAC;iBACpB;aACF;YACD,UAAU,EAAE;gBACV,O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C;IAED,KAAK,CAAC,eAAe,CAAC,IAA2B;QAC/C,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAC5B,OAAO,KAAK,MAAM,IAAI,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,OAAmB,EAAE,KAAqB;QACnE,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,UAAU,CAAC,eAAe,GAAG,yBAAyB,KAAK,EAAE,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,OAAO,CACX,IAA4B,EAC5B,MAAkB,EAClB,MAAc,EACd,IAAe;QAEf,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,MAAa,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,IAA4B;QAC9C,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;;AA9MH,gCA+MC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-error.d.ts","sourceRoot":"","sources":["../../../lib/scripts/fake-error.
|
|
1
|
+
{"version":3,"file":"fake-error.d.ts","sourceRoot":"","sources":["../../../lib/scripts/fake-error.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-error.js","sourceRoot":"","sources":["../../../lib/scripts/fake-error.
|
|
1
|
+
{"version":3,"file":"fake-error.js","sourceRoot":"","sources":["../../../lib/scripts/fake-error.ts"],"names":[],"mappings":";;AAAA,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-success.d.ts","sourceRoot":"","sources":["../../../lib/scripts/fake-success.
|
|
1
|
+
{"version":3,"file":"fake-success.d.ts","sourceRoot":"","sources":["../../../lib/scripts/fake-success.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +1,5 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
3
|
+
// eslint-disable-next-line no-console -- script output
|
|
4
|
+
console.info('Successfully ran the script');
|
|
8
5
|
//# sourceMappingURL=fake-success.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-success.js","sourceRoot":"","sources":["../../../lib/scripts/fake-success.
|
|
1
|
+
{"version":3,"file":"fake-success.js","sourceRoot":"","sources":["../../../lib/scripts/fake-success.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC"}
|
package/lib/index.ts
ADDED
package/lib/plugin.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import {BasePlugin} from 'appium/plugin';
|
|
2
|
+
import {sleep} from 'asyncbox';
|
|
3
|
+
import type {Request, Response, Application} from 'express';
|
|
4
|
+
import type {
|
|
5
|
+
AppiumServer,
|
|
6
|
+
BidiModuleMap,
|
|
7
|
+
ExecuteMethodMap,
|
|
8
|
+
ExternalDriver,
|
|
9
|
+
MethodMap,
|
|
10
|
+
} from '@appium/types';
|
|
11
|
+
|
|
12
|
+
/** Driver as seen by this plugin; may include plugin-specific session data */
|
|
13
|
+
export type DriverLike = ExternalDriver & {fakeSessionData?: unknown};
|
|
14
|
+
|
|
15
|
+
export class FakePlugin extends BasePlugin {
|
|
16
|
+
private readonly fakeThing: string;
|
|
17
|
+
private pluginThing: unknown = null;
|
|
18
|
+
protected _clockRunning: boolean = true;
|
|
19
|
+
private static _unexpectedData: string | null = null;
|
|
20
|
+
|
|
21
|
+
static newMethodMap: MethodMap<FakePlugin> = {
|
|
22
|
+
'/session/:sessionId/fake_data': {
|
|
23
|
+
GET: {command: 'getFakeSessionData', neverProxy: true},
|
|
24
|
+
POST: {
|
|
25
|
+
command: 'setFakeSessionData',
|
|
26
|
+
payloadParams: {required: ['data']},
|
|
27
|
+
neverProxy: true,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
'/session/:sessionId/fakepluginargs': {
|
|
31
|
+
GET: {command: 'getFakePluginArgs', neverProxy: true},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
static newBidiCommands: BidiModuleMap = {
|
|
36
|
+
'appium:fake': {
|
|
37
|
+
getPluginThing: {
|
|
38
|
+
command: 'getPluginThing',
|
|
39
|
+
},
|
|
40
|
+
setPluginThing: {
|
|
41
|
+
command: 'setPluginThing',
|
|
42
|
+
params: {
|
|
43
|
+
required: ['thing'],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
doSomeMath: {
|
|
47
|
+
command: 'doSomeMath',
|
|
48
|
+
params: {
|
|
49
|
+
required: ['num1', 'num2'],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
doSomeMath2: {
|
|
53
|
+
command: 'doSomeMath2',
|
|
54
|
+
params: {
|
|
55
|
+
required: ['num1', 'num2'],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
static executeMethodMap: ExecuteMethodMap<FakePlugin> = {
|
|
62
|
+
'fake: getThing': {
|
|
63
|
+
command: 'getFakeThing',
|
|
64
|
+
},
|
|
65
|
+
'fake: plugMeIn': {
|
|
66
|
+
command: 'plugMeIn',
|
|
67
|
+
params: {required: ['socket']},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
constructor(name: string, cliArgs: Record<string, unknown> = {}) {
|
|
72
|
+
super(name, cliArgs);
|
|
73
|
+
this.fakeThing = 'PLUGIN_FAKE_THING';
|
|
74
|
+
this.startClock();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static fakeRoute(_req: Request, res: Response): void {
|
|
78
|
+
res.send(JSON.stringify({fake: 'fakeResponse'}));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static unexpectedData(_req: Request, res: Response): void {
|
|
82
|
+
res.send(JSON.stringify(FakePlugin._unexpectedData));
|
|
83
|
+
FakePlugin._unexpectedData = null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static async updateServer(
|
|
87
|
+
expressApp: Application,
|
|
88
|
+
_httpServer: AppiumServer,
|
|
89
|
+
cliArgs: Record<string, unknown>
|
|
90
|
+
): Promise<void> {
|
|
91
|
+
expressApp.all('/fake', FakePlugin.fakeRoute);
|
|
92
|
+
expressApp.all('/unexpected', FakePlugin.unexpectedData);
|
|
93
|
+
expressApp.all('/cliArgs', (req, res) => {
|
|
94
|
+
res.send(JSON.stringify(cliArgs));
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async startClock(): Promise<void> {
|
|
99
|
+
while (this._clockRunning) {
|
|
100
|
+
await sleep(250);
|
|
101
|
+
this.eventEmitter.emit('bidiEvent', {
|
|
102
|
+
method: 'appium:clock.currentTime',
|
|
103
|
+
params: {time: Date.now()},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async doSomeMath(
|
|
109
|
+
next: () => Promise<number>,
|
|
110
|
+
_driver: DriverLike,
|
|
111
|
+
num1: number,
|
|
112
|
+
num2: number
|
|
113
|
+
): Promise<number> {
|
|
114
|
+
const sum = await next();
|
|
115
|
+
return num1 * num2 + sum;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async doSomeMath2(
|
|
119
|
+
_next: () => Promise<unknown>,
|
|
120
|
+
_driver: DriverLike,
|
|
121
|
+
num1: number,
|
|
122
|
+
num2: number
|
|
123
|
+
): Promise<number> {
|
|
124
|
+
await sleep(1);
|
|
125
|
+
return num1 * num2;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async getFakeThing(): Promise<string> {
|
|
129
|
+
await sleep(1);
|
|
130
|
+
return this.fakeThing;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async getPluginThing(): Promise<unknown> {
|
|
134
|
+
this.eventEmitter.emit('bidiEvent', {
|
|
135
|
+
method: 'appium:fake.pluginThingRetrieved',
|
|
136
|
+
params: {},
|
|
137
|
+
});
|
|
138
|
+
return this.pluginThing;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async setPluginThing(
|
|
142
|
+
_next: () => Promise<unknown>,
|
|
143
|
+
_driver: DriverLike,
|
|
144
|
+
thing: unknown
|
|
145
|
+
): Promise<void> {
|
|
146
|
+
this.pluginThing = thing;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async plugMeIn(
|
|
150
|
+
_next: () => Promise<unknown>,
|
|
151
|
+
_driver: DriverLike,
|
|
152
|
+
socket: string
|
|
153
|
+
): Promise<string> {
|
|
154
|
+
await sleep(1);
|
|
155
|
+
return `Plugged in to ${socket}`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async getFakePluginArgs(): Promise<Record<string, unknown>> {
|
|
159
|
+
await sleep(1);
|
|
160
|
+
return this.cliArgs;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async getPageSource(
|
|
164
|
+
_next: () => Promise<string>,
|
|
165
|
+
_driver: DriverLike,
|
|
166
|
+
...args: unknown[]
|
|
167
|
+
): Promise<string> {
|
|
168
|
+
await sleep(10);
|
|
169
|
+
return `<Fake>${JSON.stringify(args)}</Fake>`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async findElement(
|
|
173
|
+
next: () => Promise<{fake?: boolean} & Record<string, unknown>>,
|
|
174
|
+
_driver: DriverLike,
|
|
175
|
+
...args: unknown[]
|
|
176
|
+
): Promise<{fake?: boolean} & Record<string, unknown>> {
|
|
177
|
+
this.log.info(`Before findElement is run with args ${JSON.stringify(args)}`);
|
|
178
|
+
const originalRes = await next();
|
|
179
|
+
this.log.info('After findElement is run');
|
|
180
|
+
originalRes.fake = true;
|
|
181
|
+
return originalRes;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async getFakeSessionData(_next: () => Promise<unknown>, driver: DriverLike): Promise<unknown> {
|
|
185
|
+
await sleep(1);
|
|
186
|
+
return driver.fakeSessionData ?? null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async setFakeSessionData(
|
|
190
|
+
_next: () => Promise<unknown>,
|
|
191
|
+
driver: DriverLike,
|
|
192
|
+
...args: unknown[]
|
|
193
|
+
): Promise<null> {
|
|
194
|
+
await sleep(1);
|
|
195
|
+
driver.fakeSessionData = args[0];
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async getWindowHandle(next: () => Promise<string>): Promise<string> {
|
|
200
|
+
const handle = await next();
|
|
201
|
+
return `<<${handle}>>`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async onUnexpectedShutdown(_driver: DriverLike, cause: Error | string): Promise<void> {
|
|
205
|
+
this._clockRunning = false;
|
|
206
|
+
FakePlugin._unexpectedData = `Session ended because ${cause}`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async execute(
|
|
210
|
+
next: () => Promise<unknown>,
|
|
211
|
+
driver: DriverLike,
|
|
212
|
+
script: string,
|
|
213
|
+
args: unknown[]
|
|
214
|
+
): Promise<unknown> {
|
|
215
|
+
return await this.executeMethod(next, driver as any, script, args);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async deleteSession(next: () => Promise<unknown>): Promise<unknown> {
|
|
219
|
+
this._clockRunning = false;
|
|
220
|
+
return await next();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
throw new Error('Unsuccessfully ran the script');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/fake-plugin",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "A fake Appium plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -23,27 +23,30 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"author": "https://github.com/appium",
|
|
26
|
+
"main": "./build/lib/index.js",
|
|
27
|
+
"types": "./build/lib/index.d.ts",
|
|
26
28
|
"directories": {
|
|
27
29
|
"lib": "./lib"
|
|
28
30
|
},
|
|
29
31
|
"files": [
|
|
30
|
-
"
|
|
32
|
+
"build/lib",
|
|
31
33
|
"lib",
|
|
32
|
-
"
|
|
33
|
-
"tsconfig.json",
|
|
34
|
-
"!build/tsconfig.tsbuildinfo"
|
|
34
|
+
"tsconfig.json"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "npm run test:unit",
|
|
38
|
-
"test:smoke": "node ./index.js",
|
|
39
|
-
"test:unit": "mocha \"./test/unit/**/*.spec
|
|
38
|
+
"test:smoke": "node ./build/lib/index.js --smoke-test",
|
|
39
|
+
"test:unit": "mocha \"./test/unit/**/*.spec.*ts\""
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@appium/base-plugin": "^3.0
|
|
43
|
-
"@appium/support": "^7.0.
|
|
44
|
-
"
|
|
45
|
-
"lodash": "4.17.
|
|
46
|
-
|
|
42
|
+
"@appium/base-plugin": "^3.1.0",
|
|
43
|
+
"@appium/support": "^7.0.6",
|
|
44
|
+
"asyncbox": "6.1.0",
|
|
45
|
+
"lodash": "4.17.23"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@appium/types": "^1.2.1",
|
|
49
|
+
"express": "5.2.1"
|
|
47
50
|
},
|
|
48
51
|
"peerDependencies": {
|
|
49
52
|
"appium": "^3.0.0-beta.0"
|
|
@@ -63,7 +66,7 @@
|
|
|
63
66
|
"publishConfig": {
|
|
64
67
|
"access": "public"
|
|
65
68
|
},
|
|
66
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "980a121804ae006db879fb6860f627ac36174c15",
|
|
67
70
|
"tags": [
|
|
68
71
|
"appium"
|
|
69
72
|
]
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"outDir": "build",
|
|
4
|
-
"
|
|
4
|
+
"types": ["mocha", "chai", "chai-as-promised"]
|
|
5
5
|
},
|
|
6
6
|
"extends": "@appium/tsconfig/tsconfig.plugin.json",
|
|
7
|
-
"include": ["lib"],
|
|
7
|
+
"include": ["lib", "test"],
|
|
8
8
|
"references": [
|
|
9
|
-
{
|
|
10
|
-
"path": "../base-plugin"
|
|
11
|
-
}
|
|
9
|
+
{"path": "../base-plugin"}
|
|
12
10
|
]
|
|
13
11
|
}
|
package/build/lib/logger.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../lib/logger.js"],"names":[],"mappings":";AAEA,wDAA2C"}
|
package/build/lib/logger.js
DELETED
package/build/lib/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../lib/logger.js"],"names":[],"mappings":";;AAAA,4CAAsC;AAEtC,MAAM,GAAG,GAAG,gBAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;AAE3C,kBAAe,GAAG,CAAC"}
|
package/index.js
DELETED
package/lib/logger.js
DELETED
package/lib/plugin.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {BasePlugin} from 'appium/plugin';
|
|
5
|
-
import B from 'bluebird';
|
|
6
|
-
|
|
7
|
-
class FakePlugin extends BasePlugin {
|
|
8
|
-
/**
|
|
9
|
-
* @type {string}
|
|
10
|
-
* @readonly
|
|
11
|
-
*/
|
|
12
|
-
fakeThing;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @type {any}
|
|
16
|
-
*/
|
|
17
|
-
pluginThing = null;
|
|
18
|
-
|
|
19
|
-
_clockRunning = true;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @param {string} name
|
|
23
|
-
* @param {Record<string,unknown>} cliArgs
|
|
24
|
-
*/
|
|
25
|
-
constructor(name, cliArgs) {
|
|
26
|
-
super(name, cliArgs);
|
|
27
|
-
this.fakeThing = 'PLUGIN_FAKE_THING';
|
|
28
|
-
this.startClock();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static newMethodMap = /** @type {const} */ ({
|
|
32
|
-
'/session/:sessionId/fake_data': {
|
|
33
|
-
GET: {command: 'getFakeSessionData', neverProxy: true},
|
|
34
|
-
POST: {
|
|
35
|
-
command: 'setFakeSessionData',
|
|
36
|
-
payloadParams: {required: ['data']},
|
|
37
|
-
neverProxy: true,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
'/session/:sessionId/fakepluginargs': {
|
|
41
|
-
GET: {command: 'getFakePluginArgs', neverProxy: true},
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
static newBidiCommands = /** @type {const} */({
|
|
46
|
-
'appium:fake': {
|
|
47
|
-
getPluginThing: {
|
|
48
|
-
command: 'getPluginThing',
|
|
49
|
-
},
|
|
50
|
-
setPluginThing: {
|
|
51
|
-
command: 'setPluginThing',
|
|
52
|
-
params: {
|
|
53
|
-
required: ['thing'],
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
doSomeMath: {
|
|
57
|
-
command: 'doSomeMath',
|
|
58
|
-
params: {
|
|
59
|
-
required: ['num1', 'num2'],
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
doSomeMath2: {
|
|
63
|
-
command: 'doSomeMath2',
|
|
64
|
-
params: {
|
|
65
|
-
required: ['num1', 'num2'],
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
/** @type {string?} */
|
|
72
|
-
static _unexpectedData = null;
|
|
73
|
-
|
|
74
|
-
static executeMethodMap = /** @type {const} */ ({
|
|
75
|
-
// this execute method overrides fake-drivers fake: getThing, for testing
|
|
76
|
-
'fake: getThing': {
|
|
77
|
-
command: 'getFakeThing',
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
// this is a totally new execute method
|
|
81
|
-
'fake: plugMeIn': {
|
|
82
|
-
command: 'plugMeIn',
|
|
83
|
-
params: {required: ['socket']},
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
static fakeRoute(req, res) {
|
|
88
|
-
res.send(JSON.stringify({fake: 'fakeResponse'}));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
static unexpectedData(req, res) {
|
|
92
|
-
res.send(JSON.stringify(FakePlugin._unexpectedData));
|
|
93
|
-
FakePlugin._unexpectedData = null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
static async updateServer(expressApp, httpServer, cliArgs) {
|
|
98
|
-
expressApp.all('/fake', FakePlugin.fakeRoute);
|
|
99
|
-
expressApp.all('/unexpected', FakePlugin.unexpectedData);
|
|
100
|
-
expressApp.all('/cliArgs', (req, res) => {
|
|
101
|
-
res.send(JSON.stringify(cliArgs));
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async startClock() {
|
|
106
|
-
while (this._clockRunning) {
|
|
107
|
-
await B.delay(250);
|
|
108
|
-
this.eventEmitter.emit('bidiEvent', {
|
|
109
|
-
method: 'appium:clock.currentTime',
|
|
110
|
-
params: {time: Date.now()},
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async doSomeMath(next, driver, num1, num2) {
|
|
116
|
-
const sum = await next(); // call driver's 'doSomeMath' which sums num1 and num2
|
|
117
|
-
return (num1 * num2) + sum;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async doSomeMath2(next, driver, num1, num2) {
|
|
121
|
-
// ignore next & driver in this method
|
|
122
|
-
await B.delay(1);
|
|
123
|
-
return num1 * num2;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async getFakeThing() {
|
|
127
|
-
await B.delay(1);
|
|
128
|
-
return this.fakeThing;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async getPluginThing() {
|
|
132
|
-
this.eventEmitter.emit('bidiEvent', {
|
|
133
|
-
method: 'appium:fake.pluginThingRetrieved',
|
|
134
|
-
params: {},
|
|
135
|
-
});
|
|
136
|
-
return this.pluginThing;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* @param {() => Promise<any>} next
|
|
141
|
-
* @param {import('@appium/types').Driver} driver
|
|
142
|
-
* @param {any} thing
|
|
143
|
-
*/
|
|
144
|
-
async setPluginThing(next, driver, thing) {
|
|
145
|
-
this.pluginThing = thing;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async plugMeIn(next, driver, /** @type {string} */ socket) {
|
|
149
|
-
await B.delay(1);
|
|
150
|
-
return `Plugged in to ${socket}`;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async getFakePluginArgs() {
|
|
154
|
-
await B.delay(1);
|
|
155
|
-
return this.cliArgs;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async getPageSource(next, driver, ...args) {
|
|
159
|
-
await B.delay(10);
|
|
160
|
-
return `<Fake>${JSON.stringify(args)}</Fake>`;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async findElement(next, driver, ...args) {
|
|
164
|
-
this.log.info(`Before findElement is run with args ${JSON.stringify(args)}`);
|
|
165
|
-
const originalRes = await next();
|
|
166
|
-
this.log.info(`After findElement is run`);
|
|
167
|
-
originalRes.fake = true;
|
|
168
|
-
return originalRes;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async getFakeSessionData(next, driver) {
|
|
172
|
-
await B.delay(1);
|
|
173
|
-
return driver.fakeSessionData || null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async setFakeSessionData(next, driver, ...args) {
|
|
177
|
-
await B.delay(1);
|
|
178
|
-
driver.fakeSessionData = args[0];
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async getWindowHandle(next) {
|
|
183
|
-
const handle = await next();
|
|
184
|
-
return `<<${handle}>>`;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
async onUnexpectedShutdown(driver, cause) {
|
|
189
|
-
this._clockRunning = false;
|
|
190
|
-
FakePlugin._unexpectedData = `Session ended because ${cause}`;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async execute(next, driver, script, args) {
|
|
194
|
-
return await this.executeMethod(next, driver, script, args);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async deleteSession(next) {
|
|
198
|
-
this._clockRunning = false;
|
|
199
|
-
return await next();
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export {FakePlugin};
|
|
204
|
-
export default FakePlugin;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
throw Error('Unsuccessfully ran the script');
|