Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/mobilewright/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export interface MobilewrightConfig {
installApps?: string | string[];
/** Automatically launch the app after connecting. Default: true. */
autoAppLaunch?: boolean;
/** Attach the accessibility tree as JSON to the test report on failure. Default: false. */
saveTreeOnFailure?: boolean;
/** mobilecli server URL (use for remote servers). */
url?: string;
/** Path to mobilecli binary (if not on PATH). */
Expand Down
19 changes: 18 additions & 1 deletion packages/test/src/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type MobilewrightTestFixtures = {
bundleId: string | undefined;
platform: 'ios' | 'android' | undefined;
deviceName: RegExp | undefined;
saveTreeOnFailure: boolean;
device: Device;
};

Expand All @@ -53,6 +54,11 @@ export const test = base.extend<MobilewrightTestFixtures>({
platform: [undefined, { option: true }],
deviceName: [undefined, { option: true }],

saveTreeOnFailure: [async ({}, use) => {
const config = await loadConfig();
await use(config.saveTreeOnFailure ?? false);
}, { option: true }],

device: async ({ platform, deviceName, bundleId }, use, testInfo) => {
const config = await loadConfig(process.cwd(), testInfo.config.configFile);
const merged = {
Expand Down Expand Up @@ -104,7 +110,7 @@ export const test = base.extend<MobilewrightTestFixtures>({
}
},

screen: async ({ device, video }, use, testInfo) => {
screen: async ({ device, video, saveTreeOnFailure }, use, testInfo) => {
const videoMode = typeof video === 'object' ? video.mode : video;
const shouldRecord = videoMode === 'on' || videoMode === 'retain-on-failure';
const videoPath = shouldRecord
Expand Down Expand Up @@ -145,6 +151,17 @@ export const test = base.extend<MobilewrightTestFixtures>({
} catch {
// device may be disconnected
}
if (saveTreeOnFailure) {
try {
const tree = await device.screen.viewTree();
await testInfo.attach('view-tree-on-failure', {
body: Buffer.from(JSON.stringify(tree, null, 2)),
contentType: 'application/json',
});
} catch {
// device may be disconnected
}
}
}
},
});
Expand Down