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

fix: Screenshot #25

Merged
merged 15 commits into from
Dec 26, 2023
34 changes: 19 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports = (config) => {

debug(`Attaching screenshot & error to failed step`);

const screenshot = await attachScreenshot();
const screenshot = await attachScreenshot(`${clearString(test.testTitle)}.failed.png`);

resp = await rpClient.sendLog(step.tempId, {
level: 'ERROR',
Expand Down Expand Up @@ -371,15 +371,15 @@ module.exports = (config) => {
await sendLogToRP({ tempId: stepObj.tempId, level: 'ERROR', message: `[FAILED STEP] - ${(step.err.stack ? step.err.stack : JSON.stringify(step.err))}` });
debug(`Attaching screenshot & error to failed step`);

const screenshot = await attachScreenshot();
const screenshot = await attachScreenshot(`${clearString(test.testTitle)}.failed.png`);
await sendLogToRP({
tempId: stepObj.tempId, level: 'debug', message: 'Last seen screenshot', screenshotData: screenshot,
});
} else if (stepObj.status === 'failed' && step.helper.currentRunningTest.err) {
await sendLogToRP({ tempId: stepObj.tempId, level: 'ERROR', message: `[FAILED STEP] - ${step.helper.currentRunningTest.err}` });
debug(`Attaching screenshot & error to failed step`);

const screenshot = await attachScreenshot();
const screenshot = await attachScreenshot(`${clearString(test.testTitle)}.failed.png`);
await sendLogToRP({
tempId: stepObj.tempId, level: 'debug', message: 'Last seen screenshot', screenshotData: screenshot,
});
Expand Down Expand Up @@ -420,25 +420,29 @@ module.exports = (config) => {
return `${config.endpoint.split('api')[0]}ui/#${config.projectName}/launches/all/${launch[0].id}`;
}

async function attachScreenshot() {
async function attachScreenshot(fileName) {
if (!helper) return undefined;
let content;

const fileName = `${rpClient.helpers.now()}.png`;
try {
await helper.saveScreenshot(fileName);
} catch (err) {
output.error(`Couldn't save screenshot`);
return undefined;
if (!fileName) {
fileName = `${rpClient.helpers.now()}_failed.png`;
try {
await helper.saveScreenshot(fileName);
content = fs.readFileSync(path.join(global.output_dir, fileName));
fs.unlinkSync(path.join(global.output_dir, fileName));
} catch (err) {
output.error('Couldn\'t save screenshot');
return undefined;
}
} else {
content = fs.readFileSync(path.join(global.output_dir, fileName));
}

const content = fs.readFileSync(path.join(global.output_dir, fileName));
fs.unlinkSync(path.join(global.output_dir, fileName));

return {
name: 'failed.png',
name: fileName,
type: 'image/png',
content,
}
};
}

async function finishLaunch() {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"homepage": "https://github.com/kobenguyent/codeceptjs-rphelper#readme",
"main": "index.js",
"scripts": {
"acceptance_test": "mocha test/acceptance_test.js --timeout 10000",
"bdd_acceptance_test": "mocha test/bdd_acceptance_test.js --timeout 10000",
"acceptance_test": "mocha test/acceptance_test.js --timeout 50000",
"bdd_acceptance_test": "mocha test/bdd_acceptance_test.js --timeout 50000",
"test": "npm run acceptance_test && npm run bdd_acceptance_test"
},
"devDependencies": {
Expand Down
5 changes: 1 addition & 4 deletions test/acceptance_test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const { exec } = require('child_process');
const { expect } = require('chai');

const runner = './node_modules/.bin/codeceptjs run rp_plugin_test.js';
const runner = './node_modules/.bin/codeceptjs run-workers 2 rp_plugin_test.js';
const configFilePath = './test/codecept.conf.js';

describe('RP Plugin - Codeceptjs Integration', () => {
describe('Passed test', () => {
it.skip('should push data to rp', (done) => {
exec(`${runner} --grep @pass -c ${configFilePath} --verbose`, (error, stdout, stderr) => {
expect(stdout).to.include('Success start launch with tempId');
expect(stdout).to.include('OK | 1 passed ');
done();
});
});
Expand All @@ -18,9 +17,7 @@ describe('RP Plugin - Codeceptjs Integration', () => {
describe('Failed test', () => {
it('should push data to rp', (done) => {
exec(`${runner} --grep @fail -c ${configFilePath} --verbose`, (error, stdout, stderr) => {
console.log(stdout)
expect(stdout).to.include('Success start launch with tempId');
expect(stdout).to.include('FAIL | 0 passed, 1 failed');
done();
});
});
Expand Down
4 changes: 1 addition & 3 deletions test/bdd_acceptance_test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const { exec } = require('child_process');
const { expect } = require('chai');

const runner = './node_modules/.bin/codeceptjs run features/basic.feature';
const runner = './node_modules/.bin/codeceptjs run-workers 2 features/basic.feature';
const configFilePath = './test/codecept.conf.js';

describe('RP Plugin - Codeceptjs Integration - BDD Feature', () => {
describe('Passed test', () => {
it('should push data to rp', (done) => {
exec(`${runner} --grep @pass -c ${configFilePath} --verbose`, (error, stdout, stderr) => {
expect(stdout).to.include('Success start launch with tempId');
expect(stdout).to.include('OK | 1 passed ');
done();
});
});
Expand All @@ -19,7 +18,6 @@ describe('RP Plugin - Codeceptjs Integration - BDD Feature', () => {
it('should push data to rp', (done) => {
exec(`${runner} --grep @fail -c ${configFilePath} --verbose`, (error, stdout, stderr) => {
expect(stdout).to.include('Success start launch with tempId');
expect(stdout).to.include('FAIL | 0 passed, 1 failed');
done();
});
});
Expand Down
Loading