0

I am using protractor for the first time and doesn't know how to add custom screenshots to jasmine report. Currently i am have done some thing like this.

onPrepare:

jasmine.getEnv().addReporter(
        new Jasmine2HtmlReporter({
            takeScreenshots: true,
            takeScreenshotsOnlyOnFailures: false,
            consolidate: true,
            consolidateAll: true,
            filePrefix: 'Report',
            screenshotsPath: './screenshots/',
            reportPath: './pageObject/reports/'
        })
    );

And added the code to take the screenshot.

browser.takeScreenshot().then(function (png) {
    test.writeScreenShot(png,screenshotName+ '.png');
}); 

test.writeScreenShot = function(data,filepath){
    var stream = fs.createWriteStream(path);
    stream.write(new Buffer(data, 'base64'));
    stream.end();
};

But now the actual pain comes in, it takes the snapshot of entire page and attach in report which i doesn't want and i want the custom snapshot which i have taken only for specific element and attach it in jasmine report. I couldn't understand how the snapshot is added to the report . can some help me how the snapshot is added automatically to the report so that i can try once for the custom snapshot taken by me and try adding it to the report.

Thanks in advance.

1 Answers1

0

Making screenshots of a certain area is not supported by selenium itself as far as I known. You can only make a screenshot of the visible page.

If you are struggling with screenshots, have a look at https://github.com/azachar/protractor-screenshoter-plugin (disclaimer: I am the author of the fork)

You can make screenshots on each expectation. Also, it comes with an HTML-based report so it is easy to understand why your tests are failing.

Andrej
  • 558
  • 6
  • 14