Skip to content

Commit

Permalink
fix: remove page instance in dump file (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyutaotao authored Aug 8, 2024
1 parent 41058a0 commit 56db22a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ playwright/.cache/

# Midscene.js dump files
__ai_responses__/

midscene_run

.nx/cache
.nx/workspace-data
3 changes: 2 additions & 1 deletion packages/midscene/src/insight/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getDumpDir,
getPkgInfo,
insightDumpFileExt,
stringifyDumpData,
writeDumpFile,
} from '@/utils';

Expand Down Expand Up @@ -55,7 +56,7 @@ export function writeInsightDump(
logFileName = `${pid}_${baseData.logTime}-${Math.random()}`;
}
}
const dataString = JSON.stringify(finalData, null, 2);
const dataString = stringifyDumpData(finalData, 2);

if (typeof logIdIndexMap[id] === 'number') {
logContent[logIdIndexMap[id]] = dataString;
Expand Down
14 changes: 14 additions & 0 deletions packages/midscene/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,17 @@ export async function sleep(ms: number) {
}

export const commonScreenshotParam = { type: 'jpeg', quality: 75 } as any;

export function replacerForPageObject(key: string, value: any) {
if (value && value.constructor?.name === 'Page') {
return '[Page object]';
}
if (value && value.constructor?.name === 'Browser') {
return '[Browser object]';
}
return value;
}

export function stringifyDumpData(data: any, indents?: number) {
return JSON.stringify(data, replacerForPageObject, indents);
}
8 changes: 6 additions & 2 deletions packages/web-integration/src/common/agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { WebPage } from '@/common/page';
import type { ExecutionDump, GroupedActionDump } from '@midscene/core';
import { groupedActionDumpFileExt, writeDumpFile } from '@midscene/core/utils';
import {
groupedActionDumpFileExt,
stringifyDumpData,
writeDumpFile,
} from '@midscene/core/utils';
import { PageTaskExecutor } from '../common/tasks';
import type { AiTaskCache } from './task-cache';

Expand Down Expand Up @@ -41,7 +45,7 @@ export class PageAgent {
this.dumpFile = writeDumpFile({
fileName: `playwright-${this.testId}`,
fileExt: groupedActionDumpFileExt,
fileContent: JSON.stringify(this.dumps),
fileContent: stringifyDumpData(this.dumps),
});
}

Expand Down
9 changes: 6 additions & 3 deletions packages/web-integration/src/playwright/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import fs from 'node:fs';
import path, { join } from 'node:path';
import type { AiTaskCache } from '@/common/task-cache';
import { findNearestPackageJson } from '@/common/utils';
import { getDumpDirPath, writeDumpFile } from '@midscene/core/utils';
import {
getDumpDirPath,
stringifyDumpData,
writeDumpFile,
} from '@midscene/core/utils';

export function writeTestCache(
taskFile: string,
Expand All @@ -13,15 +17,14 @@ export function writeTestCache(
writeDumpFile({
fileName: `${taskFile}(${taskTitle})`,
fileExt: 'json',
fileContent: JSON.stringify(
fileContent: stringifyDumpData(
{
pkgName: packageJson.name,
pkgVersion: packageJson.version,
taskFile,
taskTitle,
...taskCacheJson,
},
null,
2,
),
type: 'cache',
Expand Down

0 comments on commit 56db22a

Please sign in to comment.