diff --git a/README.md b/README.md index e8084f5f..1f6b5f50 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,33 @@ - `git pull` - `npm install` - `bower install` + + + +### Tests + +## Unit Frontend + +- `brew install phantomjs` +- `gulp karma` + +## E2E Frontend + +### On first run +- `gulp webdriver-update` + +### Chrome Local STF +- Connect a device +- Run stf +- `gulp protractor` + +### Multiple Browsers Local STF with a specific suite +- Connect a device +- Run stf +- `gulp protractor --multi --suite devices` + +### Chrome Remote STF +- `export STF_URL='http://stf-url/#!/'` +- `export STF_USERNAME='user'` +- `export STF_PASSWORD='pass'` +- `gulp protractor` diff --git a/gulpfile.js b/gulpfile.js index c6b1d9d3..0a3860a3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,18 +9,18 @@ var webpackStatusConfig = require('./res/common/status/webpack.config') var gettext = require('gulp-angular-gettext') var jade = require('gulp-jade') var clean = require('gulp-clean') -var protractor = require("gulp-protractor") +//var protractor = require('gulp-protractor') +var protractor = require('./res/test/e2e/helpers/gulp-protractor-adv') +var protractorConfig = './res/test/protractor.conf' var karma = require('karma').server var karmaConfig = '/res/test/karma.conf.js' var stream = require('stream') +var spawn = require('child_process').spawn gulp.task('jshint', function () { return gulp.src([ - 'lib/**/*.js' - , 'res/app/**/*.js' - , 'res/auth-ldap/**/*.js' - , 'res/auth-mock/**/*.js' - , '*.js' + 'lib/**/*.js', 'res/app/**/*.js', 'res/auth-ldap/**/*.js', + 'res/auth-mock/**/*.js', '*.js' ]) .pipe(jshint()) .pipe(jshint.reporter('jshint-stylish')) @@ -28,11 +28,7 @@ gulp.task('jshint', function () { gulp.task('jsonlint', function () { return gulp.src([ - '.jshintrc' - , 'res/.jshintrc' - , '.bowerrc' - , '.yo-rc.json' - , '*.json' + '.jshintrc', 'res/.jshintrc', '.bowerrc', '.yo-rc.json', '*.json' ]) .pipe(jsonlint()) .pipe(jsonlint.reporter()) @@ -57,28 +53,22 @@ gulp.task('karma', function (done) { gulp.task('webdriver-update', protractor.webdriver_update) gulp.task('webdriver-standalone', protractor.webdriver_standalone) +gulp.task('protractor-explorer', function (callback) { + protractor.protractor_explorer({ + url: 'http://yahoo.com' + }, callback) +}) + +if (gutil.env.multi) { + protractorConfig = './res/test/protractor-multi.conf' +} gulp.task('protractor', function (callback) { - var protractorConfig = './res/test/protractor.conf' - - var args = [] - if (typeof gutil.env.suite === 'string') { - args.push('--suite') - args.push(gutil.env.suite) - } - - if (gutil.env.debug) { - args.push('debug') - } - - if (gutil.env.multi) { - protractorConfig = './res/test/protractor-multi.conf' - } - gulp.src(["./res/test/e2e/**/*.js"]) .pipe(protractor.protractor({ configFile: protractorConfig, - args: args + debug: gutil.env.debug, + suite: gutil.env.suite })) .on('error', function (e) { console.log(e) @@ -87,7 +77,7 @@ gulp.task('protractor', function (callback) { // For piping strings function fromString(filename, string) { - var src = stream.Readable({ objectMode: true }) + var src = stream.Readable({objectMode: true}) src._read = function () { this.push(new gutil.File({ cwd: '', base: '', path: filename, contents: new Buffer(string) @@ -162,8 +152,7 @@ gulp.task('translate', ['jade', 'translate:extract', 'translate:compile']) gulp.task('jade', function (cb) { gulp.src([ - './res/**/*.jade' - , '!./res/bower_components/**' + './res/**/*.jade', '!./res/bower_components/**' ]) .pipe(jade()) .pipe(gulp.dest('./tmp/html/')) @@ -172,10 +161,8 @@ gulp.task('jade', function (cb) { gulp.task('translate:extract', ['jade'], function (cb) { gulp.src([ - './tmp/html/**/*.html' - , './res/**/*.js' - , '!./res/bower_components/**' - , '!./res/build/**' + './tmp/html/**/*.html', './res/**/*.js', '!./res/bower_components/**', + '!./res/build/**' ]) .pipe(gettext.extract('stf.pot')) .pipe(gulp.dest('./res/common/lang/po/')) diff --git a/res/test/e2e/helpers/gulp-protractor-adv.js b/res/test/e2e/helpers/gulp-protractor-adv.js new file mode 100644 index 00000000..42bc8450 --- /dev/null +++ b/res/test/e2e/helpers/gulp-protractor-adv.js @@ -0,0 +1,175 @@ +/* This is a fork of https://github.com/mllrsohn/gulp-protractor + + Changes: + - Added debug support + - Added suites support + - Added element explorer support + + */ + +var es = require('event-stream') +var fs = require('fs') +var path = require('path') +var child_process = require('child_process') +var async = require('async') +var PluginError = require('gulp-util').PluginError +var winExt = /^win/.test(process.platform) ? ".cmd" : "" + +// optimization: cache for protractor binaries directory +var protractorDir = null + +function getProtractorDir() { + if (protractorDir) { + return protractorDir + } + var result = require.resolve("protractor") + if (result) { + // result is now something like + // c:\\Source\\gulp-protractor\\node_modules\\protractor\\lib\\protractor.js + protractorDir = + path.resolve(path.join(path.dirname(result), "..", "..", ".bin")) + return protractorDir + } + throw new Error("No protractor installation found.") +} + +var protractor = function (options) { + var files = [], + child, args + + options = options || {} + args = options.args || [] + + if (!options.configFile) { + this.emit('error', new PluginError('gulp-protractor', + 'Please specify the protractor config file')) + } + return es.through(function (file) { + files.push(file.path) + }, function () { + var stream = this + + // Enable debug mode + if (options.debug) { + args.push('debug') + } + + // Enable test suits + if (options.suite) { + args.push('--suite') + args.push(options.suite) + } + + // Attach Files, if any + if (files.length) { + args.push('--specs') + args.push(files.join(',')) + } + + // Pass in the config file + args.unshift(options.configFile) + + child = + child_process.spawn(path.resolve(getProtractorDir() + '/protractor' + + winExt), args, { + stdio: 'inherit', + env: process.env + }).on('exit', function (code) { + if (child) { + child.kill() + } + if (stream) { + if (code) { + stream.emit('error', new PluginError('gulp-protractor', + 'protractor exited with code ' + code)) + } + else { + stream.emit('end') + } + } + }) + }) +} + +var webdriver_update = function (opts, cb) { + var callback = (cb ? cb : opts) + var options = (cb ? opts : null) + var args = ["update", "--standalone"] + if (options) { + if (options.browsers) { + options.browsers.forEach(function (element, index, array) { + args.push("--" + element) + }) + } + } + child_process.spawn(path.resolve(getProtractorDir() + '/webdriver-manager' + + winExt), args, { + stdio: 'inherit' + }).once('close', callback) +} + +var webdriver_update_specific = function (opts) { + return webdriver_update.bind(this, opts) +} + +webdriver_update.bind(null, ["ie", "chrome"]) + +var webdriver_standalone = function (cb) { + var child = child_process.spawn(path.resolve(getProtractorDir() + + '/webdriver-manager' + winExt), ['start'], { + stdio: 'inherit' + }).once('close', cb) +} + +var protractorExplorerDir = null +function getProtractorExplorerDir() { + if (protractorExplorerDir) { + return protractorExplorerDir + } + var result = require.resolve("protractor") + if (result) { + // result is now something like + // c:\\Source\\gulp-protractor\\node_modules\\protractor\\lib\\protractor.js + protractorExplorerDir = + path.resolve(path.join(path.dirname(result), "..", "bin")) + return protractorExplorerDir + } + throw new Error("No protractor installation found.") +} + +var protractor_explorer = function (opts, cb) { + var callback = (cb ? cb : opts) + var options = (cb ? opts : null) + var url = 'https://angularjs.org/' + + if (options) { + if (options.configFile) { + var configFile = require(options.configFile) + if (configFile.config && configFile.config.baseUrl) { + url = configFile.config.baseUrl + } + } + + if (options.url) { + url = options.url + } + + if (!options.launchWebDriver) { + + } + } + + child_process.spawn(path.resolve(getProtractorExplorerDir() + + '/elementexplorer.js'), [url], { + stdio: 'inherit' + }).once('close', callback) +} + +module.exports = { + getProtractorDir: getProtractorDir, + protractor: protractor, + webdriver_standalone: webdriver_standalone, + webdriver_update: webdriver_update, + webdriver_update_specific: webdriver_update_specific, + protractor_explorer: protractor_explorer +}