@testingbot/mobilewright-driver 0.1.0 → 0.2.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/README.md +87 -3
- package/dist/capabilities.d.ts +4 -3
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +21 -10
- package/dist/capabilities.js.map +1 -1
- package/dist/driver.d.ts +29 -0
- package/dist/driver.d.ts.map +1 -1
- package/dist/driver.js +138 -32
- package/dist/driver.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +6 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/observer.d.ts +18 -0
- package/dist/observer.d.ts.map +1 -1
- package/dist/observer.js +49 -3
- package/dist/observer.js.map +1 -1
- package/dist/options.d.ts +13 -2
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +2 -0
- package/dist/options.js.map +1 -1
- package/dist/rest-api.d.ts +9 -1
- package/dist/rest-api.d.ts.map +1 -1
- package/dist/rest-api.js.map +1 -1
- package/dist/run-log.d.ts +3 -2
- package/dist/run-log.d.ts.map +1 -1
- package/dist/run-log.js +2 -2
- package/dist/run-log.js.map +1 -1
- package/dist/session-commands.d.ts +75 -0
- package/dist/session-commands.d.ts.map +1 -0
- package/dist/session-commands.js +119 -0
- package/dist/session-commands.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { TestingBotDriver } from './driver.js';
|
|
2
|
+
/** @internal — called by TestingBotDriver.connect()/disconnect(). */
|
|
3
|
+
export declare function setActiveDriver(driver: TestingBotDriver | undefined): void;
|
|
4
|
+
/** Network conditions accepted by `testingbot.throttle()`. */
|
|
5
|
+
export type ThrottlePreset = 'Edge' | '3G' | '4G' | 'airplane' | 'disable';
|
|
6
|
+
export interface ThrottleProfile {
|
|
7
|
+
downloadSpeed?: number;
|
|
8
|
+
uploadSpeed?: number;
|
|
9
|
+
latency?: number;
|
|
10
|
+
loss?: number;
|
|
11
|
+
disable?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* TestingBot-specific commands, callable from inside a mobilewright test:
|
|
15
|
+
*
|
|
16
|
+
* import { testingbot } from '@testingbot/mobilewright-driver';
|
|
17
|
+
* await testingbot.throttle('3G');
|
|
18
|
+
*/
|
|
19
|
+
export declare const testingbot: {
|
|
20
|
+
/**
|
|
21
|
+
* Change network conditions mid-test (`tb:throttle`). Pass a preset
|
|
22
|
+
* ("Edge", "3G", "4G", "airplane", "disable") or a custom profile.
|
|
23
|
+
* Throttling is reset automatically when the test's device session is
|
|
24
|
+
* released, so it cannot leak into the next test on a pooled device.
|
|
25
|
+
*/
|
|
26
|
+
throttle(conditions: ThrottlePreset | ThrottleProfile): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Run an ADB shell command on Android (`mobile: shell`). Physical devices
|
|
29
|
+
* allow a whitelisted subset (am/pm/input/getprop/settings/dumpsys, ...);
|
|
30
|
+
* emulators allow everything.
|
|
31
|
+
*/
|
|
32
|
+
shell<T = unknown>(command: string, args?: string[]): Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Name this session on the TestingBot dashboard (`tb:test-name`). Useful
|
|
35
|
+
* per test — see the README recipe for naming every session from a
|
|
36
|
+
* `beforeEach`. In pooled mode the last test to run on a session wins.
|
|
37
|
+
*/
|
|
38
|
+
setName(name: string): Promise<void>;
|
|
39
|
+
/** Group this session under a build on the dashboard (`tb:test-build`). */
|
|
40
|
+
setBuild(build: string): Promise<void>;
|
|
41
|
+
/** Tag this session (`tb:test-tags`). */
|
|
42
|
+
setTags(tags: string[]): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Mark the session passed or failed (`tb:test-result`). The driver already
|
|
45
|
+
* reports the run's verdict automatically — use this only to override it,
|
|
46
|
+
* e.g. to fail a session for a reason mobilewright cannot see.
|
|
47
|
+
*/
|
|
48
|
+
setResult(passed: boolean | "passed" | "failed"): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Log a step into the session's command list (`tb:test-context`), so the
|
|
51
|
+
* TestingBot timeline shows what the test was doing at that point.
|
|
52
|
+
*/
|
|
53
|
+
annotate(context: string): Promise<void>;
|
|
54
|
+
/** Update several session fields at once (`tb:test-info`). */
|
|
55
|
+
updateInfo(info: {
|
|
56
|
+
name?: string;
|
|
57
|
+
build?: string;
|
|
58
|
+
public?: boolean;
|
|
59
|
+
statusMessage?: string;
|
|
60
|
+
extra?: string;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Pause the session for manual inspection (`tb:break`) — the test result
|
|
64
|
+
* page offers a live view with mouse/keyboard control. Debugging only: it
|
|
65
|
+
* blocks until you resume, so never leave it in CI.
|
|
66
|
+
*/
|
|
67
|
+
breakpoint(): Promise<void>;
|
|
68
|
+
/** Escape hatch: run any Appium or TestingBot execute-script command. */
|
|
69
|
+
execute<T = unknown>(script: string, ...args: unknown[]): Promise<T>;
|
|
70
|
+
/** WebDriver session id of the device this test is running on. */
|
|
71
|
+
sessionId(): string;
|
|
72
|
+
/** Link to this test's session on the TestingBot dashboard. */
|
|
73
|
+
dashboardUrl(): string;
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=session-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-commands.d.ts","sourceRoot":"","sources":["../src/session-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAYpD,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAE1E;AAYD,8DAA8D;AAC9D,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,UAAU,GAAG,SAAS,CAAC;AAC3E,MAAM,WAA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* The driver instance currently connected in THIS process. mobilewright loads
|
|
3
|
+
* `mobilewright.config.ts` in every worker and connects the driver instance it
|
|
4
|
+
* exports, and test files run in that same worker process — so tests can reach
|
|
5
|
+
* the live session through this registry without mobilewright needing to pass
|
|
6
|
+
* the driver through its fixtures. Workers are single-test-at-a-time, so one
|
|
7
|
+
* slot is enough; parallel workers are separate processes with their own.
|
|
8
|
+
*/
|
|
9
|
+
let active;
|
|
10
|
+
/** @internal — called by TestingBotDriver.connect()/disconnect(). */
|
|
11
|
+
export function setActiveDriver(driver) {
|
|
12
|
+
active = driver;
|
|
13
|
+
}
|
|
14
|
+
function requireActive(command) {
|
|
15
|
+
if (!active) {
|
|
16
|
+
throw new Error(`TestingBot: ${command} needs a connected device session. Call it inside a test body ` +
|
|
17
|
+
'(mobilewright connects the device before the test runs), not at module scope.');
|
|
18
|
+
}
|
|
19
|
+
return active;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* TestingBot-specific commands, callable from inside a mobilewright test:
|
|
23
|
+
*
|
|
24
|
+
* import { testingbot } from '@testingbot/mobilewright-driver';
|
|
25
|
+
* await testingbot.throttle('3G');
|
|
26
|
+
*/
|
|
27
|
+
export const testingbot = {
|
|
28
|
+
/**
|
|
29
|
+
* Change network conditions mid-test (`tb:throttle`). Pass a preset
|
|
30
|
+
* ("Edge", "3G", "4G", "airplane", "disable") or a custom profile.
|
|
31
|
+
* Throttling is reset automatically when the test's device session is
|
|
32
|
+
* released, so it cannot leak into the next test on a pooled device.
|
|
33
|
+
*/
|
|
34
|
+
async throttle(conditions) {
|
|
35
|
+
await requireActive('throttle()').throttle(conditions);
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* Run an ADB shell command on Android (`mobile: shell`). Physical devices
|
|
39
|
+
* allow a whitelisted subset (am/pm/input/getprop/settings/dumpsys, ...);
|
|
40
|
+
* emulators allow everything.
|
|
41
|
+
*/
|
|
42
|
+
async shell(command, args = []) {
|
|
43
|
+
return await requireActive('shell()').executeScript('mobile: shell', { command, args });
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Name this session on the TestingBot dashboard (`tb:test-name`). Useful
|
|
47
|
+
* per test — see the README recipe for naming every session from a
|
|
48
|
+
* `beforeEach`. In pooled mode the last test to run on a session wins.
|
|
49
|
+
*/
|
|
50
|
+
async setName(name) {
|
|
51
|
+
await requireActive('setName()').executeScript(`tb:test-name=${oneLine(name)}`);
|
|
52
|
+
},
|
|
53
|
+
/** Group this session under a build on the dashboard (`tb:test-build`). */
|
|
54
|
+
async setBuild(build) {
|
|
55
|
+
await requireActive('setBuild()').executeScript(`tb:test-build=${oneLine(build)}`);
|
|
56
|
+
},
|
|
57
|
+
/** Tag this session (`tb:test-tags`). */
|
|
58
|
+
async setTags(tags) {
|
|
59
|
+
await requireActive('setTags()').executeScript(`tb:test-tags=${tags.map(oneLine).join(',')}`);
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Mark the session passed or failed (`tb:test-result`). The driver already
|
|
63
|
+
* reports the run's verdict automatically — use this only to override it,
|
|
64
|
+
* e.g. to fail a session for a reason mobilewright cannot see.
|
|
65
|
+
*/
|
|
66
|
+
async setResult(passed) {
|
|
67
|
+
const value = typeof passed === 'string' ? passed : (passed ? 'passed' : 'failed');
|
|
68
|
+
await requireActive('setResult()').executeScript(`tb:test-result=${value}`);
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* Log a step into the session's command list (`tb:test-context`), so the
|
|
72
|
+
* TestingBot timeline shows what the test was doing at that point.
|
|
73
|
+
*/
|
|
74
|
+
async annotate(context) {
|
|
75
|
+
await requireActive('annotate()').executeScript(`tb:test-context=${oneLine(context)}`);
|
|
76
|
+
},
|
|
77
|
+
/** Update several session fields at once (`tb:test-info`). */
|
|
78
|
+
async updateInfo(info) {
|
|
79
|
+
const payload = {};
|
|
80
|
+
if (info.name !== undefined)
|
|
81
|
+
payload['name'] = oneLine(info.name);
|
|
82
|
+
if (info.build !== undefined)
|
|
83
|
+
payload['build'] = oneLine(info.build);
|
|
84
|
+
if (info.public !== undefined)
|
|
85
|
+
payload['public'] = info.public;
|
|
86
|
+
// The hub decodeURIComponent()s these two — send them encoded so a stray
|
|
87
|
+
// '%' in the text cannot make the whole update throw server-side.
|
|
88
|
+
if (info.statusMessage !== undefined)
|
|
89
|
+
payload['status_message'] = encodeURIComponent(info.statusMessage);
|
|
90
|
+
if (info.extra !== undefined)
|
|
91
|
+
payload['extra'] = encodeURIComponent(info.extra);
|
|
92
|
+
await requireActive('updateInfo()').executeScript(`tb:test-info=${JSON.stringify(payload)}`);
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* Pause the session for manual inspection (`tb:break`) — the test result
|
|
96
|
+
* page offers a live view with mouse/keyboard control. Debugging only: it
|
|
97
|
+
* blocks until you resume, so never leave it in CI.
|
|
98
|
+
*/
|
|
99
|
+
async breakpoint() {
|
|
100
|
+
await requireActive('breakpoint()').executeScript('tb:break');
|
|
101
|
+
},
|
|
102
|
+
/** Escape hatch: run any Appium or TestingBot execute-script command. */
|
|
103
|
+
async execute(script, ...args) {
|
|
104
|
+
return await requireActive('execute()').executeScript(script, ...args);
|
|
105
|
+
},
|
|
106
|
+
/** WebDriver session id of the device this test is running on. */
|
|
107
|
+
sessionId() {
|
|
108
|
+
return requireActive('sessionId()').currentSessionId();
|
|
109
|
+
},
|
|
110
|
+
/** Link to this test's session on the TestingBot dashboard. */
|
|
111
|
+
dashboardUrl() {
|
|
112
|
+
return `https://testingbot.com/members/tests/${this.sessionId()}`;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
/** tb: commands are string-encoded, so newlines would corrupt the payload. */
|
|
116
|
+
function oneLine(value) {
|
|
117
|
+
return value.replace(/\s*\n\s*/g, ' ').trim();
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=session-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-commands.js","sourceRoot":"","sources":["../src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