225 lines
7.7 KiB
JavaScript
225 lines
7.7 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
'use strict';
|
|
|
|
var execSync = require('child_process').execSync,
|
|
expect = require('expect.js'),
|
|
path = require('path'),
|
|
webdriver = require('selenium-webdriver');
|
|
|
|
var by = webdriver.By,
|
|
until = webdriver.until;
|
|
|
|
var accessKey = 'admin',
|
|
secretKey = 'secretkey';
|
|
|
|
var bucket = 'cloudrontestbucket';
|
|
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
|
|
|
|
describe('Application life cycle test', function () {
|
|
this.timeout(0);
|
|
|
|
var chrome = require('selenium-webdriver/chrome');
|
|
var server, browser = new chrome.Driver();
|
|
|
|
before(function (done) {
|
|
var seleniumJar= require('selenium-server-standalone-jar');
|
|
var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
|
|
server = new SeleniumServer(seleniumJar.path, { port: 4444 });
|
|
server.start();
|
|
|
|
done();
|
|
});
|
|
|
|
after(function (done) {
|
|
browser.quit();
|
|
server.stop();
|
|
done();
|
|
});
|
|
|
|
var LOCATION = 'test';
|
|
var TEST_TIMEOUT = 10000;
|
|
var app;
|
|
|
|
function pageLoaded() {
|
|
return browser.wait(until.elementLocated(by.className('page-load pl-0 pl-1')), TEST_TIMEOUT);
|
|
}
|
|
|
|
function visible(selector) {
|
|
return browser.wait(until.elementLocated(selector), TEST_TIMEOUT).then(function () {
|
|
return browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT);
|
|
});
|
|
}
|
|
|
|
function login(callback) {
|
|
browser.manage().deleteAllCookies();
|
|
browser.get('https://' + app.fqdn).then(function () {
|
|
return visible(by.id('accessKey'));
|
|
}).then(function () {
|
|
return browser.findElement(by.id('accessKey')).sendKeys(accessKey);
|
|
}).then(function () {
|
|
return browser.findElement(by.id('secretKey')).sendKeys(secretKey);
|
|
}).then(function () {
|
|
// return browser.findElement(by.className('lw-btn')).click();
|
|
return browser.findElement(by.tagName('form')).submit();
|
|
}).then(function () {
|
|
return browser.wait(until.elementLocated(by.id('top-right-menu')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
callback();
|
|
});
|
|
}
|
|
|
|
function logout(callback) {
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
pageLoaded().then(function () {
|
|
return visible(by.id('top-right-menu'));
|
|
}).then(function () {
|
|
return browser.findElement(by.id('top-right-menu')).click();
|
|
}).then(function () {
|
|
return visible(by.xpath('//*[text()="Sign Out "]'));
|
|
}).then(function () {
|
|
return browser.findElement(by.xpath('//*[text()="Sign Out "]')).click();
|
|
}).then(function () {
|
|
return browser.wait(until.elementLocated(by.id('accessKey')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
callback();
|
|
});
|
|
}
|
|
|
|
function addBucket(callback) {
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
pageLoaded().then(function () {
|
|
return visible(by.className('fa fa-plus'));
|
|
}).then(function () {
|
|
return browser.findElement(by.className('fa fa-plus')).click();
|
|
}).then(function () {
|
|
return visible(by.className('fa fa-hdd-o'));
|
|
}).then(function () {
|
|
return browser.findElement(by.className('fa fa-hdd-o')).click();
|
|
}).then(function () {
|
|
return visible(by.xpath('//*[@class="modal-body"]/form/div/input'));
|
|
}).then(function () {
|
|
return browser.findElement(by.xpath('//*[@class="modal-body"]/form/div/input')).sendKeys(bucket);
|
|
}).then(function () {
|
|
return browser.findElement(by.xpath('//*[@class="modal-body"]/form')).submit();
|
|
}).then(function () {
|
|
return visible(by.xpath('//*[@class="main"]/a[text()="' + bucket + '"]'));
|
|
}).then(function () {
|
|
callback();
|
|
});
|
|
}
|
|
|
|
function checkBucket(callback) {
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
pageLoaded().then(function () {
|
|
return browser.findElement(by.xpath(`//a[contains(text(), ${bucket})]`));
|
|
}).then(function () {
|
|
callback();
|
|
});
|
|
}
|
|
|
|
function openSettings(callback) {
|
|
browser.get('https://' + app.fqdn);
|
|
|
|
pageLoaded().then(function () {
|
|
return visible(by.id('top-right-menu'));
|
|
}).then(function () {
|
|
return browser.findElement(by.id('top-right-menu')).click();
|
|
}).then(function () {
|
|
return visible(by.xpath('//*[text()="Settings "]'));
|
|
}).then(function () {
|
|
return browser.findElement(by.xpath('//*[text()="Settings "]')).click();
|
|
}).then(function () {
|
|
return browser.wait(until.elementLocated(by.xpath('//*[text()="Generate"]')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
callback();
|
|
});
|
|
}
|
|
|
|
xit('build app', function () {
|
|
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
|
|
it('install app', function () {
|
|
execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
|
|
it('can get app information', function () {
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
|
|
|
|
expect(app).to.be.an('object');
|
|
});
|
|
|
|
it('can login', login);
|
|
it('can add bucket', addBucket);
|
|
it('can open settings', openSettings);
|
|
it('can logout', logout);
|
|
|
|
it('can restart app', function (done) {
|
|
execSync('cloudron restart --wait');
|
|
done();
|
|
});
|
|
|
|
it('can login', login);
|
|
it('has bucket', checkBucket);
|
|
it('can logout', logout);
|
|
|
|
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('can login', login);
|
|
it('has bucket', checkBucket);
|
|
it('can open settings', openSettings);
|
|
it('can logout', logout);
|
|
|
|
it('move to different location', function () {
|
|
browser.manage().deleteAllCookies();
|
|
execSync('cloudron configure --wait --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
|
|
expect(app).to.be.an('object');
|
|
});
|
|
|
|
it('can login', login);
|
|
it('has bucket', checkBucket);
|
|
it('can logout', logout);
|
|
|
|
it('uninstall app', function () {
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
|
|
// test update
|
|
it('can install app', function () {
|
|
execSync('cloudron install --new --wait --appstore-id io.minio.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
|
|
expect(app).to.be.an('object');
|
|
});
|
|
|
|
it('can login', login);
|
|
it('can add buckets', addBucket);
|
|
it('can logout', logout);
|
|
it('can update', function () {
|
|
execSync('cloudron install --wait --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
it('can login', login);
|
|
it('has bucket', checkBucket);
|
|
it('can logout', logout);
|
|
it('uninstall app', function () {
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
});
|
|
});
|
|
|