[英]Playwright JS: How to take screenshot for failed test cases in jest test
當 Playwright Test Runner 中的測試用例失敗時,有一種方法可以使用配置文件截取屏幕截圖。 我正在使用 Jest 作為 Playwright JS 測試的測試運行器 - 有沒有辦法使用 Jest 實現相同的目標?
您可以將這樣的內容添加到您的安裝文件中:
global.test = async (name, func) => {
return await it(name, async () => {
try {
await func();
} catch (e) {
const date = new Date();
const year = date.getFullYear();
const month = date.getUTCMonth() + 1;
const dateOfMonth = date.getUTCDate();
const hour = date.getUTCHours();
const minute = date.getUTCMinutes();
const sec = date.getUTCSeconds();
const dateString = `${year}-${month}-${dateOfMonth}-${hour}-${minute}-${sec}`;
const errorScreenshotPath = `screenshots/${browserName}-${dateString}-${name.replace(
/ /g,
"_"
)}.png`;
await page.screenshot({
path: errorScreenshotPath,
});
throw e;
}
});};
它不會支持其他測試全局變量,但它是一個很好的起點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.