From e87dc45fb9963e8c1c1f647d9ade55cce69c538d Mon Sep 17 00:00:00 2001 From: Gunther Brunner Date: Tue, 26 Aug 2014 20:57:26 +0900 Subject: [PATCH] - e2e tests should work with production now also by exporting STF_URL, STF_USERNAME and STF_PASSWORD. - Added BrowerLogs, a Protractor helper which redirects browser logs to the console, with an additional expectNoLogs option. - Refactored Login model names to work seamlessly. --- gulpfile.js | 16 +++++---- .../mock/scripts/controllers/SignInCtrl.js | 2 +- res/auth/mock/views/partials/signin.jade | 4 +-- res/test/e2e/devices/devices-spec.js | 6 +++- res/test/e2e/helpers/browser-logs.js | 36 +++++++++++++++++++ res/test/e2e/login/index.js | 32 +++++++++++------ res/test/e2e/login/login-spec.js | 11 +++--- res/test/protractor.conf.js | 27 ++++++++++++-- 8 files changed, 104 insertions(+), 30 deletions(-) create mode 100644 res/test/e2e/helpers/browser-logs.js diff --git a/gulpfile.js b/gulpfile.js index 4b4393bf..3236c4e3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -56,14 +56,18 @@ gulp.task('karma', function (done) { }, done) }) -gulp.task('webdriver_update', protractor.webdriver_update) -gulp.task('webdriver_standalone', protractor.webdriver_standalone) +gulp.task('webdriver-update', protractor.webdriver_update) +gulp.task('webdriver-standalone', protractor.webdriver_standalone) gulp.task('protractor', function (callback) { - var args - var suite = gutil.env.suite - if (typeof suite === 'string') { - args = ['--suite', suite] + var args = [] + if (typeof gutil.env.suite === 'string') { + args.push('--suite') + args.push(gutil.env.suite) + } + + if (gutil.env.debug) { + args.push('debug') } gulp.src(["./res/test/e2e/**/*.js"]) diff --git a/res/auth/mock/scripts/controllers/SignInCtrl.js b/res/auth/mock/scripts/controllers/SignInCtrl.js index 7df60837..fc969175 100644 --- a/res/auth/mock/scripts/controllers/SignInCtrl.js +++ b/res/auth/mock/scripts/controllers/SignInCtrl.js @@ -4,7 +4,7 @@ define(['./module'], function(mod) { $scope.submit = function() { var data = { - name: $scope.signin.name.$modelValue + name: $scope.signin.username.$modelValue , email: $scope.signin.email.$modelValue } $scope.invalid = false diff --git a/res/auth/mock/views/partials/signin.jade b/res/auth/mock/views/partials/signin.jade index 8502b8aa..54b6f56a 100644 --- a/res/auth/mock/views/partials/signin.jade +++ b/res/auth/mock/views/partials/signin.jade @@ -13,9 +13,9 @@ .input-group span.input-group-addon i.fa.fa-user - input.form-control(ng-model='name', name='name', required, type='text', placeholder='Name', + input.form-control(ng-model='username', name='username', required, type='text', placeholder='Name', autocorrect='off', autocapitalize='off', spellcheck='false', autocomplete='section-login username') - .alert.alert-warning(ng-show='signin.name.$dirty && signin.name.$invalid') + .alert.alert-warning(ng-show='signin.username.$dirty && signin.username.$invalid') span Please enter your name .form-group diff --git a/res/test/e2e/devices/devices-spec.js b/res/test/e2e/devices/devices-spec.js index d83fdc98..5a277fd8 100644 --- a/res/test/e2e/devices/devices-spec.js +++ b/res/test/e2e/devices/devices-spec.js @@ -1,5 +1,5 @@ describe('Device Page', function () { - describe('List', function () { + describe('Icon View', function () { var DeviceListPage = require('./') var deviceListPage = new DeviceListPage() @@ -29,4 +29,8 @@ describe('Device Page', function () { }) }) + + describe('List View', function () { + + }) }) diff --git a/res/test/e2e/helpers/browser-logs.js b/res/test/e2e/helpers/browser-logs.js new file mode 100644 index 00000000..c8f9f5e6 --- /dev/null +++ b/res/test/e2e/helpers/browser-logs.js @@ -0,0 +1,36 @@ +var chalk = require('chalk') + +// http://stackoverflow.com/questions/7157999/output-jasmine-test-results-to-the-console +// https://github.com/pivotal/jasmine/blob/master/src/console/ConsoleReporter.js + +module.exports = function BrowserLogs(options) { + options = options || {} + + if (typeof options.expectNoLogs === 'undefined') { + options.expectNoLogs = false + } + if (typeof options.outputLogs === 'undefined') { + options.outputLogs = true + } + + browser.getCapabilities().then(function (cap) { + var browserName = ' ' + cap.caps_.browserName + ' log ' + var browserStyled = chalk.bgBlue.white.bold(browserName) + ' ' + + browser.manage().logs().get('browser').then(function (browserLogs) { + if (options.expectNoLogs) { + expect(browserLogs.length).toEqual(0) + } + + if (options.outputLogs && browserLogs.length) { + browserLogs.forEach(function (log) { + if (log.level.value > 900) { + console.error(browserStyled + chalk.white.bold(log.message)) + } else { + console.log(browserStyled + chalk.white.bold(log.message)) + } + }) + } + }) + }) +} diff --git a/res/test/e2e/login/index.js b/res/test/e2e/login/index.js index c827d691..e0530018 100644 --- a/res/test/e2e/login/index.js +++ b/res/test/e2e/login/index.js @@ -1,13 +1,19 @@ -var loginBaseUrl = 'http://localhost:7120' - module.exports = function LoginPage() { + this.login = protractor.getInstance().params.login + this.get = function () { - return browser.get(loginBaseUrl) + return browser.get(this.login.url) } - this.name = element(by.model('name')) - this.email = element(by.model('email')) - this.setName = function (name) { - return this.name.sendKeys(name) + this.username = element(by.model('username')) + + if (this.login.method === 'ldap') { + this.password = element(by.model('password')) + } else { + this.email = element(by.model('email')) + } + + this.setName = function (username) { + return this.username.sendKeys(username) } this.setEmail = function (email) { return this.email.sendKeys(email) @@ -16,12 +22,16 @@ module.exports = function LoginPage() { return this.password.sendKeys(password) } this.submit = function () { - return this.name.submit() + return this.username.submit() } - this.login = function () { + this.doLogin = function () { this.get() - this.setName('test_user') - this.setEmail('test_user@login.local') + this.setName(this.login.username) + if (this.login.method === 'ldap') { + this.setPassword(this.login.password) + } else { + this.setEmail(this.login.email) + } return this.submit() } } diff --git a/res/test/e2e/login/login-spec.js b/res/test/e2e/login/login-spec.js index 8ac13137..778022e7 100644 --- a/res/test/e2e/login/login-spec.js +++ b/res/test/e2e/login/login-spec.js @@ -2,13 +2,12 @@ describe('Login Page', function () { var LoginPage = require('./') var loginPage = new LoginPage() - it('should login with auth-mock', function () { - loginPage.get() + it('should have an url to login', function () { + expect(loginPage.login.url).toMatch('http') + }) - loginPage.setName('test_user') - loginPage.setEmail('test_user@test.local') - - loginPage.submit().then(function () { + it('should login with method: "' + loginPage.login.method + '"', function () { + loginPage.doLogin().then(function () { browser.getLocationAbsUrl().then(function (newUrl) { expect(newUrl).toBe(protractor.getInstance().baseUrl + 'devices') }) diff --git a/res/test/protractor.conf.js b/res/test/protractor.conf.js index ca325759..da2eba65 100644 --- a/res/test/protractor.conf.js +++ b/res/test/protractor.conf.js @@ -1,8 +1,9 @@ // Reference: https://github.com/angular/protractor/blob/master/referenceConf.js var LoginPage = require('./e2e/login') +var BrowserLogs = require('./e2e/helpers/browser-logs') exports.config = { - baseUrl: 'http://localhost:7100/#!/', + baseUrl: process.env.STF_URL || 'http://localhost:7100/#!/', suites: { control: 'e2e/control/**/*-spec.js', devices: 'e2e/devices/**/*-spec.js', @@ -10,9 +11,22 @@ exports.config = { login: 'e2e/login/**/*-spec.js', settings: 'e2e/settings/**/*-spec.js' }, + params: { + login: { + url: process.env.STF_LOGINURL || process.env.STF_URL || + 'http://localhost:7120', + username: process.env.STF_USERNAME || 'test_user', + email: process.env.STF_EMAIL || 'test_user@login.local', + password: process.env.STF_PASSWORD, + method: process.env.STF_METHOD || process.env.STF_PASSWORD ? 'ldap' : + 'mock' + } + }, jasmineNodeOpts: { showColors: true, - defaultTimeoutInterval: 30000 + defaultTimeoutInterval: 30000, + isVerbose: true, + includeStackTrace: true }, capabilities: { browserName: 'chrome', @@ -23,7 +37,14 @@ exports.config = { chromeOnly: true, onPrepare: function () { var loginPage = new LoginPage() - loginPage.login() + loginPage.doLogin() //browser.driver.wait(loginPage.login) + + afterEach(function () { + BrowserLogs({expectNoLogs: true}) + }) + }, + onComplete: function () { + } }