diff --git a/gulpfile.js b/gulpfile.js index aa35cf2f..b46325b9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -10,7 +10,7 @@ var gettext = require('gulp-angular-gettext') var jade = require('gulp-jade') var clean = require('gulp-clean') var protractor = require("gulp-protractor") -var protractorConfig = require('./res/test/protractor.conf') +var protractorConfig = './res/test/protractor.conf' var karma = require('karma').server var karmaConfig = '/res/test/karma.conf.js' var stream = require('stream') @@ -59,8 +59,8 @@ gulp.task('karma', function (done) { gulp.task('webdriver_update', protractor.webdriver_update) gulp.task('webdriver_standalone', protractor.webdriver_standalone) -gulp.task('protractor', ['webdriver_update'], function (callback) { - gulp.src(["./res/test/**/*.js"]) +gulp.task('protractor', function (callback) { + gulp.src(["./res/test/e2e/**/*.js"]) .pipe(protractor.protractor({ configFile: protractorConfig })) diff --git a/res/.jshintrc b/res/.jshintrc index 5180cfae..9081e2cf 100644 --- a/res/.jshintrc +++ b/res/.jshintrc @@ -37,6 +37,7 @@ "by": false, "Promise": true, "$": false, - "$$": false + "$$": false, + "protractor": false } } diff --git a/res/test/e2e/app-control-spec.js b/res/test/e2e/app-control-spec.js new file mode 100644 index 00000000..c72a9f6d --- /dev/null +++ b/res/test/e2e/app-control-spec.js @@ -0,0 +1,41 @@ +describe('Control Page', function () { + var DeviceListPage = require('./app-devices') + var deviceListPage = new DeviceListPage() + + var ControlPage = function () { + this.get = function () { + browser.get(protractor.getInstance().baseUrl + 'control') + } + this.kickDeviceButton = element.all(by.css('.kick-device')).first() + this.kickDevice = function () { + this.kickDeviceButton.click() + } + } + + var controlPage = new ControlPage() + + it('should control an usable device', function () { + deviceListPage.controlAvailableDevice() + browser.getLocationAbsUrl().then(function (newUrl) { + expect(newUrl).toMatch(protractor.getInstance().baseUrl + 'control') + }) + }) + + it('should have a kick button', function () { + expect(controlPage.kickDeviceButton, true) + }) + + //it('should stop controlling an usable device', function () { + // controlPage.kickDevice() + // + // browser.getLocationAbsUrl().then(function (newUrl) { + // expect(newUrl).toBe(protractor.getInstance().baseUrl + 'devices') + // }) + //}) + + describe('Dashboard', function () { + describe('Shell', function () { + + }) + }) +}) diff --git a/res/test/e2e/app-devices-spec.js b/res/test/e2e/app-devices-spec.js new file mode 100644 index 00000000..a4b80dfd --- /dev/null +++ b/res/test/e2e/app-devices-spec.js @@ -0,0 +1,32 @@ +describe('Device Page', function () { + describe('List', function () { + + var DeviceListPage = require('./app-devices') + var deviceListPage = new DeviceListPage() + + it('should go to Devices List page', function () { + deviceListPage.get() + browser.getLocationAbsUrl().then(function (newUrl) { + expect(newUrl).toBe(protractor.getInstance().baseUrl + 'devices') + }) + }) + + it('should have more than 1 device in the list', function () { + expect(deviceListPage.numberOfDevices()).toBeGreaterThan(0) + }) + + it('should filter available devices', function () { + deviceListPage.filterAvailableDevices() + expect(deviceListPage.searchInput.getAttribute('value')).toBe('state: "available"') + }) + + it('should have more than 1 device available', function () { + expect(deviceListPage.devicesUsable.count()).toBeGreaterThan(0) + }) + + it('should have one device usable', function () { + expect(deviceListPage.availableDevice().getText()).toBe('Use') + }) + + }) +}) diff --git a/res/test/e2e/app-devices.js b/res/test/e2e/app-devices.js new file mode 100644 index 00000000..f48b3c59 --- /dev/null +++ b/res/test/e2e/app-devices.js @@ -0,0 +1,23 @@ +module.exports = function DeviceListPage() { + this.get = function () { + // TODO: Let's get rid off the login first + browser.get(protractor.getInstance().baseUrl + 'devices') + } + this.devices = element(by.model('tracker.devices')) + this.devicesByCss = element.all(by.css('ul.devices-icon-view > li')) + this.devicesUsable = + element.all(by.css('button.device-status.btn-primary-outline')) + this.searchInput = element(by.model('search.deviceFilter')) + this.filterAvailableDevices = function () { + return this.searchInput.sendKeys('state: "available"') + } + this.numberOfDevices = function () { + return this.devicesByCss.count() + } + this.availableDevice = function () { + return this.devicesUsable.first() + } + this.controlAvailableDevice = function () { + this.availableDevice().click() + } +} diff --git a/res/test/e2e/app-help-spec.js b/res/test/e2e/app-help-spec.js new file mode 100644 index 00000000..cb04cfba --- /dev/null +++ b/res/test/e2e/app-help-spec.js @@ -0,0 +1,7 @@ +describe('Help Page', function () { + var HelpPage = function () { + this.get = function () { + browser.get(protractor.getInstance().baseUrl + 'help') + } + } +}) diff --git a/res/test/e2e/app-login-spec.js b/res/test/e2e/app-login-spec.js new file mode 100644 index 00000000..a5cad7f0 --- /dev/null +++ b/res/test/e2e/app-login-spec.js @@ -0,0 +1,17 @@ +describe('Login Page', function () { + var LoginPage = require('./app-login') + var loginPage = new LoginPage() + + it('should login with auth-mock', function () { + loginPage.get() + + loginPage.setName('test_user') + loginPage.setEmail('test_user@test.local') + + loginPage.submit().then(function () { + browser.getLocationAbsUrl().then(function (newUrl) { + expect(newUrl).toBe(protractor.getInstance().baseUrl + 'devices') + }) + }) + }) +}) diff --git a/res/test/e2e/app-login.js b/res/test/e2e/app-login.js new file mode 100644 index 00000000..c827d691 --- /dev/null +++ b/res/test/e2e/app-login.js @@ -0,0 +1,27 @@ +var loginBaseUrl = 'http://localhost:7120' + +module.exports = function LoginPage() { + this.get = function () { + return browser.get(loginBaseUrl) + } + this.name = element(by.model('name')) + this.email = element(by.model('email')) + this.setName = function (name) { + return this.name.sendKeys(name) + } + this.setEmail = function (email) { + return this.email.sendKeys(email) + } + this.setPassword = function (password) { + return this.password.sendKeys(password) + } + this.submit = function () { + return this.name.submit() + } + this.login = function () { + this.get() + this.setName('test_user') + this.setEmail('test_user@login.local') + return this.submit() + } +} diff --git a/res/test/e2e/app-settings-spec.js b/res/test/e2e/app-settings-spec.js new file mode 100644 index 00000000..8a9646c9 --- /dev/null +++ b/res/test/e2e/app-settings-spec.js @@ -0,0 +1,7 @@ +describe('Settings Page', function () { + var SettingsPage = function () { + this.get = function () { + browser.get(protractor.getInstance().baseUrl + 'settings') + } + } +}) diff --git a/res/test/e2e/stfAppE2E-spec.js b/res/test/e2e/stfAppE2E-spec.js deleted file mode 100644 index 00147b64..00000000 --- a/res/test/e2e/stfAppE2E-spec.js +++ /dev/null @@ -1,100 +0,0 @@ -describe('STF App', function () { - var config = { - baseUrl: 'http://localhost:7100/#!', - loginBaseUrl: 'http://localhost:7120' - } - - describe('Login Page', function () { - var LoginPage = function () { - this.get = function () { - return browser.get(config.loginBaseUrl) - } - this.name = element(by.model('name')) - this.email = element(by.model('email')) - this.setName = function (name) { - return this.name.sendKeys(name) - } - this.setEmail = function (email) { - return this.email.sendKeys(email) - } - this.setPassword = function (password) { - return this.password.sendKeys(password) - } - this.submit = function () { - return this.name.submit() - } - this.login = function () { - this.get() - this.setName('test_user') - this.setEmail('test_user@login.local') - return this.submit() - } - } - - var loginPage = new LoginPage() - - it('should login with auth-mock', function () { - loginPage.get() - - loginPage.setName('test_user') - loginPage.setEmail('test_user@test.local') - - loginPage.submit().then(function () { - browser.getLocationAbsUrl().then(function (newUrl) { - expect(newUrl).toBe(config.baseUrl + '/devices') - }) - }) - }) - }) - - describe('Device List Page', function () { - var DeviceListPage = function () { - this.get = function () { - // TODO: Let's get rid off the login first - browser.get(config.baseUrl + '/devices') - } - this.rootClass = $$('.stf-device-list') - this.devices = element(by.model('tracker.devices')) - this.devicesRepeated = element.all( - by.repeater('device in tracker.devices')) - } - - var deviceListPage = new DeviceListPage() - - it('should show a list of devices', function () { -// console.log(deviceListPage.devices) -// expect(deviceListPage.devices.isPresent()).toBe(true) - }) - - it('should filter out all the devices', function () { - - }) - }) - - describe('Control Page', function () { - var DeviceListPage = function () { - this.get = function () { - browser.get(config.baseUrl + '/control') - } - } - - }) - - describe('Settings Page', function () { - var SettingsPage = function () { - this.get = function () { - browser.get(config.baseUrl + '/settings') - } - } - - }) - - describe('Help Page', function () { - var HelpPage = function () { - this.get = function () { - browser.get(config.baseUrl + '/help') - } - } - - }) -}) diff --git a/res/test/protractor.conf.js b/res/test/protractor.conf.js index a01ea31f..e2414466 100644 --- a/res/test/protractor.conf.js +++ b/res/test/protractor.conf.js @@ -1,9 +1,20 @@ // Reference: https://github.com/angular/protractor/blob/master/referenceConf.js +var LoginPage = require('./e2e/app-login.js') exports.config = { - specs: ['res/test/e2e/*spec.js'], + chromeOnly: true, + baseUrl: 'http://localhost:7100/#!/', + specs: ['res/test/e2e/**/*-spec.js'], jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 30000 + }, + capabilities: { + browserName: 'chrome' + }, + onPrepare: function() { + var loginPage = new LoginPage() + loginPage.login() + //browser.driver.wait(loginPage.login) } }