Skip to content

Commit

Permalink
End2end testing (prebid#571)
Browse files Browse the repository at this point in the history
* End to end testing using nightwatch

* End2end testing results in webpage

* Added missing files

* Adding custom assertions folder with dummy template

* Moved extra code to gulp helpers

* Bug fix - now accesing proper url
  • Loading branch information
jaiminpanchal27 authored and Nate Guisinger committed Sep 1, 2016
1 parent 5964907 commit cda1382
Show file tree
Hide file tree
Showing 20 changed files with 2,564 additions and 200 deletions.
198 changes: 198 additions & 0 deletions browsers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
{
"bs_ie_13_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "edge",
"browser_version": "13.0",
"device": null,
"os": "Windows"
},
"bs_ie_11_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "ie",
"browser_version": "11.0",
"device": null,
"os": "Windows"
},
"bs_firefox_46_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "firefox",
"browser_version": "46.0",
"device": null,
"os": "Windows"
},
"bs_chrome_51_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "chrome",
"browser_version": "51.0",
"device": null,
"os": "Windows"
},
"bs_ie_11_windows_8.1": {
"base": "BrowserStack",
"os_version": "8.1",
"browser": "ie",
"browser_version": "11.0",
"device": null,
"os": "Windows"
},
"bs_firefox_46_windows_8.1": {
"base": "BrowserStack",
"os_version": "8.1",
"browser": "firefox",
"browser_version": "46.0",
"device": null,
"os": "Windows"
},
"bs_chrome_51_windows_8.1": {
"base": "BrowserStack",
"os_version": "8.1",
"browser": "chrome",
"browser_version": "51.0",
"device": null,
"os": "Windows"
},
"bs_ie_10_windows_8": {
"base": "BrowserStack",
"os_version": "8",
"browser": "ie",
"browser_version": "10.0",
"device": null,
"os": "Windows"
},
"bs_firefox_46_windows_8": {
"base": "BrowserStack",
"os_version": "8",
"browser": "firefox",
"browser_version": "46.0",
"device": null,
"os": "Windows"
},
"bs_chrome_51_windows_8": {
"base": "BrowserStack",
"os_version": "8",
"browser": "chrome",
"browser_version": "51.0",
"device": null,
"os": "Windows"
},
"bs_ie_11_windows_7": {
"base": "BrowserStack",
"os_version": "7",
"browser": "ie",
"browser_version": "11.0",
"device": null,
"os": "Windows"
},
"bs_ie_10_windows_7": {
"base": "BrowserStack",
"os_version": "7",
"browser": "ie",
"browser_version": "10.0",
"device": null,
"os": "Windows"
},
"bs_ie_9_windows_7": {
"base": "BrowserStack",
"os_version": "7",
"browser": "ie",
"browser_version": "9.0",
"device": null,
"os": "Windows"
},
"bs_firefox_46_windows_7": {
"base": "BrowserStack",
"os_version": "7",
"browser": "firefox",
"browser_version": "46.0",
"device": null,
"os": "Windows"
},
"bs_chrome_51_windows_7": {
"base": "BrowserStack",
"os_version": "7",
"browser": "chrome",
"browser_version": "51.0",
"device": null,
"os": "Windows"
},
"bs_safari_9.1_mac_elcapitan": {
"base": "BrowserStack",
"os_version": "El Capitan",
"browser": "safari",
"browser_version": "9.1",
"device": null,
"os": "OS X"
},
"bs_firefox_46_mac_elcapitan": {
"base": "BrowserStack",
"os_version": "El Capitan",
"browser": "firefox",
"browser_version": "46.0",
"device": null,
"os": "OS X"
},
"bs_chrome_51_mac_elcapitan": {
"base": "BrowserStack",
"os_version": "El Capitan",
"browser": "chrome",
"browser_version": "51.0",
"device": null,
"os": "OS X"
},
"bs_safari_8_mac_yosemite": {
"base": "BrowserStack",
"os_version": "Yosemite",
"browser": "safari",
"browser_version": "8.0",
"device": null,
"os": "OS X"
},
"bs_firefox_46_mac_yosemite": {
"base": "BrowserStack",
"os_version": "Yosemite",
"browser": "firefox",
"browser_version": "46.0",
"device": null,
"os": "OS X"
},
"bs_chrome_51_mac_yosemite": {
"base": "BrowserStack",
"os_version": "Yosemite",
"browser": "chrome",
"browser_version": "51.0",
"device": null,
"os": "OS X"
},
"bs_safari_7.1_mac_mavericks": {
"base": "BrowserStack",
"os_version": "Mavericks",
"browser": "safari",
"browser_version": "7.1",
"device": null,
"os": "OS X"
},
"bs_firefox_46_mac_mavericks": {
"base": "BrowserStack",
"os_version": "Mavericks",
"browser": "firefox",
"browser_version": "46.0",
"device": null,
"os": "OS X"
},
"bs_chrome_49_mac_mavericks": {
"base": "BrowserStack",
"os_version": "Mavericks",
"browser": "chrome",
"browser_version": "49.0",
"device": null,
"os": "OS X"
},
"Chrome_travis_ci": {
"base": "Chrome",
"flags": ["--no-sandbox"]
}
}
61 changes: 60 additions & 1 deletion gulpHelpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const fs = require('fs');
// this will have all of a copy of the normal fs methods as well
const fs = require('fs.extra');
const path = require('path');
const argv = require('yargs').argv;
const MANIFEST = 'package.json';
const exec = require('child_process').exec;

module.exports = {
parseBrowserArgs: function (argv) {
Expand Down Expand Up @@ -47,5 +49,62 @@ module.exports = {
}
catch (error) {}
}
},

createEnd2EndTestReport : function(targetDestinationDir) {
var browsers = require('./browsers.json');
var env = ['default'];
var input = 'bs';
for(var key in browsers) {
if(key.substring(0, input.length) === input) {
env.push(key);
}
}

//create new directory structure
fs.rmrfSync(targetDestinationDir);
env.forEach(item => {
fs.mkdirpSync(targetDestinationDir + '/' + item);
});

//move xml files to newly created directory
var walker = fs.walk('./build/coverage/e2e/reports');
walker.on("file", function (root, stat, next) {
env.forEach(item => {
if(stat.name.search(item) !== -1) {
var src = root + '/' + stat.name;
var dest = targetDestinationDir + '/' + item + '/' + stat.name;
fs.copy(src, dest, {replace: true}, function(err) {
if(err) {
throw err;
}
});
}
});
next();
});

//run junit-viewer to read xml and create html
env.forEach(item => {
//junit-viewer --results="./custom-reports/chrome51" --save="./chrome.html"
var cmd = 'junit-viewer --results="' + targetDestinationDir + '/' + item + '" --save="' + targetDestinationDir + '/' + item +'.html"';
exec(cmd);
});

//create e2e-results.html
var html = '<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>End to End Testing Result</title><link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"><script src="https://code.jquery.com/jquery-1.12.4.js"></script><script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script><script>$( function() {$( "#tabs" ).tabs({heightStyle: "fill"});});</script></head><body><div style="font-weight: bold;">Note: Refresh in 2-3 seconds if it says "Cannot get ....."</div><div id="tabs" style="height:2000px;">';
var li = '';
var tabs = '';
env.forEach(function(item,i) {
i++;
li = li + '<li><a href="#tabs-'+i+'">'+item+'</a></li>';
tabs = tabs + '<div id="tabs-'+i+'"><iframe name="'+item+'" src="/' + targetDestinationDir.slice(2) + '/'+item+'.html" frameborder="0" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:100%;width:100%;top:50px;left:0px;right:0px;bottom:0px" height="100%" width="100%"></iframe></div>';
});
html = html + '<ul>' + li + '</ul>' + tabs;
html = html + '</div></body></html>';

var filepath = targetDestinationDir + '/results.html';
fs.openSync(filepath, 'w+');
fs.writeFileSync(filepath, html);
}
};
49 changes: 48 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ var dateString = 'Updated : ' + (new Date()).toISOString().substring(0, 10);
var packageNameVersion = prebid.name + '_' + prebid.version;
var banner = '/* <%= prebid.name %> v<%= prebid.version %>\n' + dateString + ' */\n';
var analyticsDirectory = '../analytics';
var port = 9999;

// Tasks
gulp.task('default', ['clean', 'quality', 'webpack']);

gulp.task('serve', ['clean', 'quality', 'devpack', 'webpack', 'watch', 'test']);

gulp.task('serve-nw', ['clean', 'quality', 'devpack', 'webpack', 'watch', 'e2etest']);

gulp.task('run-tests', ['clean', 'quality', 'webpack', 'test']);

gulp.task('build', ['clean', 'quality', 'webpack', 'devpack', 'zip']);
Expand Down Expand Up @@ -155,7 +158,7 @@ gulp.task('watch', function () {
gulp.watch(['integrationExamples/gpt/*.html'], ['test']);
gulp.watch(['src/**/*.js'], ['quality', 'webpack', 'devpack', 'test']);
connect.server({
port: 9999,
port: port,
root: './',
livereload: true
});
Expand Down Expand Up @@ -191,3 +194,47 @@ gulp.task('docs', ['clean-docs'], function () {
})
.pipe(gulp.dest('docs'));
});

gulp.task('e2etest', function() {
var cmd = '--env default';
if(argv.browserstack) {
var browsers = require('./browsers.json');
var env = [];
var input = 'bs';
for(var key in browsers) {
if(key.substring(0, input.length) === input) {
env.push(key);
}
}
cmd = '--env default,' + env.join(',');
}

if(argv.browserstack) {
cmd = cmd + ' --config nightwatch.conf.js';
} else {
cmd = cmd + ' --config nightwatch.json';
}

if (argv.group) {
cmd = cmd + ' --group ' + argv.group;
}

cmd = cmd + ' --reporter ./test/spec/e2e/custom-reporter/pbjs-html-reporter.js';
return gulp.src('')
.pipe(shell('nightwatch ' + cmd));
});

gulp.task('e2etest-report', function() {
var targetDestinationDir = './e2etest-report';
helpers.createEnd2EndTestReport(targetDestinationDir);
connect.server({
port: port,
root: './',
livereload: true
});

setTimeout(function() {
opens('http://localhost:' + port + '/' + targetDestinationDir.slice(2) + '/results.html');
}, 5000);

});
Loading

0 comments on commit cda1382

Please sign in to comment.