Skip to content

Commit

Permalink
Merge pull request #147 from Evilweed/mergecssandtime
Browse files Browse the repository at this point in the history
Merge changes for time coloring and screenshots exception handling
  • Loading branch information
miller45 authored May 5, 2019
2 parents bb3a96a + 87facb0 commit 23dcbf4
Show file tree
Hide file tree
Showing 10 changed files with 1,869 additions and 1,361 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ npm-debug.log
.idea/
tmp/
.npmrc
package-lock.json

5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

## Version 1.2.8 (Not released yet)
## Version 1.2.8
* Hardend: Continue test when screenshot fails. Especially when 'target window already closed' occurs.
* Fixed: Handling of 'excluded' status with protractor 6.0.0
* Fixed: Handling of 'excluded' status with protractor 6.0.0 (but protractor still not working correctly with duration)
* Values for coloring time column now customizable

## Version 1.2.7
* Fixed: TypeError: Cannot set property 'searchSettings' of undefined
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ Default is every option is set to `true`

Default is every option except `inlineScreenshots` is set to `true`

Additionally you can customize the time values for coloring the time column.
For example if you want to mark the time orange when the test took longer than 1 second and red when the test took longer than 1.5 seconds
add the following to columnSettings (values are in milliseconds scale):
```javascript
new HtmlReporter({
baseDirectory: 'tmp/screenshots'
, clientDefaults:{
columnSettings:{
warningTime: 1000,
dangerTime: 1500
}
}
});
```

## HTML Reporter

Expand Down
4 changes: 3 additions & 1 deletion app/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ function ScreenshotReporter(options) {
if (options.columnSettings) {
this.clientDefaults.columnSettings = options.columnSettings;
}
this.customCssInline = options.customCssInline;

this.finalOptions = {
excludeSkippedSpecs: this.excludeSkippedSpecs,
Expand All @@ -207,7 +208,8 @@ function ScreenshotReporter(options) {
docName: this.docName,
cssOverrideFile: this.cssOverrideFile,
prepareAssets: true,
clientDefaults: this.clientDefaults
clientDefaults: this.clientDefaults,
customCssInline: this.customCssInline
};
if (!this.preserveDirectory) {
util.removeDirectory(this.finalOptions.baseDirectory);
Expand Down
18 changes: 12 additions & 6 deletions app/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const fse = require('fs-extra');
function storeScreenShot(data, file) {
try {
fse.outputFileSync(file, data, {encoding: 'base64'});
} catch(e) {
} catch (e) {
console.error(e);
console.error('Could not save image: ', file);
}
Expand Down Expand Up @@ -50,11 +50,17 @@ function addHTMLReport(jsonData, baseName, options) {
let cssLink = path.join('assets', 'bootstrap.css').replace(/\\/g, '/');

try {

if (options.cssOverrideFile) {
cssLink = options.cssOverrideFile;
}

if (options.prepareAssets) {
var cssInsert = `<link rel="stylesheet" href="${cssLink}">`;
if (options.customCssInline) {
cssInsert += ` <style type="text/css">${options.customCssInline}</style>`;
}

//copy assets
fse.copySync(path.join(__dirname, 'lib', 'assets'), path.join(basePath, 'assets'));

Expand All @@ -68,7 +74,7 @@ function addHTMLReport(jsonData, baseName, options) {
streamHtml.write(
fs.readFileSync(htmlInFile)
.toString()
.replace('<!-- Here will be CSS placed -->', '<link rel="stylesheet" href="' + cssLink + '">')
.replace('<!-- Here will be CSS placed -->', cssInsert)
.replace('<!-- Here goes title -->', options.docTitle)
);

Expand Down Expand Up @@ -96,7 +102,7 @@ function addHTMLReport(jsonData, baseName, options) {
);

streamJs.end();
} catch(e) {
} catch (e) {
console.error(e);
console.error('Could not save combined.js for data: ' + jsonData);
}
Expand Down Expand Up @@ -140,7 +146,7 @@ function addMetaData(test, baseName, options) {

fs.rmdirSync(lock);

} catch(e) {
} catch (e) {
console.error(e);
console.error('Could not save JSON for data: ' + test);
}
Expand All @@ -158,7 +164,7 @@ function storeMetaData(metaData, file, descriptions) {
try {
metaData.description = cleanArray(descriptions).join('|');
fse.outputJsonSync(file, metaData);
} catch(e) {
} catch (e) {
console.error(e);
console.error('Could not save meta data for ' + file);
}
Expand Down Expand Up @@ -229,7 +235,7 @@ function removeDirectory(dirPath) {
try {
files = fs.readdirSync(dirPath);
}
catch(e) {
catch (e) {
return;
}
if (files.length > 0) {
Expand Down
121 changes: 74 additions & 47 deletions examples/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,80 @@
module.exports = function(grunt) {

require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

shell: {
"options": {
stdout: true
},
"selenium": {
command: './selenium/start',
options: {
stdout: false,
async: true
}
},
"protractor_install": {
command: 'node ./node_modules/protractor/bin/webdriver-manager update'
},
"webdriver_start": {
command: 'node ./node_modules/protractor/bin/webdriver-manager start'
},
"npm_install": {
command: 'npm install'
}
},

protractor: {
options: {
keepAlive: true,
configFile: "protractor.jasmine2.conf.js"
},
singlerun: {},
auto: {
keepAlive: true,
options: {
args: {
seleniumPort: 4444
}
const fs = require('fs');
const path = require('path');
const reportsTmpPath = ('./reports-tmp');
module.exports = function (grunt) {

require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

shell: {
"options": {
stdout: true
},
"selenium": {
command: './selenium/start',
options: {
stdout: false,
async: true
}
},
"protractor_install": {
command: 'node ./node_modules/protractor/bin/webdriver-manager update'
},
"webdriver_start": {
command: 'node ./node_modules/protractor/bin/webdriver-manager start'
},
"npm_install": {
command: 'npm install'
}
},

protractor: {
options: {
keepAlive: true,
configFile: "protractor.jasmine2.conf.js"
},
singlerun: {},
auto: {
keepAlive: true,
options: {
args: {
seleniumPort: 4444
}
}
}
}
}
}

});
});


grunt.registerTask('test:e2e', ['protractor:singlerun']);
grunt.registerTask('install', ['update','shell:protractor_install']);
grunt.registerTask('update', ['shell:npm_install']);
grunt.registerTask('test:e2e', ['protractor:singlerun']);
grunt.registerTask('install', ['update', 'shell:protractor_install']);
grunt.registerTask('update', ['shell:npm_install']);
grunt.registerTask('unescape-combined-json', () => {
const CircularJSON = require('circular-json');

const dirContents = fs.readdirSync(reportsTmpPath);
for (let entry of dirContents) {
let fpath = path.resolve(reportsTmpPath, entry);
if (fs.statSync(fpath).isDirectory()) {
const jsonFile=path.join(fpath, 'combined.json');
const text = fs.readFileSync(jsonFile).toString();

if (text && text[0] === `"`) {
console.log(`unescaped combined.json in '${entry}'`);
const cs = CircularJSON.parse(text);
const obj = JSON.parse(cs);
const str = JSON.stringify(obj, null, 4);
fs.writeFileSync(jsonFile,str);
} else {//else do nothing as the file is already unescaped
console.log(`doing nothing combined json in '${entry}' is already unescaped`);
}

}
}

});

};
3 changes: 2 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
"author": "",
"license": "ISC",
"devDependencies": {
"circular-json": "^0.5.9",
"grunt": "^1.0.3",
"grunt-concurrent": "^0.5.0",
"grunt-protractor-runner": "~0.1.6",
"grunt-shell": "~0.4.0",
"grunt-shell-spawn": "~0.3.0",
"matchdep": "^2.0.0",
"protractor": "^5.1.1",
"protractor-beautiful-reporter": "^1.2.6",
"protractor-beautiful-reporter": "^1.2.7",
"selenium-webdriver": "^3.4.0",
"webdriver-manager": "^12.0.6"
}
Expand Down
Loading

0 comments on commit 23dcbf4

Please sign in to comment.