From da12bdde932af6fba7430f6c7c905e40ac3fb3d9 Mon Sep 17 00:00:00 2001 From: Juanfran Date: Mon, 15 Jun 2015 08:32:16 +0200 Subject: [PATCH] integration test infrastructure --- .gitignore | 1 + integration-test-conf.js | 34 +++++ integration/auth/auth.integrationSpec.js | 161 +++++++++++++++++++++++ integration/full/home.integrationSpec.js | 11 ++ integration/utils/common.js | 77 +++++++++++ integration/utils/index.js | 3 + integration/utils/lightbox.js | 40 ++++++ integration/utils/notifications.js | 50 +++++++ package.json | 1 + 9 files changed, 378 insertions(+) create mode 100644 integration-test-conf.js create mode 100644 integration/auth/auth.integrationSpec.js create mode 100644 integration/full/home.integrationSpec.js create mode 100644 integration/utils/common.js create mode 100644 integration/utils/index.js create mode 100644 integration/utils/lightbox.js create mode 100644 integration/utils/notifications.js diff --git a/.gitignore b/.gitignore index 18a1d2d1..81383148 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ tmp/ app/config/main.coffee app/plugins/taiga-front-extras scss-lint.log +integration/screenshots/ \ No newline at end of file diff --git a/integration-test-conf.js b/integration-test-conf.js new file mode 100644 index 00000000..1d037acf --- /dev/null +++ b/integration-test-conf.js @@ -0,0 +1,34 @@ +var utils = require('./integration/utils'); + +exports.config = { + seleniumAddress: 'http://localhost:4444/wd/hub', + framework: 'mocha', + mochaOpts: { + timeout: 5000 + }, + suites: { + auth: 'integration/auth/*.integrationSpec.js', + full: 'integration/full/**/*integrationSpec.js' + }, + onPrepare: function() { + browser.get('http://localhost:9001/login'); + + var username = $('input[name="username"]'); + username.sendKeys('admin'); + + var password = $('input[name="password"]'); + password.sendKeys('123123'); + + $('.submit-button').click(); + + return browser.driver.wait(function() { + return utils.common.closeCookies() + .then(function() { + return browser.driver.getCurrentUrl() + }) + .then(function(url) { + return url === 'http://localhost:9001/'; + }); + }, 10000); + } +} diff --git a/integration/auth/auth.integrationSpec.js b/integration/auth/auth.integrationSpec.js new file mode 100644 index 00000000..161b2048 --- /dev/null +++ b/integration/auth/auth.integrationSpec.js @@ -0,0 +1,161 @@ +var utils = require('../utils'); + +var chai = require('chai'); +var chaiAsPromised = require('chai-as-promised'); + +chai.use(chaiAsPromised); +var expect = chai.expect; + +describe('auth', function() { + it('login', function() { + browser.get('http://localhost:9001/login'); + + return utils.common.waitLoader().then(function() { + utils.common.takeScreenshot("auth", "login"); + + var username = $('input[name="username"]'); + username.sendKeys('admin'); + + var password = $('input[name="password"]'); + password.sendKeys('123123'); + + $('.submit-button').click(); + + return expect(browser.getCurrentUrl()).to.be.eventually.equal('http://localhost:9001/'); + }); + }); + + describe("user", function() { + var user = {}; + + describe("register", function() { + it('screenshot', function() { + browser.get('http://localhost:9001/register'); + + utils.common.waitLoader().then(function() { + utils.common.takeScreenshot("auth", "register"); + }); + }); + + it('register validation', function() { + browser.get('http://localhost:9001/register'); + + $('.submit-button').click(); + + utils.common.takeScreenshot("auth", "register-validation"); + + return expect($$('.checksley-required').count()).to.be.eventually.equal(4); + }); + + it('register ok', function() { + browser.get('http://localhost:9001/register'); + + user.username = "username-" + Math.random(); + user.fullname = "fullname-" + Math.random(); + user.password = "passsword-" + Math.random(); + user.email = "email-" + Math.random() + "@taiga.io"; + + $('input[name="username"]').sendKeys(user.username); + $('input[name="full_name"]').sendKeys(user.fullname); + $('input[name="email"]').sendKeys(user.email); + $('input[name="password"]').sendKeys(user.password); + + $('.submit-button').click(); + + return expect(browser.getCurrentUrl()).to.be.eventually.equal('http://localhost:9001/'); + }); + }); + + describe("change password", function() { + beforeEach(function(done) { + utils.common.login(user.username, user.password).then(function() { + browser.get('http://localhost:9001/user-settings/user-change-password'); + done(); + }); + }); + + it("error", function() { + $('#current-password').sendKeys('wrong'); + $('#new-password').sendKeys('123123'); + $('#retype-password').sendKeys('123123'); + + $('.submit-button').click(); + + return expect(utils.notifications.error.open()).to.be.eventually.equal(true); + }); + + it("success", function() { + $('#current-password').sendKeys(user.password); + $('#new-password').sendKeys(user.password); + $('#retype-password').sendKeys(user.password); + + $('.submit-button').click(); + + return expect(utils.notifications.success.open()).to.be.eventually.equal(true); + }); + }); + + describe("remember password", function() { + beforeEach(function() { + browser.get('http://localhost:9001/forgot-password'); + }); + + it ("screenshot", function() { + utils.common.waitLoader().then(function() { + utils.common.takeScreenshot("auth", "remember-password"); + }); + }); + + it ("error", function() { + $('input[name="username"]').sendKeys("xxxxxxxx"); + $('.submit-button').click(); + + return expect(utils.notifications.errorLight.open()).to.be.eventually.equal(true); + }); + + it ("success", function() { + $('input[name="username"]').sendKeys(user.username); + $('.submit-button').click(); + + return utils.lightbox.open('.lightbox-generic-success').then(function() { + utils.common.takeScreenshot('auth', 'remember-password-success'); + + $('.lightbox-generic-success .button-green').click(); + + return expect(utils.lightbox.close('.lightbox-generic-success')).to.be.eventually.equal(true); + }); + }); + }); + + describe("", function() { + it("logout", function() { + return utils.common.login(user.username, user.password) + .then(function() { + browser.actions().mouseMove($('div[tg-dropdown-user]')).perform(); + $$('.dropdown-user li a').last().click(); + + return expect(browser.getCurrentUrl()).to.be.eventually.equal('http://localhost:9001/login'); + }) + }); + + it("delete account", function() { + return utils.common.login(user.username, user.password) + .then(function() { + browser.get('http://localhost:9001/user-settings/user-profile'); + $('.delete-account').click(); + + return utils.lightbox.open('.lightbox-delete-account'); + }) + .then(function() { + utils.common.takeScreenshot("auth", "delete-account"); + + $('#unsuscribe').click(); + $('.lightbox-delete-account .button-green').click(); + + return expect(browser.getCurrentUrl()) + .to.be.eventually.equal('http://localhost:9001/login'); + }); + }); + }); + }); +}); diff --git a/integration/full/home.integrationSpec.js b/integration/full/home.integrationSpec.js new file mode 100644 index 00000000..bc2c0716 --- /dev/null +++ b/integration/full/home.integrationSpec.js @@ -0,0 +1,11 @@ +var utils = require('../utils'); + +var chai = require('chai'); +var chaiAsPromised = require('chai-as-promised'); + +chai.use(chaiAsPromised); +var expect = chai.expect; + +describe('home', function() { + +}); diff --git a/integration/utils/common.js b/integration/utils/common.js new file mode 100644 index 00000000..fd9bed66 --- /dev/null +++ b/integration/utils/common.js @@ -0,0 +1,77 @@ +var common = module.exports; + +var fs = require('fs'); + +common.hasClass = function (element, cls) { + return element.getAttribute('class').then(function (classes) { + return classes.split(' ').indexOf(cls) !== -1; + }); +}; + +common.waitLoader = function () { + var el = $(".loader"); + + return browser.wait(function() { + return common.hasClass(el, 'active').then(function(active) { + return !active; + }); + }, 5000); +}; + +common.takeScreenshot = function (section, filename) { + var screenshotsFolder = __dirname + "/../screenshots/"; + var dir = screenshotsFolder + section + "/"; + + if (!fs.existsSync(screenshotsFolder)) { + fs.mkdirSync(screenshotsFolder); + } + + return browser.takeScreenshot().then(function (data) { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + + var path = dir + filename + ".png"; + var stream = fs.createWriteStream(path); + + stream.write(new Buffer(data, 'base64')); + stream.end(); + }); +}; + +common.closeCookies = function() { + return browser.executeScript(function() { + document.cookie='cookieConsent=1'; + }); +}; + +// common.waitLoad = function() { +// var deferred = protractor.promise.defer(); + +// common.waitLoader().then(function() { +// deferred.fulfill(); +// }); + +// return deferred.promise; +// }; + +common.login = function(username, password) { + browser.get('http://localhost:9001/login'); + + $('input[name="username"]').sendKeys(username); + $('input[name="password"]').sendKeys(password); + + $('.submit-button').click(); + + return browser.driver.wait(function() { + return browser.driver.getCurrentUrl().then(function(url) { + return url === 'http://localhost:9001/'; + }); + }, 10000); +}; + +common.prepare = function() { + browser.get('http://localhost:9001/'); + + return common.closeCookies() +} diff --git a/integration/utils/index.js b/integration/utils/index.js new file mode 100644 index 00000000..1e63c735 --- /dev/null +++ b/integration/utils/index.js @@ -0,0 +1,3 @@ +module.exports.common = require("./common"); +module.exports.notifications = require("./notifications"); +module.exports.lightbox = require("./lightbox"); diff --git a/integration/utils/lightbox.js b/integration/utils/lightbox.js new file mode 100644 index 00000000..949d3660 --- /dev/null +++ b/integration/utils/lightbox.js @@ -0,0 +1,40 @@ +var common = require('./common') + +var lightbox = module.exports; +var transition = 300; + +lightbox.open = function(el) { + var deferred = protractor.promise.defer(); + + if (typeof el == 'string' || el instanceof String) { + el = $(el); + } + + browser + .wait(function() { + return common.hasClass(el, 'open') + }, 2000) + .then(function(open) { + return browser.sleep(transition).then(function() { + if (open) { + deferred.fulfill(open); + } else { + deferred.reject(new Error('Lightbox doesn\'t open')); + } + }); + }); + + return deferred.promise; +}; + +lightbox.close = function(el) { + if (typeof el == 'string' || el instanceof String) { + el = $(el); + } + + return browser.wait(function() { + return common.hasClass(el, 'open').then(function(open) { + return !open; + }); + }, 2000); +}; diff --git a/integration/utils/notifications.js b/integration/utils/notifications.js new file mode 100644 index 00000000..cd242b9b --- /dev/null +++ b/integration/utils/notifications.js @@ -0,0 +1,50 @@ +var common = require('./common') + +var notifications = module.exports; + +var transition = 600; + +notifications.success = {}; +notifications.success.open = function() { + var el = $('.notification-message-success'); + + return browser + .wait(function() { + return common.hasClass(el, 'active') + }, 2000) + .then(function(active) { + return browser.sleep(transition).then(function() { + return active; + }); + }); +}; + +notifications.error = {}; +notifications.error.open = function() { + var el = $('.notification-message-error'); + + return browser + .wait(function() { + return common.hasClass(el, 'active') + }, 2000) + .then(function(active) { + return browser.sleep(transition).then(function() { + return active; + }); + }); +}; + +notifications.errorLight = {}; +notifications.errorLight.open = function() { + var el = $('.notification-message-light-error'); + + return browser + .wait(function() { + return common.hasClass(el, 'active') + }, 2000) + .then(function(active) { + return browser.sleep(transition).then(function() { + return active; + }); + }); +}; diff --git a/package.json b/package.json index bfd6dd6b..6b518ffd 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "devDependencies": { "angular-mocks": "^1.3.15", "chai": "^2.2.0", + "chai-as-promised": "^5.1.0", "chai-jquery": "^2.0.0", "cli-color": "^0.3.3", "coffee-script": "^1.9.1",