Skip to content

Commit

Permalink
feat: attach more artifacts to rp (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Aug 14, 2024
1 parent d3b0f47 commit 45dd6cd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
26 changes: 24 additions & 2 deletions helpers/rpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -218,4 +238,6 @@ module.exports = {
sendLogToRP,
attachScreenshot,
finishLaunch,
attachVideo,
attachTrace,
};
45 changes: 41 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const {
sendLogToRP,
attachScreenshot,
finishLaunch,
attachVideo,
attachTrace,
} = require('./helpers/rpHelpers');
const { finishTestItem } = require('./helpers/rpHelpers');
const { version } = require('./package.json');
Expand Down Expand Up @@ -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${
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions test/codecept.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.config = {
Playwright: {
url: 'https://www.google.de/',
show: false,
trace: true,
video: true
},
JSONResponse: {},
REST: {
Expand Down

0 comments on commit 45dd6cd

Please sign in to comment.