This commit is contained in:
zhanggy committed 2025-11-05 14:46:49 +08:00
1 parent fc250c54ed
commit 5eec516459
62 files changed
+3912 -3376

No files matched your search

+16 -16
View File
@@ -1,40 +1,40 @@
import { Page } from 'playwright'
import { TestInfo } from 'playwright/test'
import type { Page } from 'playwright';
import type { TestInfo } from 'playwright/test';
export default class TestUtil {
_page: Page
_page: Page;
_testInfo: TestInfo
_testInfo: TestInfo;
_testScreenshotPath: string
_testScreenshotPath: string;
constructor(page: Page, testInfo: TestInfo, testScreenshotPath: string) {
this._page = page
this._testInfo = testInfo
this._testScreenshotPath = testScreenshotPath
this._page = page;
this._testInfo = testInfo;
this._testScreenshotPath = testScreenshotPath;
}
async captureScreenshot(pageInstance: Page, screenshotName: string) {
if (!pageInstance) {
return
return;
}
try {
const screenshotPath = `${this._testScreenshotPath}/${screenshotName || `unknown_${Date.now()}`}.png`
const screenshotPath = `${this._testScreenshotPath}/${screenshotName || `unknown_${Date.now()}`}.png`;
await pageInstance.screenshot({ path: screenshotPath })
await pageInstance.screenshot({ path: screenshotPath });
} catch {
// Do nothing
}
}
async onTestError(error: Error) {
const titleLists = [...this._testInfo.titlePath]
titleLists.shift()
const title = titleLists.join('-')
const titleLists = [...this._testInfo.titlePath];
titleLists.shift();
const title = titleLists.join('-');
await this.captureScreenshot(this._page, `${title}_${Date.now()}`)
await this.captureScreenshot(this._page, `${title}_${Date.now()}`);
return new Error(error.message)
return new Error(error.message);
}
}