@flowspec-qa/runner-core 0.2.1 → 0.2.3
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/devices.d.ts +12 -0
- package/dist/devices.d.ts.map +1 -0
- package/dist/devices.js +174 -0
- package/dist/devices.js.map +1 -0
- package/dist/discovery.d.ts +9 -0
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +316 -41
- package/dist/discovery.js.map +1 -1
- package/dist/executor.d.ts +12 -0
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +119 -1
- package/dist/executor.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/devices.ts +196 -0
- package/src/discovery.ts +342 -48
- package/src/executor.ts +140 -1
- package/src/index.ts +2 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface DeviceInfo {
|
|
2
|
+
id: string;
|
|
3
|
+
platform: 'android' | 'ios';
|
|
4
|
+
name: string;
|
|
5
|
+
status: 'ready' | 'offline' | 'unauthorized';
|
|
6
|
+
osVersion?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function detectAndroidDevices(): DeviceInfo[];
|
|
9
|
+
export declare function detectIosDevices(): DeviceInfo[];
|
|
10
|
+
export declare function detectAllDevices(platform?: 'android' | 'ios' | 'all'): DeviceInfo[];
|
|
11
|
+
export declare function readyDevices(platform?: 'android' | 'ios' | 'all'): DeviceInfo[];
|
|
12
|
+
//# sourceMappingURL=devices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../src/devices.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,SAAS,GAAG,KAAK,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,cAAc,CAAC;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA2BD,wBAAgB,oBAAoB,IAAI,UAAU,EAAE,CAqDnD;AAID,wBAAgB,gBAAgB,IAAI,UAAU,EAAE,CAO/C;AAgFD,wBAAgB,gBAAgB,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,UAAU,EAAE,CAKnF;AAED,wBAAgB,YAAY,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,UAAU,EAAE,CAE/E"}
|
package/dist/devices.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlowSpecQA Device Farm — USB device detection for Android and iOS.
|
|
3
|
+
* Detects all devices connected via ADB (Android) and libimobiledevice/Xcode (iOS).
|
|
4
|
+
*/
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
|
+
import { existsSync, readFileSync, unlinkSync } from 'fs';
|
|
7
|
+
import { tmpdir } from 'os';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
// ─── ADB path resolution ─────────────────────────────────────────────────────
|
|
10
|
+
const ADB_COMMON_PATHS = [
|
|
11
|
+
'adb', // already on PATH
|
|
12
|
+
'/opt/homebrew/share/android-commandlinetools/platform-tools/adb', // Homebrew
|
|
13
|
+
`${process.env.HOME}/Library/Android/sdk/platform-tools/adb`, // Android Studio macOS
|
|
14
|
+
'/usr/local/share/android-commandlinetools/platform-tools/adb', // Homebrew Intel
|
|
15
|
+
'/usr/local/bin/adb', // manual install
|
|
16
|
+
`${process.env.ANDROID_HOME}/platform-tools/adb`, // ANDROID_HOME env
|
|
17
|
+
`${process.env.ANDROID_SDK_ROOT}/platform-tools/adb`, // ANDROID_SDK_ROOT env
|
|
18
|
+
];
|
|
19
|
+
function resolveAdb() {
|
|
20
|
+
for (const candidate of ADB_COMMON_PATHS) {
|
|
21
|
+
if (!candidate)
|
|
22
|
+
continue;
|
|
23
|
+
try {
|
|
24
|
+
execSync(`"${candidate}" version`, { stdio: 'ignore', timeout: 2000 });
|
|
25
|
+
return candidate;
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
// ─── Android ────────────────────────────────────────────────────────────────
|
|
32
|
+
export function detectAndroidDevices() {
|
|
33
|
+
const adb = resolveAdb();
|
|
34
|
+
if (!adb)
|
|
35
|
+
return [];
|
|
36
|
+
try {
|
|
37
|
+
const output = execSync(`"${adb}" devices -l`, {
|
|
38
|
+
encoding: 'utf8',
|
|
39
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
40
|
+
});
|
|
41
|
+
const devices = [];
|
|
42
|
+
const lines = output.split('\n').slice(1); // skip "List of devices attached"
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
const trimmed = line.trim();
|
|
45
|
+
if (!trimmed)
|
|
46
|
+
continue;
|
|
47
|
+
const parts = trimmed.split(/\s+/);
|
|
48
|
+
const id = parts[0];
|
|
49
|
+
const statusRaw = parts[1];
|
|
50
|
+
if (!id || !statusRaw)
|
|
51
|
+
continue;
|
|
52
|
+
let status;
|
|
53
|
+
if (statusRaw === 'device')
|
|
54
|
+
status = 'ready';
|
|
55
|
+
else if (statusRaw === 'offline')
|
|
56
|
+
status = 'offline';
|
|
57
|
+
else if (statusRaw === 'unauthorized')
|
|
58
|
+
status = 'unauthorized';
|
|
59
|
+
else
|
|
60
|
+
continue;
|
|
61
|
+
// Extract model from -l output: model:SM_S911B → "Samsung SM-S911B"
|
|
62
|
+
const modelMatch = trimmed.match(/model:(\S+)/);
|
|
63
|
+
const productMatch = trimmed.match(/product:(\S+)/);
|
|
64
|
+
const rawModel = modelMatch?.[1] ?? productMatch?.[1] ?? id;
|
|
65
|
+
const name = rawModel.replace(/_/g, ' ').trim();
|
|
66
|
+
// Try to get Android version
|
|
67
|
+
let osVersion;
|
|
68
|
+
if (status === 'ready') {
|
|
69
|
+
try {
|
|
70
|
+
osVersion = execSync(`"${adb}" -s ${id} shell getprop ro.build.version.release`, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 3000 }).trim();
|
|
71
|
+
}
|
|
72
|
+
catch { }
|
|
73
|
+
}
|
|
74
|
+
devices.push({ id, platform: 'android', name, status, osVersion });
|
|
75
|
+
}
|
|
76
|
+
return devices;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// ─── iOS ────────────────────────────────────────────────────────────────────
|
|
83
|
+
export function detectIosDevices() {
|
|
84
|
+
// Strategy 1: xcrun devicectl (Xcode 15+, macOS Sonoma+)
|
|
85
|
+
const fromDevicectl = _detectViaDevicectl();
|
|
86
|
+
if (fromDevicectl.length > 0)
|
|
87
|
+
return fromDevicectl;
|
|
88
|
+
// Strategy 2: idevice_id + ideviceinfo (libimobiledevice)
|
|
89
|
+
return _detectViaLibimobiledevice();
|
|
90
|
+
}
|
|
91
|
+
function _detectViaDevicectl() {
|
|
92
|
+
// Write JSON to a temp file to avoid stdout pollution from devicectl warnings
|
|
93
|
+
const tmpFile = join(tmpdir(), `fsqa-devices-${Date.now()}.json`);
|
|
94
|
+
try {
|
|
95
|
+
execSync(`xcrun devicectl list devices --json-output "${tmpFile}" 2>/dev/null`, { stdio: 'ignore', timeout: 8000 });
|
|
96
|
+
if (!existsSync(tmpFile))
|
|
97
|
+
return [];
|
|
98
|
+
const raw = readFileSync(tmpFile, 'utf8');
|
|
99
|
+
const parsed = JSON.parse(raw);
|
|
100
|
+
const result = parsed?.result?.devices ?? [];
|
|
101
|
+
return result
|
|
102
|
+
.filter((d) => {
|
|
103
|
+
const transport = d.connectionProperties?.transportType ?? '';
|
|
104
|
+
// Accept wired connections regardless of tunnel state (shows offline if not tunneled)
|
|
105
|
+
return transport.toLowerCase().includes('wired');
|
|
106
|
+
})
|
|
107
|
+
.map((d) => {
|
|
108
|
+
const tunnelState = d.connectionProperties?.tunnelState ?? '';
|
|
109
|
+
const status = tunnelState === 'connected' ? 'ready' : 'offline';
|
|
110
|
+
return {
|
|
111
|
+
id: d.hardwareProperties?.udid ?? d.identifier ?? 'unknown',
|
|
112
|
+
platform: 'ios',
|
|
113
|
+
name: d.deviceProperties?.name ?? d.hardwareProperties?.marketingName ?? 'iOS Device',
|
|
114
|
+
status,
|
|
115
|
+
osVersion: d.deviceProperties?.osVersionNumber,
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
try {
|
|
124
|
+
unlinkSync(tmpFile);
|
|
125
|
+
}
|
|
126
|
+
catch { }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function _detectViaLibimobiledevice() {
|
|
130
|
+
try {
|
|
131
|
+
const ids = execSync('idevice_id -l', {
|
|
132
|
+
encoding: 'utf8',
|
|
133
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
134
|
+
timeout: 5000,
|
|
135
|
+
}).trim().split('\n').filter(Boolean);
|
|
136
|
+
return ids.map(udid => {
|
|
137
|
+
let name = 'iOS Device';
|
|
138
|
+
let osVersion;
|
|
139
|
+
try {
|
|
140
|
+
const info = execSync(`ideviceinfo -u ${udid} -k DeviceName`, {
|
|
141
|
+
encoding: 'utf8',
|
|
142
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
143
|
+
timeout: 3000,
|
|
144
|
+
}).trim();
|
|
145
|
+
if (info)
|
|
146
|
+
name = info;
|
|
147
|
+
}
|
|
148
|
+
catch { }
|
|
149
|
+
try {
|
|
150
|
+
osVersion = execSync(`ideviceinfo -u ${udid} -k ProductVersion`, {
|
|
151
|
+
encoding: 'utf8',
|
|
152
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
153
|
+
timeout: 3000,
|
|
154
|
+
}).trim();
|
|
155
|
+
}
|
|
156
|
+
catch { }
|
|
157
|
+
return { id: udid, platform: 'ios', name, status: 'ready', osVersion };
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// ─── Unified detection ───────────────────────────────────────────────────────
|
|
165
|
+
export function detectAllDevices(platform) {
|
|
166
|
+
const target = platform ?? 'all';
|
|
167
|
+
const android = target !== 'ios' ? detectAndroidDevices() : [];
|
|
168
|
+
const ios = target !== 'android' ? detectIosDevices() : [];
|
|
169
|
+
return [...android, ...ios];
|
|
170
|
+
}
|
|
171
|
+
export function readyDevices(platform) {
|
|
172
|
+
return detectAllDevices(platform).filter(d => d.status === 'ready');
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=devices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devices.js","sourceRoot":"","sources":["../src/devices.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAiB,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAU5B,gFAAgF;AAEhF,MAAM,gBAAgB,GAAG;IACvB,KAAK,EAAqE,kBAAkB;IAC5F,iEAAiE,EAAQ,WAAW;IACpF,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,yCAAyC,EAAY,uBAAuB;IAC/F,8DAA8D,EAAU,iBAAiB;IACzF,oBAAoB,EAAqD,iBAAiB;IAC1F,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,qBAAqB,EAAwB,mBAAmB;IAC3F,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,qBAAqB,EAAoB,uBAAuB;CAChG,CAAC;AAEF,SAAS,UAAU;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,QAAQ,EAAE,MAAM;oBAChB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;oBACjC,OAAO,EAAE,IAAI;iBACd,CAAC,CAAC,IAAI,EAAE,CAAC;YACZ,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YAEV,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAc,EAAE,IAAI,EAAE,MAAM,EAAE,OAAgB,EAAE,SAAS,EAAE,CAAC;QAC3F,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,gFAAgF;AAEhF,MAAM,UAAU,gBAAgB,CAAC,QAAoC;IACnE,MAAM,MAAM,GAAG,QAAQ,IAAI,KAAK,CAAC;IACjC,MAAM,OAAO,GAAG,MAAM,KAAK,KAAK,CAAK,CAAC,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,MAAM,GAAG,GAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAK,CAAC,CAAC,EAAE,CAAC;IACnE,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,GAAG,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,QAAoC;IAC/D,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC;AACtE,CAAC"}
|
package/dist/discovery.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ export interface DiscoveryOptions {
|
|
|
4
4
|
projectId?: string;
|
|
5
5
|
entityId?: string;
|
|
6
6
|
outputDir?: string;
|
|
7
|
+
username?: string;
|
|
8
|
+
password?: string;
|
|
9
|
+
/** Android device serial (from `flowspecqa devices`). Required when multiple Android devices are connected. */
|
|
10
|
+
deviceId?: string;
|
|
7
11
|
}
|
|
8
12
|
export interface DiscoveryResult {
|
|
9
13
|
planContent: string;
|
|
@@ -15,7 +19,12 @@ export interface DiscoveryResult {
|
|
|
15
19
|
*/
|
|
16
20
|
export declare const discoveryEngine: {
|
|
17
21
|
run(options: DiscoveryOptions): Promise<DiscoveryResult>;
|
|
22
|
+
/** Capture maestro hierarchy from current screen and return parsed JSON */
|
|
23
|
+
_captureHierarchy(env?: NodeJS.ProcessEnv): Promise<any>;
|
|
24
|
+
/** Execute a Maestro YAML flow (written to a temp file) */
|
|
25
|
+
_runMaestroFlow(appId: string, steps: string[], env?: NodeJS.ProcessEnv): boolean;
|
|
18
26
|
discoverMobile(options: DiscoveryOptions): Promise<DiscoveryResult>;
|
|
27
|
+
handleLogin(page: any, username: string, password: string): Promise<boolean>;
|
|
19
28
|
discoverWeb(options: DiscoveryOptions): Promise<DiscoveryResult>;
|
|
20
29
|
/** Fallback DOM-based plan (no Vision AI) */
|
|
21
30
|
_buildDomPlan(title: string, url: string, elements: any[]): string;
|
package/dist/discovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AA+BA,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,YAAY,GAAG,SAAS,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+GAA+G;IAC/G,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,GAAG,CAAC;CAClB;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe;iBACP,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;IAwC9D,2EAA2E;4BAC7C,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC;IAY9D,2DAA2D;2BACpC,MAAM,SAAS,MAAM,EAAE,QAAQ,MAAM,CAAC,UAAU,GAAG,OAAO;4BAmBnD,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;sBAyNjD,GAAG,YAAY,MAAM,YAAY,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;yBAkCvD,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;IAgHtE,6CAA6C;yBACxB,MAAM,OAAO,MAAM,YAAY,GAAG,EAAE,GAAG,MAAM;kCA4BpC,GAAG,GAAG,GAAG,EAAE;CA4C1C,CAAC"}
|
package/dist/discovery.js
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
1
|
+
import { execSync, spawnSync } from 'child_process';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
+
import os from 'os';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import chalk from 'chalk';
|
|
5
|
-
import { XMLParser } from 'fast-xml-parser';
|
|
6
6
|
import { FlowSpecQAApi } from './api-client.js';
|
|
7
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
8
|
+
// ─── ADB path resolution (mirrors devices.ts) ───────────────────────────────
|
|
9
|
+
const ADB_COMMON_PATHS = [
|
|
10
|
+
'adb',
|
|
11
|
+
'/opt/homebrew/share/android-commandlinetools/platform-tools/adb',
|
|
12
|
+
`${process.env.HOME}/Library/Android/sdk/platform-tools/adb`,
|
|
13
|
+
'/usr/local/share/android-commandlinetools/platform-tools/adb',
|
|
14
|
+
'/usr/local/bin/adb',
|
|
15
|
+
`${process.env.ANDROID_HOME}/platform-tools/adb`,
|
|
16
|
+
`${process.env.ANDROID_SDK_ROOT}/platform-tools/adb`,
|
|
17
|
+
];
|
|
18
|
+
function resolveAdb() {
|
|
19
|
+
for (const candidate of ADB_COMMON_PATHS) {
|
|
20
|
+
if (!candidate)
|
|
21
|
+
continue;
|
|
22
|
+
try {
|
|
23
|
+
execSync(`"${candidate}" version`, { stdio: 'ignore', timeout: 2000 });
|
|
24
|
+
return candidate;
|
|
25
|
+
}
|
|
26
|
+
catch { }
|
|
27
|
+
}
|
|
28
|
+
throw new Error('adb not found. Install Android SDK platform-tools and add to PATH.');
|
|
29
|
+
}
|
|
7
30
|
/**
|
|
8
31
|
* Autonomous Discovery Engine 2.0
|
|
9
32
|
* Uses Playwright and Maestro to extract real UI intelligence.
|
|
@@ -45,40 +68,277 @@ export const discoveryEngine = {
|
|
|
45
68
|
}
|
|
46
69
|
return result;
|
|
47
70
|
},
|
|
71
|
+
/** Capture maestro hierarchy from current screen and return parsed JSON */
|
|
72
|
+
async _captureHierarchy(env) {
|
|
73
|
+
const rawOutput = execSync('maestro hierarchy', {
|
|
74
|
+
encoding: 'utf8',
|
|
75
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
76
|
+
env: env ?? process.env,
|
|
77
|
+
});
|
|
78
|
+
const lines = rawOutput.split('\n');
|
|
79
|
+
const jsonStart = lines.findIndex(l => l.trim().startsWith('{'));
|
|
80
|
+
const jsonStr = jsonStart >= 0 ? lines.slice(jsonStart).join('\n') : rawOutput;
|
|
81
|
+
return JSON.parse(jsonStr);
|
|
82
|
+
},
|
|
83
|
+
/** Execute a Maestro YAML flow (written to a temp file) */
|
|
84
|
+
_runMaestroFlow(appId, steps, env) {
|
|
85
|
+
const yaml = `appId: ${appId}\n---\n${steps.join('\n')}\n`;
|
|
86
|
+
const tmpFile = path.join(os.tmpdir(), `discovery_flow_${Date.now()}.yaml`);
|
|
87
|
+
fs.writeFileSync(tmpFile, yaml);
|
|
88
|
+
try {
|
|
89
|
+
const result = spawnSync('maestro', ['test', tmpFile], {
|
|
90
|
+
encoding: 'utf8',
|
|
91
|
+
timeout: 120000,
|
|
92
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
93
|
+
env: env ?? process.env,
|
|
94
|
+
});
|
|
95
|
+
fs.unlinkSync(tmpFile);
|
|
96
|
+
return result.status === 0;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
try {
|
|
100
|
+
fs.unlinkSync(tmpFile);
|
|
101
|
+
}
|
|
102
|
+
catch { }
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
48
106
|
async discoverMobile(options) {
|
|
49
|
-
|
|
107
|
+
const appId = options.url;
|
|
108
|
+
const username = options.username || '';
|
|
109
|
+
const password = options.password || '';
|
|
110
|
+
const adb = resolveAdb();
|
|
111
|
+
// -s flag for device targeting when serial is provided
|
|
112
|
+
const adbS = options.deviceId ? `"${adb}" -s ${options.deviceId}` : `"${adb}"`;
|
|
113
|
+
// Maestro device env var
|
|
114
|
+
const maestroEnv = options.deviceId
|
|
115
|
+
? { ...process.env, MAESTRO_DEVICE_ID: options.deviceId }
|
|
116
|
+
: process.env;
|
|
117
|
+
console.log(chalk.gray(`📱 Starting multi-screen autonomous discovery${options.deviceId ? ` on device ${options.deviceId}` : ''}...`));
|
|
118
|
+
const allScreens = [];
|
|
50
119
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
120
|
+
// ── Reset app state ───────────────────────────────────────────────
|
|
121
|
+
console.log(chalk.gray(' 🔄 Resetting app state...'));
|
|
122
|
+
try {
|
|
123
|
+
execSync(`${adbS} shell am force-stop ${appId}`, { stdio: 'ignore' });
|
|
124
|
+
}
|
|
125
|
+
catch { }
|
|
126
|
+
try {
|
|
127
|
+
execSync(`${adbS} shell pm clear ${appId}`, { stdio: 'ignore' });
|
|
128
|
+
}
|
|
129
|
+
catch { }
|
|
130
|
+
await sleep(1000);
|
|
131
|
+
// ── Screen 1: Launch & capture Login ─────────────────────────────
|
|
132
|
+
console.log(chalk.gray(' 📸 Screen 1/3 — Login...'));
|
|
133
|
+
execSync(`${adbS} shell monkey -p ${appId} -c android.intent.category.LAUNCHER 1`, { stdio: 'ignore' });
|
|
134
|
+
await sleep(2500);
|
|
135
|
+
const loginHierarchy = await this._captureHierarchy(maestroEnv);
|
|
136
|
+
const loginElements = this.extractMaestroSelectors(loginHierarchy);
|
|
137
|
+
allScreens.push({ name: 'Login', elements: loginElements, hierarchy: loginHierarchy });
|
|
138
|
+
console.log(chalk.green(` ✅ Login: ${loginElements.length} elements`));
|
|
139
|
+
// ── Error state: Login — submit empty to reveal tv_error ─────────
|
|
140
|
+
console.log(chalk.gray(' 📸 Screen 1 error state — empty submit...'));
|
|
141
|
+
const emptyLoginOk = this._runMaestroFlow(appId, [
|
|
142
|
+
`- tapOn:\n id: "btn_login"`,
|
|
143
|
+
`- waitForAnimationToEnd:\n timeout: 1500`,
|
|
144
|
+
], maestroEnv);
|
|
145
|
+
if (emptyLoginOk) {
|
|
146
|
+
const loginErrorHierarchy = await this._captureHierarchy(maestroEnv);
|
|
147
|
+
const loginErrorAll = this.extractMaestroSelectors(loginErrorHierarchy);
|
|
148
|
+
const knownLoginIds = new Set(loginElements.map(e => e.id));
|
|
149
|
+
const loginErrorNew = loginErrorAll.filter(e => !knownLoginIds.has(e.id));
|
|
150
|
+
if (loginErrorNew.length > 0) {
|
|
151
|
+
allScreens.push({ name: 'Login (Error State)', elements: loginErrorNew, hierarchy: loginErrorHierarchy });
|
|
152
|
+
console.log(chalk.green(` ✅ Login error state: ${loginErrorNew.length} new elements (e.g. ${loginErrorNew.map(e => e.id).join(', ')})`));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// ── Navigate to Screen 2: Accounts (via login) ───────────────────
|
|
156
|
+
if (username && password) {
|
|
157
|
+
console.log(chalk.gray(' 🔐 Logging in to discover authenticated screens...'));
|
|
158
|
+
// Run login steps — no success assertion here (extendedWaitUntil is flaky).
|
|
159
|
+
// We verify login success afterward by inspecting the hierarchy.
|
|
160
|
+
this._runMaestroFlow(appId, [
|
|
161
|
+
// clearState must be a property of launchApp, not a standalone command
|
|
162
|
+
`- launchApp:\n clearState: true`,
|
|
163
|
+
`- waitForAnimationToEnd`,
|
|
164
|
+
`- tapOn:\n id: "et_username"`,
|
|
165
|
+
`- eraseText: 50`,
|
|
166
|
+
`- inputText: "${username}"`,
|
|
167
|
+
`- waitForAnimationToEnd`,
|
|
168
|
+
// Dismiss keyboard so et_password is not covered on smaller screens
|
|
169
|
+
`- hideKeyboard`,
|
|
170
|
+
`- tapOn:\n id: "et_password"`,
|
|
171
|
+
`- eraseText: 30`,
|
|
172
|
+
`- inputText: "${password}"`,
|
|
173
|
+
`- waitForAnimationToEnd`,
|
|
174
|
+
// Dismiss keyboard so btn_login is not covered
|
|
175
|
+
`- hideKeyboard`,
|
|
176
|
+
`- tapOn:\n id: "btn_login"`,
|
|
177
|
+
`- waitForAnimationToEnd`,
|
|
178
|
+
], maestroEnv);
|
|
179
|
+
// Give the app extra time to complete the login network request & navigate
|
|
180
|
+
await sleep(3000);
|
|
181
|
+
// Verify login success by checking what screen we're on
|
|
182
|
+
let postLoginHierarchy;
|
|
183
|
+
try {
|
|
184
|
+
postLoginHierarchy = await this._captureHierarchy(maestroEnv);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
postLoginHierarchy = null;
|
|
188
|
+
}
|
|
189
|
+
const postLoginElements = postLoginHierarchy ? this.extractMaestroSelectors(postLoginHierarchy) : [];
|
|
190
|
+
const loginSuccess = postLoginElements.some(e => e.id === 'tv_welcome' || e.id === 'tv_total_balance');
|
|
191
|
+
if (loginSuccess) {
|
|
192
|
+
console.log(chalk.gray(' 📸 Screen 2/3 — Accounts...'));
|
|
193
|
+
await sleep(1500);
|
|
194
|
+
const accountsHierarchy = await this._captureHierarchy(maestroEnv);
|
|
195
|
+
const accountsElements = this.extractMaestroSelectors(accountsHierarchy);
|
|
196
|
+
allScreens.push({ name: 'Accounts', elements: accountsElements, hierarchy: accountsHierarchy });
|
|
197
|
+
console.log(chalk.green(` ✅ Accounts: ${accountsElements.length} elements`));
|
|
198
|
+
// ── Navigate to Screen 3: Transfer ─────────────────────────
|
|
199
|
+
console.log(chalk.gray(' 📸 Screen 3/3 — Transfer...'));
|
|
200
|
+
const navSuccess = this._runMaestroFlow(appId, [
|
|
201
|
+
`- tapOn:\n id: "btn_transfer"`,
|
|
202
|
+
`- waitForAnimationToEnd`,
|
|
203
|
+
// No text assertion — Transfer screen title is unknown until discovery runs
|
|
204
|
+
], maestroEnv);
|
|
205
|
+
if (navSuccess) {
|
|
206
|
+
await sleep(1200);
|
|
207
|
+
const transferHierarchy = await this._captureHierarchy(maestroEnv);
|
|
208
|
+
const transferElements = this.extractMaestroSelectors(transferHierarchy);
|
|
209
|
+
allScreens.push({ name: 'Transfer', elements: transferElements, hierarchy: transferHierarchy });
|
|
210
|
+
console.log(chalk.green(` ✅ Transfer: ${transferElements.length} elements`));
|
|
211
|
+
// ── Error state: Transfer — submit empty amount ─────────
|
|
212
|
+
console.log(chalk.gray(' 📸 Transfer error state — empty amount submit...'));
|
|
213
|
+
const emptyTransferOk = this._runMaestroFlow(appId, [
|
|
214
|
+
`- tapOn:\n id: "btn_confirm"`,
|
|
215
|
+
`- waitForAnimationToEnd:\n timeout: 1500`,
|
|
216
|
+
], maestroEnv);
|
|
217
|
+
if (emptyTransferOk) {
|
|
218
|
+
const transferErrorHierarchy = await this._captureHierarchy(maestroEnv);
|
|
219
|
+
const transferErrorAll = this.extractMaestroSelectors(transferErrorHierarchy);
|
|
220
|
+
const knownTransferIds = new Set(transferElements.map(e => e.id));
|
|
221
|
+
const transferErrorNew = transferErrorAll.filter(e => !knownTransferIds.has(e.id));
|
|
222
|
+
if (transferErrorNew.length > 0) {
|
|
223
|
+
allScreens.push({ name: 'Transfer (Error State)', elements: transferErrorNew, hierarchy: transferErrorHierarchy });
|
|
224
|
+
console.log(chalk.green(` ✅ Transfer error state: ${transferErrorNew.length} new elements (e.g. ${transferErrorNew.map(e => e.id).join(', ')})`));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
console.log(chalk.yellow(' ⚠️ Transfer screen not reachable — skipping'));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
console.log(chalk.yellow(' ⚠️ Login failed — only Login screen captured'));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// ── Build comprehensive discovery plan ────────────────────────────
|
|
237
|
+
const totalElements = allScreens.reduce((sum, s) => sum + s.elements.length, 0);
|
|
238
|
+
const screenSections = allScreens.map(screen => `
|
|
239
|
+
### Screen: ${screen.name}
|
|
240
|
+
| Element Type | Text/Content | testID / Identifier |
|
|
241
|
+
|--------------|--------------|---------------------|
|
|
242
|
+
${screen.elements.map(e => `| ${e.type} | ${e.text} | \`${e.id}\` |`).join('\n') || '| — | No interactive elements found | — |'}
|
|
243
|
+
`).join('\n');
|
|
244
|
+
const planContent = `# Discovery Plan: Mobile App (${appId})
|
|
56
245
|
Generated: ${new Date().toISOString()}
|
|
57
246
|
|
|
247
|
+
## App Overview
|
|
248
|
+
- **App ID**: ${appId}
|
|
249
|
+
- **Screens discovered**: ${allScreens.length}
|
|
250
|
+
- **Total interactive elements**: ${totalElements}
|
|
251
|
+
- **Framework**: Maestro (Android native)
|
|
252
|
+
- **Device**: Physical device (ADB)
|
|
253
|
+
|
|
58
254
|
## Screen Intelligence
|
|
59
|
-
|
|
255
|
+
${screenSections}
|
|
60
256
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
257
|
+
## Suggested Test Flows
|
|
258
|
+
|
|
259
|
+
### Flow 1 — Login con credenciales válidas
|
|
260
|
+
1. Ingresar email en \`et_username\`
|
|
261
|
+
2. Ingresar contraseña en \`et_password\`
|
|
262
|
+
3. Tap \`btn_login\`
|
|
263
|
+
4. Verificar pantalla de cuentas visible
|
|
264
|
+
|
|
265
|
+
### Flow 2 — Login con credenciales inválidas
|
|
266
|
+
1. Ingresar email incorrecto
|
|
267
|
+
2. Ingresar contraseña incorrecta
|
|
268
|
+
3. Tap \`btn_login\`
|
|
269
|
+
4. Verificar mensaje de error visible
|
|
270
|
+
|
|
271
|
+
### Flow 3 — Consulta de saldo
|
|
272
|
+
1. Login exitoso
|
|
273
|
+
2. Verificar \`tv_total_balance\` visible
|
|
274
|
+
3. Verificar \`card_checking\` y \`card_savings\` presentes
|
|
275
|
+
|
|
276
|
+
### Flow 4 — Transferencia exitosa
|
|
277
|
+
1. Login → tap \`btn_transfer\`
|
|
278
|
+
2. Ingresar monto en \`et_amount\`
|
|
279
|
+
3. Ingresar destinatario en \`et_recipient\`
|
|
280
|
+
4. Tap \`btn_confirm\`
|
|
281
|
+
5. Verificar mensaje de éxito
|
|
282
|
+
|
|
283
|
+
### Flow 5 — Transferencia con monto inválido
|
|
284
|
+
1. Login → tap \`btn_transfer\`
|
|
285
|
+
2. Dejar monto vacío
|
|
286
|
+
3. Tap \`btn_confirm\`
|
|
287
|
+
4. Verificar mensaje de error
|
|
288
|
+
|
|
289
|
+
### Flow 6 — Logout
|
|
290
|
+
1. Login exitoso
|
|
291
|
+
2. Tap \`btn_logout\`
|
|
292
|
+
3. Verificar redirección a Login screen
|
|
65
293
|
|
|
66
294
|
## UI Health
|
|
67
|
-
- Total interactive nodes detected: ${
|
|
68
|
-
-
|
|
295
|
+
- Total interactive nodes detected: ${totalElements}
|
|
296
|
+
- Screens mapped: ${allScreens.map(s => s.name).join(', ')}
|
|
297
|
+
- Screen structure complexity: ${totalElements > 15 ? 'High' : totalElements > 8 ? 'Medium' : 'Low'}
|
|
69
298
|
`;
|
|
70
|
-
return {
|
|
299
|
+
return {
|
|
300
|
+
planContent,
|
|
301
|
+
rawScanData: {
|
|
302
|
+
screens: allScreens.map(s => ({ name: s.name, elements: s.elements })),
|
|
303
|
+
total: totalElements,
|
|
304
|
+
appId,
|
|
305
|
+
framework: 'maestro',
|
|
306
|
+
},
|
|
307
|
+
};
|
|
71
308
|
}
|
|
72
309
|
catch (error) {
|
|
310
|
+
console.log(chalk.red(` ❌ Discovery error: ${error.message}`));
|
|
73
311
|
return {
|
|
74
|
-
planContent: `# Discovery Plan: Mobile App
|
|
75
|
-
|
|
76
|
-
Please ensure an emulator is open and Maestro is installed.
|
|
77
|
-
`,
|
|
78
|
-
rawScanData: { error: 'Mobile environment not ready' }
|
|
312
|
+
planContent: `# Discovery Plan: Mobile App (${appId})\nStatus: FAIL\nError: ${error.message}\n`,
|
|
313
|
+
rawScanData: { error: error.message },
|
|
79
314
|
};
|
|
80
315
|
}
|
|
81
316
|
},
|
|
317
|
+
async handleLogin(page, username, password) {
|
|
318
|
+
try {
|
|
319
|
+
const passwordField = page.locator('input[type="password"]').first();
|
|
320
|
+
const count = await passwordField.count();
|
|
321
|
+
if (count === 0)
|
|
322
|
+
return false;
|
|
323
|
+
console.log(chalk.gray('🔐 Login form detected — filling credentials...'));
|
|
324
|
+
const usernameField = page.locator('input[type="email"], input[name="email"], input[name="username"], input[name="user"], ' +
|
|
325
|
+
'input[placeholder*="correo" i], input[placeholder*="email" i], input[placeholder*="usuario" i]').first();
|
|
326
|
+
await usernameField.fill(username);
|
|
327
|
+
await passwordField.fill(password);
|
|
328
|
+
const submitBtn = page.locator('button[type="submit"], input[type="submit"], ' +
|
|
329
|
+
'button:has-text("Ingresar"), button:has-text("Login"), ' +
|
|
330
|
+
'button:has-text("Sign in"), button:has-text("Entrar"), button:has-text("Iniciar")').first();
|
|
331
|
+
await submitBtn.click();
|
|
332
|
+
await page.waitForLoadState('networkidle', { timeout: 10000 }).catch(() => { });
|
|
333
|
+
await page.waitForTimeout(600);
|
|
334
|
+
console.log(chalk.green('✅ Login successful — continuing discovery on authenticated page...'));
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
console.log(chalk.yellow(`⚠️ Login attempt failed: ${err.message}`));
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
},
|
|
82
342
|
async discoverWeb(options) {
|
|
83
343
|
const { chromium } = await import('playwright');
|
|
84
344
|
console.log(chalk.gray('🌐 Launching Autonomous Playwright Crawler...'));
|
|
@@ -89,6 +349,10 @@ Please ensure an emulator is open and Maestro is installed.
|
|
|
89
349
|
const page = await context.newPage();
|
|
90
350
|
try {
|
|
91
351
|
await page.goto(options.url, { waitUntil: 'networkidle' });
|
|
352
|
+
// ── Handle login if credentials provided ────────────────────────
|
|
353
|
+
if (options.username && options.password) {
|
|
354
|
+
await this.handleLogin(page, options.username, options.password);
|
|
355
|
+
}
|
|
92
356
|
const title = await page.title();
|
|
93
357
|
// ── Phase 1: Extract DOM elements ────────────────────────────────
|
|
94
358
|
const elements = await page.evaluate(() => {
|
|
@@ -204,32 +468,43 @@ ${elements.slice(0, 20).map((e) => {
|
|
|
204
468
|
`;
|
|
205
469
|
},
|
|
206
470
|
extractMaestroSelectors(node) {
|
|
207
|
-
|
|
471
|
+
const elements = [];
|
|
472
|
+
const INTERACTIVE_CLASSES = [
|
|
473
|
+
'android.widget.Button',
|
|
474
|
+
'android.widget.EditText',
|
|
475
|
+
'android.widget.CheckBox',
|
|
476
|
+
'android.widget.RadioButton',
|
|
477
|
+
'android.widget.Switch',
|
|
478
|
+
'android.widget.ImageButton',
|
|
479
|
+
'android.widget.TextView',
|
|
480
|
+
];
|
|
208
481
|
const traverse = (current) => {
|
|
209
|
-
if (!current)
|
|
482
|
+
if (!current || typeof current !== 'object')
|
|
210
483
|
return;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
484
|
+
// maestro hierarchy JSON format: { attributes: {...}, children: [...] }
|
|
485
|
+
const attrs = current.attributes || {};
|
|
486
|
+
const resourceId = attrs['resource-id'] || '';
|
|
487
|
+
const text = attrs['text'] || attrs['accessibilityText'] || attrs['hintText'] || '';
|
|
488
|
+
const cls = attrs['class'] || '';
|
|
489
|
+
const clickable = attrs['clickable'] === 'true';
|
|
490
|
+
// Only include app-specific elements (skip Android system UI)
|
|
491
|
+
const isAppElement = resourceId && !resourceId.startsWith('android:id/') && !resourceId.startsWith('com.android.');
|
|
492
|
+
const isInteractive = INTERACTIVE_CLASSES.includes(cls) || clickable;
|
|
493
|
+
if (isAppElement && isInteractive) {
|
|
494
|
+
elements.push({
|
|
495
|
+
type: cls.split('.').pop() || cls,
|
|
496
|
+
text: text || 'N/A',
|
|
497
|
+
id: resourceId.includes('/') ? resourceId.split('/')[1] : resourceId,
|
|
498
|
+
});
|
|
220
499
|
}
|
|
221
|
-
//
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
traverse(current.node);
|
|
228
|
-
}
|
|
500
|
+
// Recurse into children
|
|
501
|
+
const children = current.children || [];
|
|
502
|
+
for (const child of children) {
|
|
503
|
+
traverse(child);
|
|
229
504
|
}
|
|
230
505
|
};
|
|
231
506
|
traverse(node);
|
|
232
|
-
return elements.slice(0,
|
|
507
|
+
return elements.slice(0, 30);
|
|
233
508
|
}
|
|
234
509
|
};
|
|
235
510
|
//# sourceMappingURL=discovery.js.map
|