jeevan s
jeevan s

Reputation: 223

Unable to generate report using html screen shot in protractor

I'm trying to generate reports using html screen shot in protractor, have followed all the steps, but am getting an error. Please help.

My conf.js

// An example configuration file.
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter=new HtmlReporter({
    baseDirectory: './protractor-result', // a location to store screen shots.
    docTitle: 'Protractor Demo Reporter',
    docName:    'protractor-demo-tests-report.html'
});
exports.config = {
  directConnect: true,

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  // Spec patterns are relative to the current working directly when
  // protractor is called.
  specs: ['example_spec.js'],

  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000
  }

  onPrepare: function() {
        jasmine.getEnv().addReporter(reporter),
    };
};

Error I'm getting: Unexpected Error.

SyntaxError: Unexpected identifier
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at ConfigParser.addFileConfig (C:\Users\jeevan.s\AppData\Roaming\npm\node_modules\protractor\lib\configParser.js:183:20)
    at Object.init (C:\Users\jeevan.s\AppData\Roaming\npm\node_modules\protractor\lib\launcher.js:35:18)
    at Object.<anonymous> (C:\Users\jeevan.s\AppData\Roaming\npm\node_modules\protractor\lib\cli.js:129:23)
    at Module._compile (module.js:456:26)

Upvotes: 3

Views: 3071

Answers (2)

tony2tones
tony2tones

Reputation: 1670

This particular site assisted me alot https://www.npmjs.com/package/protractor-jasmine2-html-reporter

This fix also added a savePath.

What I did was Added the following var to the Conf.js file and updated the Framework: to 'Jasmine2' and the following, this is my complete conf.js file:

// conf.js
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');

exports.config = {
    framework: 'jasmine2',
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['*.js'],
    onPrepare: function() {
        jasmine.getEnv().addReporter(
            new Jasmine2HtmlReporter({
                savePath: 'target/screenshots'
            })
        );
    }
}

Upvotes: 0

alecxe
alecxe

Reputation: 473873

You have syntax errors:

  • missing , before the onPrepare():
  • replace , with ; after the addReporter() call
  • remove the ; after onPrepare()

Fixed version:

// An example configuration file.
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter=new HtmlReporter({
    baseDirectory: './protractor-result', // a location to store screen shots.
    docTitle: 'Protractor Demo Reporter',
    docName:    'protractor-demo-tests-report.html'
});
exports.config = {
    directConnect: true,

    // Capabilities to be passed to the webdriver instance.
    capabilities: {
        'browserName': 'chrome'
    },

    // Spec patterns are relative to the current working directly when
    // protractor is called.
    specs: ['example_spec.js'],

    // Options to be passed to Jasmine-node.
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000
    },

    onPrepare: function() {
        jasmine.getEnv().addReporter(reporter);
    }
};

Upvotes: 3

Related Questions