mirror of
https://github.com/openstf/stf
synced 2025-10-04 02:09:32 +02:00
- 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.
This commit is contained in:
parent
a08d9e26f0
commit
e87dc45fb9
8 changed files with 104 additions and 30 deletions
16
gulpfile.js
16
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"])
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 () {
|
||||
|
||||
})
|
||||
})
|
||||
|
|
36
res/test/e2e/helpers/browser-logs.js
Normal file
36
res/test/e2e/helpers/browser-logs.js
Normal file
|
@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
})
|
||||
|
|
|
@ -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 () {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue