user6690217 user6690217 - 3 months ago 52
JSON Question

Generating JSON object of the tests ran using Protractor?

I'm relatively new to end to end testing with

Protractor
,
Mocha
and
Yadda
(for integration with
Mocha
so I can use
Gherkin
and step definitions).

I've seen a plugin called
Mochawesome
which generates an HTML report which can be viewed offline, along with this JSON object of the test results, all of which contained in a 'reports' folder.

I presume it's
Mochawesome
which generates these JSON objects as the HTML page seems to have corresponding tags etc. Is there any way to generate a JSON object of the tests ran without the HTML reporter? The idea was to create my own sort of 'dashboard' containing information about the tests based on the JSON information.

Answer

Yes you can create a JSON report of your specs/tests with protractor.You just have to put resultJsonOutputFile: './Report.json' in your config file.

your config file should somewhat look like this:

exports.config = {

directConnect: true, 
capabilities: {
    'browserName': 'chrome'
},
baseUrl: 'http://juliemr.github.io/protractor-demo/', 
framework: 'jasmine2', 
specs: ['*spec.js '], 
allScriptsTimeout: 180000, 
getPageTimeout: 180000, 
jasmineNodeOpts: {
    defaultTimeoutInterval: 180000
},
 resultJsonOutputFile: './Report.json', // It would create report.json file in your current folder
 onPrepare: function () {

    browser.driver.manage().window().maximize();
    browser.ignoreSynchronization = true;
}
};

You can consume this json report and use it in your way!

Comments