123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- #!/usr/bin/env node
- /* global describe */
- /* global after */
- /* global it */
- 'use strict';
- require('chromedriver');
- var execSync = require('child_process').execSync,
- expect = require('expect.js'),
- path = require('path'),
- webdriver = require('selenium-webdriver');
- var by = webdriver.By,
- Keys = webdriver.Key,
- until = webdriver.until;
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
- if (!process.env.USERNAME || !process.env.PASSWORD) {
- console.log('USERNAME and PASSWORD env vars need to be set');
- process.exit(1);
- }
- describe('Application life cycle test SSO', function () {
- this.timeout(0);
- var chrome = require('selenium-webdriver/chrome');
- var server, browser = new chrome.Driver();
- after(function () {
- browser.quit();
- });
- var LOCATION = 'test';
- var TEST_TIMEOUT = 100000;
- var PROJECT_NAME = 'testproject';
- var PROJECT_DESCRIPTION = 'testdescription';
- var USER_STORY_SUBJECT = 'someteststory';
- var app;
- function waitForElement(elem) {
- return browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
- return browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
- });
- }
- function login(callback) {
- browser.manage().deleteAllCookies();
- browser.get('https://' + app.fqdn).then(function () {
- return browser.executeScript('localStorage.clear();');
- }).then(function () {
- browser.executeScript('sessionStorage.clear();');
- }).then(function () {
- browser.get('https://' + app.fqdn + '/login?next=%252Fprofile');
- }).then(function () {
- return waitForElement(by.name('username'));
- }).then(function () {
- return browser.findElement(by.name('username')).sendKeys(process.env.USERNAME);
- }).then(function () {
- return browser.findElement(by.name('password')).sendKeys(process.env.PASSWORD);
- }).then(function () {
- return browser.findElement(by.className('login-form')).submit();
- }).then(function () {
- return waitForElement(by.xpath('//h4[text()="Your profile"]'));
- }).then(function () {
- callback();
- });
- }
- function signUp(callback) {
- browser.manage().deleteAllCookies();
- browser.get(`https://${app.fqdn}`).then(function () {
- return browser.executeScript('localStorage.clear();');
- }).then(function () {
- return browser.executeScript('sessionStorage.clear();');
- }).then(function () {
- return browser.get(`https://${app.fqdn}/register`);
- }).then(function () {
- return waitForElement(by.name('username'));
- }).then(function () {
- return browser.findElement(by.name('username')).sendKeys(process.env.USERNAME);
- }).then(function () {
- return browser.findElement(by.name('full_name')).sendKeys(process.env.USERNAME + ' Name');
- }).then(function () {
- return browser.findElement(by.name('email')).sendKeys('test@cloudron.io');
- }).then(function () {
- return browser.findElement(by.name('password')).sendKeys(process.env.PASSWORD);
- }).then(function () {
- return browser.findElement(by.xpath('//button[@title="Sign up"]')).click();
- }).then(function () {
- return waitForElement(by.xpath('//p[contains(text(), "Welcome! Here you will find the projects you are involved on.")]'));
- }).then(function () {
- callback();
- });
- }
- function adminLogin(callback) {
- browser.get('https://' + app.fqdn + '/admin/login/').then(function () {
- return browser.findElement(by.name('username')).sendKeys('admin');
- }).then(function () {
- return browser.findElement(by.name('password')).sendKeys('123123');
- }).then(function () {
- return browser.findElement(by.id('login-form')).submit();
- }).then(function () {
- return waitForElement(by.xpath('//h1[text()="Site administration"]'));
- }).then(function () {
- return browser.findElement(by.xpath('//a[text()="Log out"]')).click();
- }).then(function () {
- return browser.sleep(2000);
- }).then(function () {
- callback();
- });
- }
- function userStoryExists(callback) {
- browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/us/1').then(function () {
- return waitForElement(by.xpath('//span[text()="' + USER_STORY_SUBJECT + '"]'));
- }).then(function () {
- callback();
- });
- }
- function getAppInfo() {
- var inspect = JSON.parse(execSync('cloudron inspect'));
- app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
- expect(app).to.be.an('object');
- }
- function dismissTutorial(done) {
- browser.get('https://' + app.fqdn);
- waitForElement(by.className('introjs-skipbutton')).then(function () {
- return browser.findElement(by.className('introjs-skipbutton')).sendKeys(Keys.ENTER);
- }).then(function () {
- // give some time to ack
- setTimeout(done, 5000);
- });
- }
- function createProject(done) {
- browser.get('https://' + app.fqdn + '/project/new/scrum').then(function () {
- return waitForElement(by.name('project-name'));
- }).then(function () {
- return browser.findElement(by.name('project-name')).sendKeys(PROJECT_NAME);
- }).then(function () {
- return browser.sleep(1000); // it needs some time to change focus!!
- }).then(function () {
- return browser.findElement(by.xpath('//textarea[@placeholder="Project Description"]')).sendKeys(PROJECT_DESCRIPTION);
- }).then(function () {
- return browser.sleep(1000);
- }).then(function () {
- return browser.findElement(by.xpath('//button[text()="Create Project"]')).click();
- }).then(function () {
- return browser.wait(until.elementLocated(by.xpath('//span[text()[contains(., "' + PROJECT_NAME + '")]]')), TEST_TIMEOUT);
- }).then(function () {
- done();
- });
- }
- function createUserStory(done) {
- browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/backlog').then(function () {
- return waitForElement(by.xpath('//a[@tg-check-permission="add_us"]'));
- }).then(function () {
- // clicks don't work with taiga
- return browser.findElement(by.xpath('//a[@tg-check-permission="add_us"]')).sendKeys(Keys.ENTER);
- }).then(function () {
- return waitForElement(by.name('subject'));
- }).then(function () {
- return browser.findElement(by.name('subject')).sendKeys(USER_STORY_SUBJECT);
- }).then(function () {
- return waitForElement(by.xpath('/html/body/div[2]/div/div/div[1]/form/div[2]/button'));
- }).then(function () {
- return browser.findElement(by.xpath('/html/body/div[2]/div/div/div[1]/form/div[2]/button')).sendKeys(Keys.ENTER);
- }).then(function () {
- return waitForElement(by.xpath('//span[text()[contains(., "' + USER_STORY_SUBJECT + '")]]'));
- }).then(function () {
- done();
- });
- }
- function deleteProject(done) {
- browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/admin/project-profile/details').then(function () {
- return waitForElement(by.className('delete-project'));
- }).then(function () {
- return browser.findElement(by.className('delete-project')).click();
- }).then(function () {
- return waitForElement(by.xpath('//a[@title="Yes, I\'m really sure"]'));
- }).then(function () {
- return browser.findElement(by.xpath('//a[@title="Yes, I\'m really sure"]')).click();
- }).then(function () {
- // give some time to redirect
- setTimeout(done, 5000);
- });
- }
- xit('build app', function () {
- execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('install app with SSO', function () {
- execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('can get app information', getAppInfo);
- it('can admin login', adminLogin);
- it('can login', login);
- it('can dismiss tutorial', dismissTutorial);
- it('can create project', createProject);
- it('can create user story', createUserStory);
- it('user story exists', userStoryExists);
- it('can restart app', function (done) {
- execSync('cloudron restart --wait --app ' + app.id);
- done();
- });
- it('user story is still present', userStoryExists);
- it('backup app', function () {
- execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('restore app', function () {
- execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('user story is still present', userStoryExists);
- it('move to different location', function (done) {
- // ensure we don't hit NXDOMAIN in the mean time
- browser.get('about:blank').then(function () {
- execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- done();
- });
- });
- it('can get app information', getAppInfo);
- it('can admin login', adminLogin);
- // origin change requires new login
- it('can login', login);
- it('user story is still present', userStoryExists);
- it('can delete project', deleteProject);
- it('uninstall app', function (done) {
- // ensure we don't hit NXDOMAIN in the mean time
- browser.get('about:blank').then(function () {
- execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- done();
- });
- });
- it('install app without SSO', function () {
- execSync('cloudron install --no-sso --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('can get app information', getAppInfo);
- it('can admin login', adminLogin);
- it('can sign up', signUp);
- it('can dismiss tutorial', dismissTutorial);
- it('can create project', createProject);
- it('can create user story', createUserStory);
- it('user story exists', userStoryExists);
- it('can restart app', function (done) {
- execSync('cloudron restart --wait --app ' + app.id);
- done();
- });
- it('user story is still present', userStoryExists);
- it('uninstall app', function (done) {
- // ensure we don't hit NXDOMAIN in the mean time
- browser.get('about:blank').then(function () {
- execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- done();
- });
- });
- // test update
- it('can install app', function () {
- execSync('cloudron install --new --wait --appstore-id io.taiga.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('can get app information', getAppInfo);
- it('can admin login', adminLogin);
- it('can login', login);
- it('can dismiss tutorial', dismissTutorial);
- it('can create project', createProject);
- it('can create user story', createUserStory);
- it('user story exists', userStoryExists);
- it('can update', function () {
- execSync('cloudron install --wait --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('can admin login', adminLogin);
- it('user story exists', userStoryExists);
- it('uninstall app', function (done) {
- // ensure we don't hit NXDOMAIN in the mean time
- browser.get('about:blank').then(function () {
- execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- done();
- });
- });
- });
|