integration test infrastructure

stable
Juanfran 2015-06-15 08:32:16 +02:00
parent a24762a6fb
commit da12bdde93
9 changed files with 378 additions and 0 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ tmp/
app/config/main.coffee app/config/main.coffee
app/plugins/taiga-front-extras app/plugins/taiga-front-extras
scss-lint.log scss-lint.log
integration/screenshots/

34
integration-test-conf.js Normal file
View File

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

View File

@ -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');
});
});
});
});
});

View File

@ -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() {
});

View File

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

View File

@ -0,0 +1,3 @@
module.exports.common = require("./common");
module.exports.notifications = require("./notifications");
module.exports.lightbox = require("./lightbox");

View File

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

View File

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

View File

@ -22,6 +22,7 @@
"devDependencies": { "devDependencies": {
"angular-mocks": "^1.3.15", "angular-mocks": "^1.3.15",
"chai": "^2.2.0", "chai": "^2.2.0",
"chai-as-promised": "^5.1.0",
"chai-jquery": "^2.0.0", "chai-jquery": "^2.0.0",
"cli-color": "^0.3.3", "cli-color": "^0.3.3",
"coffee-script": "^1.9.1", "coffee-script": "^1.9.1",