From d97f654c90028ffc8573d29559baa867f471c728 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Wed, 14 Aug 2024 12:10:23 +0200 Subject: [PATCH] feat: attach more artifacts to rp --- helpers/rpHelpers.js | 26 +++++++++++++++++++++++-- index.js | 45 +++++++++++++++++++++++++++++++++++++++---- test/codecept.conf.js | 2 ++ 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/helpers/rpHelpers.js b/helpers/rpHelpers.js index 5d2a773..760d9e4 100644 --- a/helpers/rpHelpers.js +++ b/helpers/rpHelpers.js @@ -193,16 +193,36 @@ async function attachScreenshot(helper, fileName) { return undefined; } } else { - content = fs.readFileSync(path.join(global.output_dir, fileName)); + content = fs.readFileSync(path.resolve(global.output_dir, fileName)); } return { - name: fileName, + name: 'failed_test.png', type: 'image/png', content, }; } +async function attachVideo(fileName) { + const content = fs.readFileSync(path.resolve(global.output_dir, fileName)); + + return { + name: 'failed_test.webm', + type: 'video/webm', + content, + }; +} + +async function attachTrace(fileName) { + const content = fs.readFileSync(path.resolve(global.output_dir, fileName)); + + return { + name: 'trace.zip', + type: 'application/zip', + content, + }; +} + module.exports = { startLaunch, getRPLink, @@ -218,4 +238,6 @@ module.exports = { sendLogToRP, attachScreenshot, finishLaunch, + attachVideo, + attachTrace, }; diff --git a/index.js b/index.js index 862375b..834666e 100644 --- a/index.js +++ b/index.js @@ -24,6 +24,8 @@ const { sendLogToRP, attachScreenshot, finishLaunch, + attachVideo, + attachTrace, } = require('./helpers/rpHelpers'); const { finishTestItem } = require('./helpers/rpHelpers'); const { version } = require('./package.json'); @@ -220,6 +222,7 @@ module.exports = (passedConfig) => { testTempId: testObj.tempId, testError: test.err, testSteps: test.steps, + testArtifacts: test.artifacts, }); const message = `${PREFIX_FAILED_TEST} - ${test.title}\n${ @@ -324,16 +327,50 @@ module.exports = (passedConfig) => { }); if (helper) { - const screenshot = await attachScreenshot( - helper, - `${clearString(test.testTitle)}.failed.png`, - ); + let screenshot; + + if (test.testArtifacts?.screenshot) { + screenshot = await attachScreenshot( + helper, + test.testArtifacts.screenshot, + ); + } else { + screenshot = await attachScreenshot( + helper, + `${clearString(test.testTitle)}.failed.png`, + ); + } + await sendLogToRP({ tempId: stepObj.tempId, level: LOG_LEVELS.DEBUG, message: '📷 Last seen screenshot', screenshotData: screenshot, }); + + if (test.testArtifacts?.video) { + const recordedVideo = await attachVideo( + test.testArtifacts.video, + ); + + await sendLogToRP({ + tempId: stepObj.tempId, + level: LOG_LEVELS.DEBUG, + message: '🎥 Last recorded video', + screenshotData: recordedVideo, + }); + } + + if (test.testArtifacts?.video) { + const trace = await attachTrace(test.testArtifacts.trace); + + await sendLogToRP({ + tempId: stepObj.tempId, + level: LOG_LEVELS.DEBUG, + message: '🕵 Trace', + screenshotData: trace, + }); + } } logToFile(`Step failed: ${stepTitle} - Error: ${stepMessage}`); } else { diff --git a/test/codecept.conf.js b/test/codecept.conf.js index b8494b8..57a88b1 100644 --- a/test/codecept.conf.js +++ b/test/codecept.conf.js @@ -4,6 +4,8 @@ exports.config = { Playwright: { url: 'https://www.google.de/', show: false, + trace: true, + video: true }, JSONResponse: {}, REST: {