@mobilewright/cli 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +422 -0
- package/dist/cli.js.map +1 -0
- package/dist/codegen.d.ts +11 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +90 -0
- package/dist/codegen.js.map +1 -0
- package/dist/codegen.test.d.ts +2 -0
- package/dist/codegen.test.d.ts.map +1 -0
- package/dist/codegen.test.js +31 -0
- package/dist/codegen.test.js.map +1 -0
- package/dist/connect.d.ts +17 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +68 -0
- package/dist/connect.js.map +1 -0
- package/dist/find-options.d.ts +19 -0
- package/dist/find-options.d.ts.map +1 -0
- package/dist/find-options.js +57 -0
- package/dist/find-options.js.map +1 -0
- package/dist/find-options.test.d.ts +2 -0
- package/dist/find-options.test.d.ts.map +1 -0
- package/dist/find-options.test.js +34 -0
- package/dist/find-options.test.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/install.d.ts +14 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +47 -0
- package/dist/install.js.map +1 -0
- package/dist/install.test.d.ts +2 -0
- package/dist/install.test.d.ts.map +1 -0
- package/dist/install.test.js +35 -0
- package/dist/install.test.js.map +1 -0
- package/dist/report.d.ts +18 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +38 -0
- package/dist/report.js.map +1 -0
- package/dist/report.test.d.ts +2 -0
- package/dist/report.test.d.ts.map +1 -0
- package/dist/report.test.js +32 -0
- package/dist/report.test.js.map +1 -0
- package/dist/session.d.ts +22 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +28 -0
- package/dist/session.js.map +1 -0
- package/dist/session.test.d.ts +2 -0
- package/dist/session.test.d.ts.map +1 -0
- package/dist/session.test.js +44 -0
- package/dist/session.test.js.map +1 -0
- package/dist/snapshot.d.ts +27 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +88 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/snapshot.test.d.ts +2 -0
- package/dist/snapshot.test.d.ts.map +1 -0
- package/dist/snapshot.test.js +45 -0
- package/dist/snapshot.test.js.map +1 -0
- package/dist/target.d.ts +17 -0
- package/dist/target.d.ts.map +1 -0
- package/dist/target.js +29 -0
- package/dist/target.js.map +1 -0
- package/dist/target.test.d.ts +2 -0
- package/dist/target.test.d.ts.map +1 -0
- package/dist/target.test.js +16 -0
- package/dist/target.test.js.map +1 -0
- package/package.json +41 -0
- package/skills/mobilewright-cli/SKILL.md +157 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.test.js","sourceRoot":"","sources":["../src/session.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAExD,SAAS,gBAAgB,CAAC,EAAyB;IACjD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,GAAG,GAAG,CAAC;IAC1C,IAAI,CAAC;QACH,EAAE,CAAC,GAAG,CAAC,CAAC;IACV,CAAC;YAAS,CAAC;QACT,IAAI,QAAQ,K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;QACpE,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,6CAA6C,EAAE,GAAG,EAAE;IACvD,gBAAgB,CAAC,CAAC,GAAG,EAAE,EAAE;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QACxC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC5B,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC;QAC9C,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ViewNode } from '@mobilewright/protocol';
|
|
2
|
+
import type { RefInfo } from './session.js';
|
|
3
|
+
export interface SnapshotLine {
|
|
4
|
+
ref: string;
|
|
5
|
+
depth: number;
|
|
6
|
+
role: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
attrs: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface SnapshotResult {
|
|
11
|
+
lines: SnapshotLine[];
|
|
12
|
+
/** Every node in document order, keyed by ref — including nodes not printed. */
|
|
13
|
+
refs: Record<string, RefInfo>;
|
|
14
|
+
/** Node identity for each ref, so `find` can map query matches back to refs. */
|
|
15
|
+
nodes: Map<ViewNode, string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Flatten a view hierarchy into Playwright-style snapshot lines.
|
|
19
|
+
* Refs are assigned to every node in document order (e1, e2, ...) so a later
|
|
20
|
+
* `find` on the same tree yields refs that agree with the printed snapshot.
|
|
21
|
+
*/
|
|
22
|
+
export declare function renderSnapshot(roots: ViewNode[]): SnapshotResult;
|
|
23
|
+
/** The snapshot line for any node, printed or not — `find` uses it for bare containers. */
|
|
24
|
+
export declare function lineFor(node: ViewNode, ref: string, depth?: number): SnapshotLine;
|
|
25
|
+
export declare function formatLine(line: SnapshotLine): string;
|
|
26
|
+
export declare function formatSnapshot(lines: SnapshotLine[]): string;
|
|
27
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,gFAAgF;IAChF,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;CAC9B;AAoCD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,cAAc,CAwBhE;AAED,2FAA2F;AAC3F,wBAAgB,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,YAAY,CAE5E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAIrD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAE5D"}
|
package/dist/snapshot.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ROLE_TYPE_MAP, bareTypeName } from '@mobilewright/core';
|
|
2
|
+
import { locatorForNode } from './codegen.js';
|
|
3
|
+
const INTERACTIVE_ROLES = new Set(['button', 'textfield', 'switch', 'checkbox', 'radio', 'slider', 'tab', 'link']);
|
|
4
|
+
function roleOf(node) {
|
|
5
|
+
const bare = bareTypeName(node.type);
|
|
6
|
+
for (const [role, types] of Object.entries(ROLE_TYPE_MAP)) {
|
|
7
|
+
if (types.includes(bare)) {
|
|
8
|
+
return role;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return bare || 'other';
|
|
12
|
+
}
|
|
13
|
+
function nameOf(node) {
|
|
14
|
+
return node.label || node.text || node.value || undefined;
|
|
15
|
+
}
|
|
16
|
+
function attrsOf(node) {
|
|
17
|
+
const attrs = [];
|
|
18
|
+
if (node.identifier) {
|
|
19
|
+
attrs.push(`testid=${JSON.stringify(node.identifier)}`);
|
|
20
|
+
}
|
|
21
|
+
if (node.placeholder) {
|
|
22
|
+
attrs.push(`placeholder=${JSON.stringify(node.placeholder)}`);
|
|
23
|
+
}
|
|
24
|
+
if (node.value && node.value !== nameOf(node)) {
|
|
25
|
+
attrs.push(`value=${JSON.stringify(node.value)}`);
|
|
26
|
+
}
|
|
27
|
+
if (!node.isVisible) {
|
|
28
|
+
attrs.push('hidden');
|
|
29
|
+
}
|
|
30
|
+
if (!node.isEnabled) {
|
|
31
|
+
attrs.push('disabled');
|
|
32
|
+
}
|
|
33
|
+
if (node.isChecked) {
|
|
34
|
+
attrs.push('checked');
|
|
35
|
+
}
|
|
36
|
+
if (node.isSelected) {
|
|
37
|
+
attrs.push('selected');
|
|
38
|
+
}
|
|
39
|
+
if (node.isFocused) {
|
|
40
|
+
attrs.push('focused');
|
|
41
|
+
}
|
|
42
|
+
return attrs;
|
|
43
|
+
}
|
|
44
|
+
/** A node earns a line when it carries text or is something the user can act on. */
|
|
45
|
+
function isInteresting(node, role) {
|
|
46
|
+
return Boolean(nameOf(node) || node.identifier || node.placeholder) || INTERACTIVE_ROLES.has(role);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Flatten a view hierarchy into Playwright-style snapshot lines.
|
|
50
|
+
* Refs are assigned to every node in document order (e1, e2, ...) so a later
|
|
51
|
+
* `find` on the same tree yields refs that agree with the printed snapshot.
|
|
52
|
+
*/
|
|
53
|
+
export function renderSnapshot(roots) {
|
|
54
|
+
const lines = [];
|
|
55
|
+
const refs = {};
|
|
56
|
+
const nodes = new Map();
|
|
57
|
+
let counter = 0;
|
|
58
|
+
function visit(node, depth) {
|
|
59
|
+
counter += 1;
|
|
60
|
+
const ref = `e${counter}`;
|
|
61
|
+
refs[ref] = { bounds: node.bounds, locator: locatorForNode(node) };
|
|
62
|
+
nodes.set(node, ref);
|
|
63
|
+
const printed = isInteresting(node, roleOf(node));
|
|
64
|
+
if (printed) {
|
|
65
|
+
lines.push(lineFor(node, ref, depth));
|
|
66
|
+
}
|
|
67
|
+
for (const child of node.children) {
|
|
68
|
+
visit(child, printed ? depth + 1 : depth);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const root of roots) {
|
|
72
|
+
visit(root, 0);
|
|
73
|
+
}
|
|
74
|
+
return { lines, refs, nodes };
|
|
75
|
+
}
|
|
76
|
+
/** The snapshot line for any node, printed or not — `find` uses it for bare containers. */
|
|
77
|
+
export function lineFor(node, ref, depth = 0) {
|
|
78
|
+
return { ref, depth, role: roleOf(node), name: nameOf(node), attrs: attrsOf(node) };
|
|
79
|
+
}
|
|
80
|
+
export function formatLine(line) {
|
|
81
|
+
const name = line.name === undefined ? '' : ` ${JSON.stringify(line.name)}`;
|
|
82
|
+
const attrs = line.attrs.map((a) => ` [${a}]`).join('');
|
|
83
|
+
return `${' '.repeat(line.depth)}- ${line.role}${name} [ref=${line.ref}]${attrs}`;
|
|
84
|
+
}
|
|
85
|
+
export function formatSnapshot(lines) {
|
|
86
|
+
return lines.map(formatLine).join('\n');
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAmB9C,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAEnH,SAAS,MAAM,CAAC,IAAc;IAC5B,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QAC1D,IAAK,KAA2B,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,IAAI,IAAI,OAAO,CAAC;AACzB,CAAC;AAED,SAAS,MAAM,CAAC,IAAc;IAC5B,OAAO,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,SAAS,CAAC;AAC5D,CAAC;AAED,SAAS,OAAO,CAAC,IAAc;IAC7B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QAAC,KAAK,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAAC,CAAC;IACjF,IAAI,IAAI,C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E,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAkB;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC5E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxD,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,IAAI,GAAG,IAAI,SAAS,IAAI,CAAC,GAAG,IAAI,KAAK,EAAE,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAqB;IAClD,OAAO,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.test.d.ts","sourceRoot":"","sources":["../src/snapshot.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test';
|
|
2
|
+
import { renderSnapshot, formatSnapshot, lineFor } from './snapshot.js';
|
|
3
|
+
function node(partial) {
|
|
4
|
+
return { isVisible: true, isEnabled: true, bounds: { x: 0, y: 0, width: 10, height: 10 }, children: [], ...partial };
|
|
5
|
+
}
|
|
6
|
+
const loginScreen = [
|
|
7
|
+
node({
|
|
8
|
+
type: 'XCUIElementTypeOther',
|
|
9
|
+
children: [
|
|
10
|
+
node({ type: 'XCUIElementTypeStaticText', label: 'Welcome' }),
|
|
11
|
+
node({ type: 'XCUIElementTypeTextField', placeholder: 'Email', identifier: 'email', bounds: { x: 10, y: 20, width: 100, height: 40 } }),
|
|
12
|
+
node({ type: 'XCUIElementTypeButton', label: 'Sign in', isEnabled: false }),
|
|
13
|
+
node({ type: 'XCUIElementTypeOther', children: [node({ type: 'android.widget.Switch', label: 'Remember me', isChecked: true })] }),
|
|
14
|
+
],
|
|
15
|
+
}),
|
|
16
|
+
];
|
|
17
|
+
test('refs are numbered in document order over every node, printed or not', () => {
|
|
18
|
+
const { refs } = renderSnapshot(loginScreen);
|
|
19
|
+
expect(Object.keys(refs)).toEqual(['e1', 'e2', 'e3', 'e4', 'e5', 'e6']);
|
|
20
|
+
expect(refs['e3'].bounds).toEqual({ x: 10, y: 20, width: 100, height: 40 });
|
|
21
|
+
expect(refs['e3'].locator).toBe('screen.getByTestId(\'email\')');
|
|
22
|
+
});
|
|
23
|
+
test('bare containers are skipped and their children are not indented further', () => {
|
|
24
|
+
const { lines } = renderSnapshot(loginScreen);
|
|
25
|
+
expect(formatSnapshot(lines)).toBe([
|
|
26
|
+
'- text "Welcome" [ref=e2]',
|
|
27
|
+
'- textfield [ref=e3] [testid="email"] [placeholder="Email"]',
|
|
28
|
+
'- button "Sign in" [ref=e4] [disabled]',
|
|
29
|
+
'- switch "Remember me" [ref=e6] [checked]',
|
|
30
|
+
].join('\n'));
|
|
31
|
+
});
|
|
32
|
+
test('children of a printed node are indented under it', () => {
|
|
33
|
+
const tree = [node({ type: 'XCUIElementTypeCell', label: 'Row', children: [node({ type: 'XCUIElementTypeStaticText', text: 'Detail' })] })];
|
|
34
|
+
expect(formatSnapshot(renderSnapshot(tree).lines)).toBe('- listitem "Row" [ref=e1]\n - text "Detail" [ref=e2]');
|
|
35
|
+
});
|
|
36
|
+
test('node identity maps back to its ref so find can reuse snapshot refs', () => {
|
|
37
|
+
const { nodes } = renderSnapshot(loginScreen);
|
|
38
|
+
expect(nodes.get(loginScreen[0].children[2])).toBe('e4');
|
|
39
|
+
});
|
|
40
|
+
test('lineFor renders a bare container that the snapshot itself would skip', () => {
|
|
41
|
+
const { lines } = renderSnapshot(loginScreen);
|
|
42
|
+
expect(lines.map((l) => l.ref)).not.toContain('e1');
|
|
43
|
+
expect(formatSnapshot([lineFor(loginScreen[0], 'e1')])).toBe('- listitem [ref=e1]');
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=snapshot.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.test.js","sourceRoot":"","sources":["../src/snapshot.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExE,SAAS,IAAI,CAAC,OAA6C;IACzD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC;AACvH,CAAC;AAED,MAAM,WAAW,GAAe;IAC9B,IAAI,CAAC;QACH,IAAI,EAAE,sBAAsB;QAC5B,QAAQ,EAAE;YACR,IAAI,CAAC,EAAE,IAAI,EAAE,2BAA2B,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;YAC7D,IAAI,CAAC,EAAE,IAAI,EAAE,0BAA0B,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC;YACvI,IAAI,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;YAC3E,IA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|
9
|
+
};
|
|
10
|
+
/** Accepts "e12" (a ref from the last snapshot) or "x,y" (screen coordinates). */
|
|
11
|
+
export declare function parseTarget(arg: string): Target;
|
|
12
|
+
export declare function resolveRef(target: Target, refs: Record<string, RefInfo>): RefInfo | undefined;
|
|
13
|
+
export declare function centerOfTarget(target: Target, refs: Record<string, RefInfo>): {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../src/target.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,MAAM,MAAM,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5F,kFAAkF;AAClF,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAS/C;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,GAAG,SAAS,CAS7F;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAMtG"}
|
package/dist/target.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Accepts "e12" (a ref from the last snapshot) or "x,y" (screen coordinates). */
|
|
2
|
+
export function parseTarget(arg) {
|
|
3
|
+
if (/^e\d+$/.test(arg)) {
|
|
4
|
+
return { kind: 'ref', ref: arg };
|
|
5
|
+
}
|
|
6
|
+
const match = arg.match(/^(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)$/);
|
|
7
|
+
if (match) {
|
|
8
|
+
return { kind: 'point', x: Number(match[1]), y: Number(match[2]) };
|
|
9
|
+
}
|
|
10
|
+
throw new Error(`expected a ref like e12 or coordinates like 100,200, got: ${arg}`);
|
|
11
|
+
}
|
|
12
|
+
export function resolveRef(target, refs) {
|
|
13
|
+
if (target.kind === 'point') {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const info = refs[target.ref];
|
|
17
|
+
if (!info) {
|
|
18
|
+
throw new Error(`unknown ref ${target.ref}, run "snapshot" or "find" first`);
|
|
19
|
+
}
|
|
20
|
+
return info;
|
|
21
|
+
}
|
|
22
|
+
export function centerOfTarget(target, refs) {
|
|
23
|
+
if (target.kind === 'point') {
|
|
24
|
+
return { x: target.x, y: target.y };
|
|
25
|
+
}
|
|
26
|
+
const { bounds } = resolveRef(target, refs);
|
|
27
|
+
return { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 };
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.js","sourceRoot":"","sources":["../src/target.ts"],"names":[],"mappings":"AAIA,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IACnC,CAAC;IACD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;IACjE,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACrE,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,6DAA6D,GAAG,EAAE,CAAC,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,IAA6B;IACtE,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,eAAe,MAAM,CAAC,GAAG,kCAAkC,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,IAA6B;IAC1E,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;IACtC,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,MAAM,EAAE,IAAI,CAAE,CAAC;IAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.test.d.ts","sourceRoot":"","sources":["../src/target.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test';
|
|
2
|
+
import { parseTarget, centerOfTarget } from './target.js';
|
|
3
|
+
const refs = { e5: { bounds: { x: 10, y: 20, width: 100, height: 40 }, locator: 'screen.getByTestId(\'x\')' } };
|
|
4
|
+
test('a ref resolves to the center of its remembered bounds', () => {
|
|
5
|
+
expect(centerOfTarget(parseTarget('e5'), refs)).toEqual({ x: 60, y: 40 });
|
|
6
|
+
});
|
|
7
|
+
test('coordinates are used as-is', () => {
|
|
8
|
+
expect(centerOfTarget(parseTarget('100,200.5'), refs)).toEqual({ x: 100, y: 200.5 });
|
|
9
|
+
});
|
|
10
|
+
test('an unknown ref tells the agent to snapshot first', () => {
|
|
11
|
+
expect(() => centerOfTarget(parseTarget('e9'), refs)).toThrow('run "snapshot" or "find" first');
|
|
12
|
+
});
|
|
13
|
+
test('anything else is rejected', () => {
|
|
14
|
+
expect(() => parseTarget('button')).toThrow('expected a ref like e12');
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=target.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.test.js","sourceRoot":"","sources":["../src/target.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,2BAA2B,EAAE,EAAE,CAAC;AAEhH,IAAI,CAAC,uDAAuD,EAAE,GAAG,EAAE;IACjE,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC5E,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4BAA4B,EAAE,GAAG,EAAE;IACtC,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AACvF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,kDAAkD,EAAE,GAAG,EAAE;IAC5D,MAAM,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAC;AAClG,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACrC,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;AACzE,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mobilewright/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Token-efficient command line interface for driving mobile devices from coding agents",
|
|
5
|
+
"homepage": "https://mobilewright.dev",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20.19"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"mobilewright-cli": "./dist/cli.js"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -b",
|
|
24
|
+
"prepublishOnly": "tsc -b"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/mobile-next/mobilewright.git",
|
|
29
|
+
"directory": "packages/cli"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"skills"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@mobilewright/core": "^0.0.1",
|
|
37
|
+
"@mobilewright/driver-mobilecli": "^0.0.1",
|
|
38
|
+
"@mobilewright/protocol": "^0.0.1",
|
|
39
|
+
"commander": "^15.0.0"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mobilewright-cli
|
|
3
|
+
description: Automate iOS and Android apps on simulators, emulators and real devices, explore screens and write Mobilewright tests.
|
|
4
|
+
allowed-tools: Bash(mobilewright-cli:*) Bash(npx:*) Bash(npm:*)
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Mobile automation with mobilewright-cli
|
|
8
|
+
|
|
9
|
+
## Quick start
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# see which devices are online (one online device is picked automatically)
|
|
13
|
+
mobilewright-cli devices
|
|
14
|
+
# launch the app under test
|
|
15
|
+
mobilewright-cli launch com.example.app
|
|
16
|
+
# snapshot prints the screen tree with refs; actions link a fresh one under .mobilewright-cli/
|
|
17
|
+
mobilewright-cli snapshot
|
|
18
|
+
mobilewright-cli fill e7 "alice@example.com"
|
|
19
|
+
mobilewright-cli tap e9
|
|
20
|
+
mobilewright-cli expect visible --text "Welcome back"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
After every action the CLI prints:
|
|
24
|
+
|
|
25
|
+
````
|
|
26
|
+
### Ran Mobilewright code
|
|
27
|
+
```js
|
|
28
|
+
await screen.getByRole('button', { name: 'Sign in' }).tap();
|
|
29
|
+
```
|
|
30
|
+
### Device
|
|
31
|
+
- Device ID: 6A557392-1480-4355-9EBC-B1D12A0F665D
|
|
32
|
+
- App: com.example.app
|
|
33
|
+
### Snapshot
|
|
34
|
+
- [Snapshot](.mobilewright-cli/screen-2026-09-14T20-13-21-867Z.yml)
|
|
35
|
+
````
|
|
36
|
+
|
|
37
|
+
Read the snapshot file to learn the refs. A snapshot line looks like
|
|
38
|
+
`- button "Sign in" [ref=e9] [testid="login"]`. Roles are `button`, `textfield`, `text`,
|
|
39
|
+
`image`, `switch`, `checkbox`, `radio`, `slider`, `list`, `listitem`, `tab`, `link`, `header`.
|
|
40
|
+
Attributes: `testid`, `placeholder`, `value`, `hidden`, `disabled`, `checked`, `selected`, `focused`.
|
|
41
|
+
|
|
42
|
+
Collect the `Ran Mobilewright code` lines to write a test: they are the exact calls
|
|
43
|
+
a Mobilewright test makes.
|
|
44
|
+
|
|
45
|
+
## Commands
|
|
46
|
+
|
|
47
|
+
### Devices and apps
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
mobilewright-cli devices
|
|
51
|
+
mobilewright-cli --device Pixel_9_Pro launch com.example.app # remembered for later commands
|
|
52
|
+
mobilewright-cli apps
|
|
53
|
+
mobilewright-cli app-install ./app.apk
|
|
54
|
+
mobilewright-cli app-install ./app.ipa
|
|
55
|
+
mobilewright-cli launch com.example.app
|
|
56
|
+
mobilewright-cli terminate com.example.app
|
|
57
|
+
mobilewright-cli url myapp://checkout/42
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Reading the screen
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
mobilewright-cli snapshot
|
|
64
|
+
# find prints only matching elements, with refs
|
|
65
|
+
mobilewright-cli find --text "Sign in"
|
|
66
|
+
mobilewright-cli find --text "/sign (in|up)/i"
|
|
67
|
+
mobilewright-cli find --role button --name "Sign in"
|
|
68
|
+
mobilewright-cli find --test-id login
|
|
69
|
+
mobilewright-cli find --label "Password"
|
|
70
|
+
mobilewright-cli find --placeholder Email
|
|
71
|
+
mobilewright-cli find --role listitem --has-text Milk --first
|
|
72
|
+
mobilewright-cli find --role listitem --nth 2
|
|
73
|
+
mobilewright-cli screenshot
|
|
74
|
+
mobilewright-cli screenshot e5 -o element.png
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Actions
|
|
78
|
+
|
|
79
|
+
Targets are a ref (`e12`) or coordinates (`100,200`).
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
mobilewright-cli tap e12
|
|
83
|
+
mobilewright-cli doubletap e12
|
|
84
|
+
mobilewright-cli longpress e12
|
|
85
|
+
mobilewright-cli fill e7 "alice@example.com" # tap, clear, type
|
|
86
|
+
mobilewright-cli type "more text" # into the focused element, no tap/clear
|
|
87
|
+
mobilewright-cli press Enter
|
|
88
|
+
mobilewright-cli press cmd+a backspace
|
|
89
|
+
mobilewright-cli button HOME
|
|
90
|
+
mobilewright-cli button BACK
|
|
91
|
+
mobilewright-cli swipe up
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Assertions
|
|
95
|
+
|
|
96
|
+
`expect` polls until the condition holds or `--timeout` (default 5000 ms) expires. It takes
|
|
97
|
+
the same locator options as `find`.
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
mobilewright-cli expect visible --text "Welcome"
|
|
101
|
+
mobilewright-cli expect hidden --test-id spinner --timeout 10000
|
|
102
|
+
mobilewright-cli expect text "3 items" --test-id cart-count
|
|
103
|
+
mobilewright-cli expect contain-text "items" --test-id cart-count
|
|
104
|
+
mobilewright-cli expect value "alice@example.com" --placeholder Email
|
|
105
|
+
mobilewright-cli expect count 3 --role listitem
|
|
106
|
+
mobilewright-cli expect enabled --role button --name "Pay"
|
|
107
|
+
mobilewright-cli expect checked --role switch --name "Remember me"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Logs and video
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
mobilewright-cli logs
|
|
114
|
+
mobilewright-cli logs --limit 500
|
|
115
|
+
mobilewright-cli logs --filter level=Error --filter process!=SpringBoard
|
|
116
|
+
mobilewright-cli video-start
|
|
117
|
+
mobilewright-cli video-start demo.mp4
|
|
118
|
+
mobilewright-cli video-stop
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Sessions
|
|
122
|
+
|
|
123
|
+
Use `-s <name>` to drive two devices side by side; each session keeps its own device and refs.
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
mobilewright-cli -s phone --device <ios-id> launch com.example.app
|
|
127
|
+
mobilewright-cli -s tablet --device <android-id> launch com.example.app
|
|
128
|
+
mobilewright-cli -s phone tap e3
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### JSON output
|
|
132
|
+
|
|
133
|
+
`--json` prints one object per command: `{ ok, code, result, device, app, snapshot }` on
|
|
134
|
+
success and `{ error }` on failure. The exceptions: `devices` prints the device array,
|
|
135
|
+
`install` prints `{ ok, lines }`, `video-stop` prints `{ ok, video }`, and `logs` always
|
|
136
|
+
prints JSON lines.
|
|
137
|
+
|
|
138
|
+
## Writing a test from a session
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
mobilewright-cli find --placeholder Email # screen.getByPlaceholder('Email')
|
|
142
|
+
mobilewright-cli fill e7 "alice@example.com" # await screen.getByPlaceholder('Email').fill('alice@example.com');
|
|
143
|
+
mobilewright-cli find --role button --name "Sign in"
|
|
144
|
+
mobilewright-cli tap e9 # await screen.getByRole('button', { name: 'Sign in' }).tap();
|
|
145
|
+
mobilewright-cli expect visible --text "Welcome" # await expect(screen.getByText('Welcome')).toBeVisible();
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { test, expect } from '@mobilewright/test';
|
|
150
|
+
|
|
151
|
+
test('signs in', async ({ device, screen }) => {
|
|
152
|
+
await device.launchApp('com.example.app');
|
|
153
|
+
await screen.getByPlaceholder('Email').fill('alice@example.com');
|
|
154
|
+
await screen.getByRole('button', { name: 'Sign in' }).tap();
|
|
155
|
+
await expect(screen.getByText('Welcome')).toBeVisible();
|
|
156
|
+
});
|
|
157
|
+
```
|