I'm using protractor html reporter 2 for my reporting. I need to get spec name as html report output file name.
i'm using the below code in my config file.
var today = new Date(),
timeStamp = today.getMonth() + 1 + '-' + today.getDate() + '-' + today.getFullYear();
onPrepare:
function ()
{
browser.driver.manage().window().maximize();
var fs = require('fs-extra');
scriptName=function(){
return browser.getProcessedConfig().then(function(config){
return config.specs;
});
};
fs.emptyDir('./target/htmlReports/'+scriptName+'-'+timeStamp+'/screenShots/', function (err) {
console.log(err);
});
jasmine.getEnv().addReporter({
specDone: function(result) {
//if (result.status == 'failed' || result.status == 'passed') {
if (1==1) {
browser.getCapabilities().then(function (caps) {
var browserName = userData.testUser.browser.toUpperCase();
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream('./target/htmlReports/'+scriptName+'-'+timeStamp+'/screenShots/'+ result.fullName+'.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
});
});
}
}
});
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'target/XMLReports',
filePrefix: 'xmlresults'
}));
},
onComplete: function() {
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function (caps) {
browserName = userData.testUser.browser.toUpperCase();
platform=caps.get('platform');
browserVersion = caps.get('version');
testConfig = {
reportTitle: 'Test Execution Report',
outputPath: './target/htmlReports/'+scriptName+'-'+timeStamp,
screenshotPath: './target/htmlReports/'+scriptName+'-'+timeStamp+'/screenShots',
testBrowser: browserName,
browserVersion: browserVersion,
outputFilename:'ProtractorTestReport',
testPlatform: platform,
//browserVersion: browserVersion,
modifiedSuiteName: true,
screenshotsOnlyOnFailure: false
};
new HTMLReport().from('./target/XMLReports/xmlresults.xml', testConfig);
});
},
plugins: [{
package: 'jasmine2-protractor-utils',
disableHTMLReport: true,
disableScreenshot: false,
screenshotPath:'./target/htmlReports/'+scriptName+'-'+timeStamp+'/screenShots',
screenshotOnExpectFailure:true,
screenshotOnSpecFailure:true,
clearFoldersBeforeTest: true,
htmlReportDir: './target/htmlReports'
}],
i tried with
browser.getProcessedConfig().then(function(config){
console.log(config.specs);
});
,it returns
[ 'D:\projects\HeartlandSSP\Automation\TenantManagement\Ssp.TenantManagement.Protractor_Test\specs\createTenantSpec.js', 'C:\Users\renusri.rajalingam\AppData\Roaming\npm\node_modules\protractor\built\frameworks\__protractor_internal_afterEach_setup_spec.js' ]
but the actual spec name createTenantSpec.js is not returning. I need only the filename of the spec and not the name of the describe or it functions. Since I have 5 specs, i need to generate separate report with its spec name. Can anyone please help me on this?