-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cannot attach screenshot to cucumber report #275
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
Comments
Here is my code: this.After(function (scenario, done) {
if (scenario.isFailed()) {
browser.takeScreenshot().then(function (png) {
scenario.attach(png, 'image/png');
});
}
}); I know the screenshot data is good because I get write to an image file and it is displayed correctly like this:
@simondean You work on screenshot feature. |
I am finally able to make it to work. This is my workaround:
|
@jlin412 that worked for me. thanks! |
I think that we can close this issue because #249 and #255 are tracking this already. |
@jlin412 If understand current code, I see that Previously ([email protected])
|
@nikulkarni the base64 encoding happens inside the JSON formatter. Cucumber's JSON formatter wrapps Gerkin's JSON formatter and it is Gerkin's JSON formatter that contains the base64 code. The code is in the encode64s function of https://github.com/cucumber/gherkin/blob/master/js/lib/gherkin/formatter/json_formatter.js |
oh I see, thanks for clearing that @simondean |
@jlin412 I get the encoded data in testReport.json but they do not show up in the cucumber Report in Jenkins. |
@jlin412 ++ |
This works currently and examples are provided in README.md, i guess this bug can be closed. |
The example on using WebDriver is not even syntactically correct, leave alone working. As stated above, the following works (using typescript and protractors browser instead of the general webdriver):
|
With 5fb6706 there is no intermediate conversion to string and we just encode it as base64 when adding it to the json output. |
@charlierudolph what if This work-around is ugly, but it works: mrooding/gulp-protractor-cucumber-html-report#19 |
Hmm. okay. What do you think about the following rule: If a string is attached, doesn't base 64 encode it. If a stream / buffer is attached, the data will be base 64 encoded |
I notice that all of my base 64 encoded strings end with "=" and when encoded twice they end with "==". I'm not sure if that's a reliable indicator - it might be a valid final character of some images. I suppose you're right though, images aren't strings, they are binary streams (or buffers) |
Hi All, We use BDD Framework (Cucumber) automated with help of Protractor/Selenium and scripting language is Typescript. I am new to Cucumber/Typescript/Protractor. I am very keen on implementing the capture of screenshots for the failed steps in our framework. I have been researching on this topic from a long time now. Although i found solution to capture screenshots with the help of this thread however i am not able to make it work with Cucumber i.e. I have placed the capture screenshot code in the After hook but the After hook does not seem to be called.I have placed the After hook code in the file named Hooks.ts under support folder. Could anyone be able to let me know what am i missing here? Appreciate your help. const Cucumber = require('cucumber'); defineSupportCode(function ({registerHandler, After}) {
}) |
@yogitasn you should not need My import {browser} from 'protractor';
export = function () {
this.Before(function (scenario, callback) {
browser.manage().window().setSize(1270, 1200);
browser.driver.get('about:blank').then(callback);
});
this.After(function (scenario, callback) {
if (scenario.isFailed()) {
browser.manage().window().setSize(1270, 1200).then(result =>
browser.takeScreenshot().then(function (stream) {
let decodedImage = new Buffer(stream.replace(/^data:image\/(png|gif|jpeg);base64,/, ''), 'base64');
scenario.attach(decodedImage, 'image/png');
callback();
}, function (err) {
callback(err);
}));
}
else {
callback();
}
});
}; |
@nalbion Thank you so much. I will use your solution and check if its working for me. |
I used the above solution with some minor changes as below however it did not seem to work :(. I added a import statement import { } from '../../support/hooks' in typescript files where the failed step function is called and also put console.log statement inside the After block and executed a failed test case. There was no output for the console statement on execution. Appreciate any suggestions. "use strict"; //import {browser} from 'protractor';(This gave me error: Module ''protractor'' has no exported member 'browser'. Used below import statement) I would also like to add that if i used the save screenshot code inside the After block i get different set of errors. features2/support/Hooks.ts(83,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'stream' must be of type 'string', but here has type 'any'. this.After(function (scenario, callback) { Thanks |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
No description provided.
The text was updated successfully, but these errors were encountered: