1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 02:09:32 +02:00

- Forked gulp-protractor .

Changes:
 - Added debug support
 - Added suites support
 - Added element explorer support
This commit is contained in:
Gunther Brunner 2014-08-27 16:36:37 +09:00
parent 5941030743
commit 30bbf430d3
3 changed files with 227 additions and 35 deletions

View file

@ -27,3 +27,33 @@
- `git pull` - `git pull`
- `npm install` - `npm install`
- `bower 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`

View file

@ -9,18 +9,18 @@ var webpackStatusConfig = require('./res/common/status/webpack.config')
var gettext = require('gulp-angular-gettext') var gettext = require('gulp-angular-gettext')
var jade = require('gulp-jade') var jade = require('gulp-jade')
var clean = require('gulp-clean') 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 karma = require('karma').server
var karmaConfig = '/res/test/karma.conf.js' var karmaConfig = '/res/test/karma.conf.js'
var stream = require('stream') var stream = require('stream')
var spawn = require('child_process').spawn
gulp.task('jshint', function () { gulp.task('jshint', function () {
return gulp.src([ return gulp.src([
'lib/**/*.js' 'lib/**/*.js', 'res/app/**/*.js', 'res/auth-ldap/**/*.js',
, 'res/app/**/*.js' 'res/auth-mock/**/*.js', '*.js'
, 'res/auth-ldap/**/*.js'
, 'res/auth-mock/**/*.js'
, '*.js'
]) ])
.pipe(jshint()) .pipe(jshint())
.pipe(jshint.reporter('jshint-stylish')) .pipe(jshint.reporter('jshint-stylish'))
@ -28,11 +28,7 @@ gulp.task('jshint', function () {
gulp.task('jsonlint', function () { gulp.task('jsonlint', function () {
return gulp.src([ return gulp.src([
'.jshintrc' '.jshintrc', 'res/.jshintrc', '.bowerrc', '.yo-rc.json', '*.json'
, 'res/.jshintrc'
, '.bowerrc'
, '.yo-rc.json'
, '*.json'
]) ])
.pipe(jsonlint()) .pipe(jsonlint())
.pipe(jsonlint.reporter()) .pipe(jsonlint.reporter())
@ -57,28 +53,22 @@ gulp.task('karma', function (done) {
gulp.task('webdriver-update', protractor.webdriver_update) gulp.task('webdriver-update', protractor.webdriver_update)
gulp.task('webdriver-standalone', protractor.webdriver_standalone) gulp.task('webdriver-standalone', protractor.webdriver_standalone)
gulp.task('protractor-explorer', function (callback) {
gulp.task('protractor', function (callback) { protractor.protractor_explorer({
var protractorConfig = './res/test/protractor.conf' url: 'http://yahoo.com'
}, callback)
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) { if (gutil.env.multi) {
protractorConfig = './res/test/protractor-multi.conf' protractorConfig = './res/test/protractor-multi.conf'
} }
gulp.task('protractor', function (callback) {
gulp.src(["./res/test/e2e/**/*.js"]) gulp.src(["./res/test/e2e/**/*.js"])
.pipe(protractor.protractor({ .pipe(protractor.protractor({
configFile: protractorConfig, configFile: protractorConfig,
args: args debug: gutil.env.debug,
suite: gutil.env.suite
})) }))
.on('error', function (e) { .on('error', function (e) {
console.log(e) console.log(e)
@ -162,8 +152,7 @@ gulp.task('translate', ['jade', 'translate:extract', 'translate:compile'])
gulp.task('jade', function (cb) { gulp.task('jade', function (cb) {
gulp.src([ gulp.src([
'./res/**/*.jade' './res/**/*.jade', '!./res/bower_components/**'
, '!./res/bower_components/**'
]) ])
.pipe(jade()) .pipe(jade())
.pipe(gulp.dest('./tmp/html/')) .pipe(gulp.dest('./tmp/html/'))
@ -172,10 +161,8 @@ gulp.task('jade', function (cb) {
gulp.task('translate:extract', ['jade'], function (cb) { gulp.task('translate:extract', ['jade'], function (cb) {
gulp.src([ gulp.src([
'./tmp/html/**/*.html' './tmp/html/**/*.html', './res/**/*.js', '!./res/bower_components/**',
, './res/**/*.js' '!./res/build/**'
, '!./res/bower_components/**'
, '!./res/build/**'
]) ])
.pipe(gettext.extract('stf.pot')) .pipe(gettext.extract('stf.pot'))
.pipe(gulp.dest('./res/common/lang/po/')) .pipe(gulp.dest('./res/common/lang/po/'))

View file

@ -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
}