Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: attach more artifacts to rp #35

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading