Skip to content

Commit

Permalink
Bug Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekswain committed Apr 11, 2016
1 parent 69ba7bb commit 68c3e11
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
82 changes: 48 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ protractorUtil.takeScreenshotOnExpectFail = function (context) {
if (fileName.length > 245) {
fileName = (config.capabilities.browserName + '-' + self.result.fullName).replace(/[\/\\]/g, ' ').substring(0, 230) + '-' + 'expect failure-' + protractorUtil.index++;
}
var screenshotPathUserSupplied;

if (context.config.screenshotPath) {
if (((context.config.screenshotPath.charAt(context.config.screenshotPath.length - 1)) != '/') || ((context.config.screenshotPath.charAt(context.config.screenshotPath.length - 1)) != '\\')) {
screenshotPathUserSupplied = context.config.screenshotPath + '/';
var screenshotPathUserSupplied = context.config.screenshotPath + '/';
}
}
var stream = fs.createWriteStream((screenshotPathUserSupplied ? context.config.screenshotPath.replace('./', '') : 'reports/screenshots/') + fileName + '.png');

var stream = fs.createWriteStream((screenshotPathUserSupplied ? screenshotPathUserSupplied.replace('./', '') : 'reports/screenshots/') + fileName + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();

}, function (err) {
console.log('Error while taking screenshot - ' + err.message);
});
Expand All @@ -90,14 +92,22 @@ protractorUtil.takeScreenshotOnSpecFail = function (context) {
specDone: function (result) {
if (result.failedExpectations.length > 0) {
// take screenshot
global.browser.takeScreenshot().then(function (png) {
browser.takeScreenshot().then(function (png) {
var fileName = (config.capabilities.browserName + '-' + result.fullName).replace(/[\/\\]/g, ' ');
if (fileName.length > 245) {
fileName = (config.capabilities.browserName + '-' + result.fullName).replace(/[\/\\]/g, ' ').substring(0, 230);
}
var stream = fs.createWriteStream((context.config.screenshotPath ? context.config.screenshotPath.replace('./', '') : 'reports/screenshots/') + fileName + '.png');

if (context.config.screenshotPath) {
if (((context.config.screenshotPath.charAt(context.config.screenshotPath.length - 1)) != '/') || ((context.config.screenshotPath.charAt(context.config.screenshotPath.length - 1)) != '\\')) {
var screenshotPathUserSupplied = context.config.screenshotPath + '/';
}
}

var stream = fs.createWriteStream((screenshotPathUserSupplied ? screenshotPathUserSupplied.replace('./', '') : 'reports/screenshots/') + fileName + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();

}, function (err) {
console.log('Error while taking screenshot - ' + err.message);
});
Expand Down Expand Up @@ -221,63 +231,67 @@ protractorUtil.prototype.setup = function () {
// fs.mkdirSync(reportsDir);
// }

if (this.config.clearFoldersBeforeTest) {
try {
fse.removeSync('./reports/screenshots');
} catch (err) {
console.error(err);
}
}

if (!this.config.disableScreenshot) {

//creates screenshots folder if does not exist
var screenshotDir = './reports/screenshots';
if (!fs.existsSync(screenshotDir)) {
fs.mkdirSync(screenshotDir);
}

mkdirp.sync(screenshotDir, function (err) {
if (err) console.error(err);
else console.log(htmlReportsDir + ' folder created!');
});

}

}
else {

if (this.config.clearFoldersBeforeTest) {
try {
fse.removeSync('./reports/screenshots');
fse.removeSync(this.config.screenshotPath);
} catch (err) {
console.error(err);
}
}
}
else {

mkdirp.sync(this.config.screenshotPath, function (err) {
if (err) console.error(err);
else console.log(self.config.screenshotPath + ' folder created!');
});
}


if (!this.config.htmlReportDir) {



//creates htmlReports folder if does not exist
var htmlReportsDir = './reports/htmlReports';

if (this.config.clearFoldersBeforeTest) {
try {
fse.removeSync(this.config.screenshotPath);
fse.removeSync(htmlReportsDir);
} catch (err) {
console.error(err);
}
}

if (!this.config.disableHTMLReport) {

}


if (!this.config.htmlReportDir) {
//creates reports folder if does not exist
// var reportsDir = './reports';
// if (!fs.existsSync(reportsDir)) {
// fs.mkdirSync(reportsDir);
// }
mkdirp.sync(htmlReportsDir, function (err) {
if (err) console.error(err);
else console.log(htmlReportsDir + ' folder created!');
});

if (!this.config.disableHTMLReport) {
//creates htmlReports folder if does not exist
var htmlReportsDir = './reports/htmlReports';
if (!fs.existsSync(htmlReportsDir)) {
fs.mkdirSync(htmlReportsDir);
}

if (this.config.clearFoldersBeforeTest) {
try {
fse.removeSync(htmlReportsDir);
} catch (err) {
console.error(err);
}
}
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jasmine2-protractor-utils",
"version": "1.2.4",
"version": "1.2.5",
"description": "Utilities for Protractor with jasmine2 [HTML Reports, Screenshot, Browser Console log and more]",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 68c3e11

Please sign in to comment.