@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.
- package/LICENSE +201 -0
- package/build/lib/commands/alert.d.ts +10 -13
- package/build/lib/commands/alert.d.ts.map +1 -1
- package/build/lib/commands/alert.js +39 -46
- package/build/lib/commands/alert.js.map +1 -1
- package/build/lib/commands/contexts.d.ts +9 -13
- package/build/lib/commands/contexts.d.ts.map +1 -1
- package/build/lib/commands/contexts.js +55 -62
- package/build/lib/commands/contexts.js.map +1 -1
- package/build/lib/commands/element.d.ts +23 -26
- package/build/lib/commands/element.d.ts.map +1 -1
- package/build/lib/commands/element.js +100 -89
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/find.d.ts +14 -17
- package/build/lib/commands/find.d.ts.map +1 -1
- package/build/lib/commands/find.js +66 -63
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/general.d.ts +25 -28
- package/build/lib/commands/general.d.ts.map +1 -1
- package/build/lib/commands/general.js +90 -75
- package/build/lib/commands/general.js.map +1 -1
- package/build/lib/desired-caps.d.ts +14 -0
- package/build/lib/desired-caps.d.ts.map +1 -0
- package/build/lib/desired-caps.js +16 -0
- package/build/lib/desired-caps.js.map +1 -0
- package/build/lib/doctor/common.d.ts +11 -0
- package/build/lib/doctor/common.d.ts.map +1 -0
- package/build/lib/doctor/common.js +25 -0
- package/build/lib/doctor/common.js.map +1 -0
- package/build/lib/doctor/fake1.d.ts +3 -0
- package/build/lib/doctor/fake1.d.ts.map +1 -0
- package/build/lib/doctor/fake1.js +6 -0
- package/build/lib/doctor/fake1.js.map +1 -0
- package/build/lib/doctor/fake2.d.ts +3 -0
- package/build/lib/doctor/fake2.d.ts.map +1 -0
- package/build/lib/doctor/fake2.js +6 -0
- package/build/lib/doctor/fake2.js.map +1 -0
- package/build/lib/driver.d.ts +128 -156
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +146 -154
- package/build/lib/driver.js.map +1 -1
- package/build/lib/fake-app.d.ts +37 -45
- package/build/lib/fake-app.d.ts.map +1 -1
- package/build/lib/fake-app.js +57 -34
- package/build/lib/fake-app.js.map +1 -1
- package/build/lib/fake-driver-schema.d.ts +16 -11
- package/build/lib/fake-driver-schema.d.ts.map +1 -1
- package/build/lib/fake-driver-schema.js +2 -17
- package/build/lib/fake-driver-schema.js.map +1 -1
- package/build/lib/fake-element.d.ts +27 -26
- package/build/lib/fake-element.d.ts.map +1 -1
- package/build/lib/fake-element.js +19 -19
- package/build/lib/fake-element.js.map +1 -1
- package/build/lib/index.d.ts +2 -3
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +2 -6
- package/build/lib/index.js.map +1 -1
- package/build/lib/logger.d.ts +1 -2
- package/build/lib/logger.d.ts.map +1 -1
- package/build/lib/logger.js +2 -2
- package/build/lib/logger.js.map +1 -1
- package/build/lib/scripts/fake-error.d.ts.map +1 -1
- package/build/lib/scripts/fake-error.js.map +1 -1
- package/build/lib/scripts/fake-stdin.d.ts.map +1 -1
- package/build/lib/scripts/fake-stdin.js.map +1 -1
- package/build/lib/scripts/fake-success.d.ts.map +1 -1
- package/build/lib/scripts/fake-success.js +3 -6
- package/build/lib/scripts/fake-success.js.map +1 -1
- package/build/lib/server.d.ts +2 -1
- package/build/lib/server.d.ts.map +1 -1
- package/build/lib/server.js +3 -5
- package/build/lib/server.js.map +1 -1
- package/build/lib/types.d.ts +1 -1
- package/build/lib/types.d.ts.map +1 -1
- package/lib/commands/alert.ts +31 -61
- package/lib/commands/contexts.ts +50 -73
- package/lib/commands/element.ts +122 -135
- package/lib/commands/find.ts +100 -115
- package/lib/commands/general.ts +122 -127
- package/lib/desired-caps.ts +16 -0
- package/lib/doctor/common.ts +26 -0
- package/lib/doctor/fake1.ts +3 -0
- package/lib/doctor/fake2.ts +3 -0
- package/lib/driver.ts +321 -0
- package/lib/fake-app.ts +234 -0
- package/lib/fake-driver-schema.ts +43 -0
- package/lib/fake-element.ts +128 -0
- package/lib/{index.js → index.ts} +5 -9
- package/lib/logger.ts +3 -0
- package/lib/scripts/{fake-success.js → fake-success.ts} +1 -1
- package/lib/{server.js → server.ts} +3 -4
- package/lib/types.ts +1 -1
- package/package.json +9 -12
- package/tsconfig.json +2 -1
- package/build/lib/commands/index.d.ts +0 -14
- package/build/lib/commands/index.d.ts.map +0 -1
- package/build/lib/commands/index.js +0 -16
- package/build/lib/commands/index.js.map +0 -1
- package/build/lib/commands/mixin.d.ts +0 -11
- package/build/lib/commands/mixin.d.ts.map +0 -1
- package/build/lib/commands/mixin.js +0 -16
- package/build/lib/commands/mixin.js.map +0 -1
- package/lib/commands/index.ts +0 -14
- package/lib/commands/mixin.ts +0 -13
- package/lib/driver.js +0 -356
- package/lib/fake-app.js +0 -190
- package/lib/fake-driver-schema.js +0 -35
- package/lib/fake-element.js +0 -117
- package/lib/logger.js +0 -5
- package/test/fixtures/app.xml +0 -38
- /package/lib/scripts/{fake-error.js → fake-error.ts} +0 -0
- /package/lib/scripts/{fake-stdin.js → fake-stdin.ts} +0 -0
package/build/lib/server.js
CHANGED
|
@@ -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 =
|
|
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.
|
|
15
|
+
logger_1.log.info(`FakeDriver server listening on http://${hostname}:${port}`);
|
|
18
16
|
return server;
|
|
19
17
|
}
|
|
20
18
|
//# sourceMappingURL=server.js.map
|
package/build/lib/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../lib/server.
|
|
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"}
|
package/build/lib/types.d.ts
CHANGED
package/build/lib/types.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/lib/commands/alert.ts
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
37
|
+
/** In this fake, dismiss is the same as accept. */
|
|
38
|
+
export async function postDismissAlert(this: FakeDriver): Promise<void> {
|
|
39
|
+
return this.postAcceptAlert();
|
|
40
|
+
}
|
package/lib/commands/contexts.ts
CHANGED
|
@@ -1,84 +1,61 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import {
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
export async function getCurrentContext(this: FakeDriver): Promise<string> {
|
|
25
|
+
return this.curContext;
|
|
26
|
+
}
|
|
36
27
|
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (context
|
|
52
|
-
this.
|
|
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
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
}
|
package/lib/commands/element.ts
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
+
}
|