198 lines
7.2 KiB
JavaScript
198 lines
7.2 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/* jshint esversion: 8 */
|
|
/* global describe */
|
|
/* global before */
|
|
/* global after */
|
|
/* global it */
|
|
|
|
'use strict';
|
|
|
|
require('chromedriver');
|
|
|
|
var execSync = require('child_process').execSync,
|
|
expect = require('expect.js'),
|
|
superagent = require('superagent'),
|
|
path = require('path'),
|
|
{ Builder, By, Key, until } = require('selenium-webdriver'),
|
|
{ Options } = require('selenium-webdriver/chrome');
|
|
|
|
describe('Application life cycle test', function () {
|
|
this.timeout(0);
|
|
|
|
var LOCATION = 'test';
|
|
var TEST_TIMEOUT = 30000;
|
|
var FOLDER = 'xmf'; // keep this small. long folder names fail in automation, not sure why
|
|
var SYNC_PORT = 22001;
|
|
var EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
|
|
|
var browser;
|
|
var app;
|
|
var username = 'admin', password = 'changeme';
|
|
|
|
before(function () {
|
|
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
|
|
});
|
|
|
|
after(function () {
|
|
browser.quit();
|
|
});
|
|
|
|
function getAppInfo() {
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
|
|
expect(app).to.be.an('object');
|
|
}
|
|
|
|
function waitForElement(elem) {
|
|
return browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
|
|
return browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
|
});
|
|
}
|
|
|
|
function invalidPassword(callback) {
|
|
superagent.get('https://' + app.fqdn).auth(username, password + 'x').end(function (error, result) {
|
|
expect(result.status).to.eql(401);
|
|
|
|
callback();
|
|
});
|
|
}
|
|
|
|
function loadPage(callback) {
|
|
browser.manage().deleteAllCookies().then(function () {
|
|
return browser.sleep(5000);
|
|
}).then(function() {
|
|
return browser.get('https://' + username + ':' + encodeURIComponent(password) + '@' + app.fqdn).then(function () {
|
|
return browser.get('https://' + app.fqdn);
|
|
});
|
|
}).then(function () {
|
|
return browser.sleep(5000);
|
|
}).then(function () {
|
|
return browser.get('https://' + app.fqdn);
|
|
}).then(function () {
|
|
return waitForElement(By.xpath('//span[text()="Actions"]'));
|
|
}).then(function () {
|
|
callback();
|
|
});
|
|
}
|
|
|
|
function addFolder(callback) {
|
|
browser.get('https://' + app.fqdn).then(function () {
|
|
return browser.findElement(By.css('[ng-click*=addFolder]')).click();
|
|
}).then(function () {
|
|
return waitForElement(By.id('folderPath'));
|
|
}).then(function () {
|
|
return browser.sleep(4000); // wait more, not sure why this is needed
|
|
}).then(function() {
|
|
return browser.findElement(By.id('folderLabel')).sendKeys(FOLDER);
|
|
}).then(function () {
|
|
return browser.sleep(4000); // without this sometimes only part of the folder name gets through
|
|
}).then(function() {
|
|
return browser.findElement(By.css('[ng-click*=saveFolder]')).click();
|
|
}).then(function() {
|
|
return browser.wait(until.elementLocated(By.css('#folders .panel-status span[ng-switch-when=unshared]')), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
return browser.sleep(4000);
|
|
}).then(function() {
|
|
callback();
|
|
});
|
|
}
|
|
|
|
function checkFolder(callback) {
|
|
browser.get('https://' + app.fqdn).then(function () {
|
|
return browser.sleep(5000);
|
|
}).then(function () {
|
|
return browser.get('https://' + app.fqdn);
|
|
}).then(function () {
|
|
return browser.wait(until.elementLocated(By.xpath(`//span[text()="${FOLDER}"]`)), TEST_TIMEOUT);
|
|
}).then(function () {
|
|
callback();
|
|
});
|
|
}
|
|
|
|
function removeFolder(callback) {
|
|
browser.get('https://' + app.fqdn).then(function () {
|
|
return waitForElement(By.xpath('//span[text()="Actions"]'));
|
|
}).then(function() {
|
|
return browser.findElement(By.css('#folders button')).click();
|
|
}).then(function () {
|
|
return browser.sleep(3000); //No way to check for visibility of angular-js components
|
|
}).then(function () {
|
|
return browser.findElement(By.css('#folder-0 button[ng-click*=editFolder]')).click();
|
|
}).then(function () {
|
|
return browser.sleep(3000); //No way to check for visibility of angular-js components
|
|
}).then(function () {
|
|
return browser.findElement(By.xpath('//button[@data-target="#remove-folder-confirmation"]')).click();
|
|
}).then(function () {
|
|
return browser.sleep(3000); //No way to check for visibility of angular-js components
|
|
}).then(function () {
|
|
return browser.findElement(By.css('[ng-click*=deleteFolder]')).click();
|
|
}).then(function () {
|
|
return browser.sleep(3000); //This needs to run for some time
|
|
}).then(function () {
|
|
callback();
|
|
});
|
|
}
|
|
|
|
function wait (done) {
|
|
setTimeout(done, 10000);
|
|
}
|
|
|
|
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
|
|
|
|
it('install app', function () { execSync('cloudron install --port-bindings SYNC_PORT=' + SYNC_PORT + ' --location ' + LOCATION, EXEC_ARGS); });
|
|
it('can get app information', getAppInfo);
|
|
|
|
it('wait', wait);
|
|
|
|
it('fails with invalid password', invalidPassword);
|
|
it('can load page', loadPage);
|
|
it('can add folder', addFolder);
|
|
|
|
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
|
|
it('restore app', async function () {
|
|
await browser.get('about:blank');
|
|
execSync('cloudron restore --app ' + app.id, EXEC_ARGS);
|
|
});
|
|
|
|
it('wait', wait);
|
|
|
|
it('can load page', loadPage);
|
|
it('can check folder', checkFolder);
|
|
|
|
it('move to different location', async function () {
|
|
await browser.get('about:blank');
|
|
execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_ARGS);
|
|
});
|
|
it('can get app information', getAppInfo);
|
|
|
|
it('wait', wait);
|
|
|
|
it('can load page', loadPage);
|
|
it('can check folder', checkFolder);
|
|
it('can remove folder', removeFolder);
|
|
|
|
it('uninstall app', async function () {
|
|
await browser.get('about:blank');
|
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
});
|
|
|
|
// test update
|
|
it('can install app', function () { execSync('cloudron install --port-bindings SYNC_PORT=' + SYNC_PORT + ' --appstore-id net.syncthing.cloudronapp2 --location ' + LOCATION, EXEC_ARGS); });
|
|
it('can get app information', getAppInfo);
|
|
it('wait', wait);
|
|
it('can load page', loadPage);
|
|
it('can add folder', addFolder);
|
|
it('can update', async function () {
|
|
await browser.get('about:blank');
|
|
execSync('cloudron update --app ' + LOCATION, EXEC_ARGS);
|
|
});
|
|
it('wait', wait);
|
|
it('can check folder', checkFolder);
|
|
|
|
it('uninstall app', async function () {
|
|
await browser.get('about:blank');
|
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
});
|
|
});
|