mcfly-io / generator-mcfly

A Yeoman generator for scaffolding an application using angular, browserify, ionic and famous
323 stars 43 forks source link

Add a browser.shot method in protractor #263

Closed thaiat closed 9 years ago

thaiat commented 9 years ago

in protractor.conf.js

var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var destScreenShots = './reports/screenshots';
        browser.shot = function(filename) {
            filename = _.kebabCase(filename);
            browser.takeScreenshot().then(function(png) {
                var file = path.resolve(destScreenShots + '/' + filename + '.png');
                fs.writeFileSync(file, png, {
                    encoding: 'base64'
                });
            });
        };
thaiat commented 9 years ago

this method can be used in a test suite to save specific screenshots:

it('something', function() {
   var prefixScreenshot = suitename + 'Campagne test';
   expect(mainView.charts().count()).toBe(4);
   expect(mainView.getChartTitle(mainView.charts().get(0))).toBe('TESTING');

   // take screenshot
   browser.shot(prefixScreenshot + ' screenshot1');  

  // continue                           
});