2017-05-05 11:19:38 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2021-04-06 09:24:39 +00:00
|
|
|
/* jshint esversion: 8 */
|
2024-11-11 16:45:53 +00:00
|
|
|
/* global it, xit, describe, before, after, afterEach */
|
2020-05-05 10:42:59 +00:00
|
|
|
|
2021-04-06 09:24:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-04-07 00:02:37 +00:00
|
|
|
require('chromedriver');
|
|
|
|
|
2022-05-03 21:51:25 +00:00
|
|
|
const execSync = require('child_process').execSync,
|
2017-05-05 11:19:38 +00:00
|
|
|
expect = require('expect.js'),
|
2024-11-11 16:45:53 +00:00
|
|
|
fs = require('fs'),
|
2017-05-05 11:19:38 +00:00
|
|
|
path = require('path'),
|
2023-10-11 05:17:49 +00:00
|
|
|
timers = require('timers/promises'),
|
2023-10-11 05:30:23 +00:00
|
|
|
{ Builder, By, until } = require('selenium-webdriver'),
|
2020-11-03 12:33:53 +00:00
|
|
|
{ Options } = require('selenium-webdriver/chrome');
|
2017-05-05 11:19:38 +00:00
|
|
|
|
2023-12-11 10:34:51 +00:00
|
|
|
if (!process.env.USERNAME || !process.env.PASSWORD) {
|
|
|
|
console.log('USERNAME and PASSWORD env vars need to be set');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2017-05-05 11:19:38 +00:00
|
|
|
describe('Application life cycle test', function () {
|
|
|
|
this.timeout(0);
|
|
|
|
|
2024-11-11 16:45:53 +00:00
|
|
|
const LOCATION = process.env.LOCATION || 'test';
|
2023-10-11 05:17:49 +00:00
|
|
|
const TEST_TIMEOUT = 30000;
|
|
|
|
const FOLDER = 'xmf'; // keep this small. long folder names fail in automation, not sure why
|
|
|
|
const SYNC_PORT = 22001;
|
|
|
|
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
2020-05-05 10:42:59 +00:00
|
|
|
|
2023-10-11 05:17:49 +00:00
|
|
|
let browser, app;
|
2023-12-11 10:34:51 +00:00
|
|
|
const adminUsername = 'admin', adminPassword = 'changeme';
|
2024-11-11 16:45:53 +00:00
|
|
|
const username = process.env.USERNAME;
|
|
|
|
const password = process.env.PASSWORD;
|
2020-11-03 12:33:53 +00:00
|
|
|
|
|
|
|
before(function () {
|
2024-11-11 16:45:53 +00:00
|
|
|
const chromeOptions = new Options().windowSize({ width: 1280, height: 1024 });
|
|
|
|
if (process.env.CI) chromeOptions.addArguments('no-sandbox', 'disable-dev-shm-usage', 'headless');
|
|
|
|
browser = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
|
|
|
|
if (!fs.existsSync('./screenshots')) fs.mkdirSync('./screenshots');
|
2020-11-03 12:33:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
browser.quit();
|
|
|
|
});
|
2017-05-05 11:19:38 +00:00
|
|
|
|
2024-11-11 16:45:53 +00:00
|
|
|
afterEach(async function () {
|
|
|
|
if (!process.env.CI || !app) return;
|
|
|
|
|
|
|
|
const currentUrl = await browser.getCurrentUrl();
|
|
|
|
if (!currentUrl.includes(app.domain)) return;
|
|
|
|
expect(this.currentTest.title).to.be.a('string');
|
|
|
|
|
|
|
|
const screenshotData = await browser.takeScreenshot();
|
|
|
|
fs.writeFileSync(`./screenshots/${new Date().getTime()}-${this.currentTest.title.replaceAll(' ', '_')}.png`, screenshotData, 'base64');
|
|
|
|
});
|
|
|
|
|
2020-05-05 10:42:59 +00:00
|
|
|
function getAppInfo() {
|
2023-10-11 05:17:49 +00:00
|
|
|
const inspect = JSON.parse(execSync('cloudron inspect'));
|
2020-11-03 14:38:03 +00:00
|
|
|
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
|
2020-05-05 10:42:59 +00:00
|
|
|
expect(app).to.be.an('object');
|
2018-02-27 00:56:42 +00:00
|
|
|
}
|
|
|
|
|
2023-10-11 05:30:23 +00:00
|
|
|
async function waitForElement(elem) {
|
|
|
|
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
|
|
|
|
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
2017-05-05 11:19:38 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 10:34:51 +00:00
|
|
|
async function login(username, password) {
|
2023-11-13 14:54:18 +00:00
|
|
|
await browser.manage().deleteAllCookies();
|
|
|
|
await browser.get('https://' + app.fqdn);
|
|
|
|
await waitForElement(By.id('user'));
|
|
|
|
await browser.findElement(By.id('user')).sendKeys(username);
|
|
|
|
await browser.findElement(By.id('password')).sendKeys(password);
|
|
|
|
await browser.findElement(By.xpath('//button[@type="submit"]')).click();
|
|
|
|
await waitForElement(By.xpath('//span[text()="Actions"]'));
|
2018-02-27 02:07:00 +00:00
|
|
|
}
|
|
|
|
|
2024-03-04 11:05:45 +00:00
|
|
|
async function logout() {
|
|
|
|
await browser.get('https://' + app.fqdn);
|
|
|
|
await waitForElement(By.xpath('//span[text()="Actions"]'));
|
|
|
|
await browser.findElement(By.xpath('//span[text()="Actions"]')).click();
|
|
|
|
await browser.sleep(4000);
|
|
|
|
await waitForElement(By.xpath('//span[text()="Log Out"]'));
|
|
|
|
await browser.findElement(By.xpath('//span[text()="Log Out"]')).click();
|
|
|
|
await browser.sleep(4000);
|
|
|
|
await waitForElement(By.id('user'));
|
|
|
|
}
|
|
|
|
|
2023-10-11 05:30:23 +00:00
|
|
|
async function loadPage() {
|
|
|
|
await browser.get('https://' + app.fqdn);
|
|
|
|
await waitForElement(By.xpath('//span[text()="Actions"]'));
|
2017-05-05 11:19:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-11 05:30:23 +00:00
|
|
|
async function addFolder() {
|
|
|
|
await browser.get('https://' + app.fqdn);
|
|
|
|
await browser.findElement(By.css('[ng-click*=addFolder]')).click();
|
|
|
|
await waitForElement(By.id('folderPath'));
|
2024-03-05 11:14:53 +00:00
|
|
|
await browser.sleep(8000); // wait more, not sure why this is needed
|
2023-10-11 05:30:23 +00:00
|
|
|
await browser.findElement(By.id('folderLabel')).sendKeys(FOLDER);
|
2024-03-05 11:14:53 +00:00
|
|
|
await browser.sleep(8000); // without this sometimes only part of the folder name gets through
|
2023-10-11 05:30:23 +00:00
|
|
|
await browser.findElement(By.css('[ng-click*=saveFolder]')).click();
|
2024-03-05 11:14:53 +00:00
|
|
|
await browser.sleep(8000); // without this "stale element"
|
2024-01-02 10:05:43 +00:00
|
|
|
await waitForElement(By.xpath(`//span[contains(text(), '${FOLDER}')]`));
|
2024-03-05 11:14:53 +00:00
|
|
|
await browser.sleep(8000);
|
2017-05-05 11:19:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-11 05:30:23 +00:00
|
|
|
async function checkFolder() {
|
|
|
|
await browser.get('https://' + app.fqdn);
|
|
|
|
await browser.sleep(5000);
|
|
|
|
await browser.get('https://' + app.fqdn);
|
|
|
|
await browser.wait(until.elementLocated(By.xpath(`//span[text()="${FOLDER}"]`)), TEST_TIMEOUT);
|
2018-02-27 00:56:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 10:42:59 +00:00
|
|
|
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
|
2017-05-05 11:19:38 +00:00
|
|
|
|
2023-12-11 10:34:51 +00:00
|
|
|
// NO SSO
|
|
|
|
it('install app (NO SSO)', function () { execSync('cloudron install --no-sso --port-bindings SYNC_PORT=' + SYNC_PORT + ' --location ' + LOCATION, EXEC_ARGS); });
|
|
|
|
it('can get app information', getAppInfo);
|
|
|
|
|
|
|
|
it('can admin login', login.bind(null, adminUsername, adminPassword));
|
|
|
|
it('can load page', loadPage);
|
|
|
|
it('can add folder', addFolder);
|
|
|
|
it('can check folder', checkFolder);
|
|
|
|
|
|
|
|
it('uninstall app', async function () {
|
|
|
|
await browser.get('about:blank');
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
|
|
});
|
|
|
|
|
|
|
|
// SSO
|
|
|
|
it('install app (SSO)', function () { execSync('cloudron install --port-bindings SYNC_PORT=' + SYNC_PORT + ' --location ' + LOCATION, EXEC_ARGS); });
|
2020-05-05 10:42:59 +00:00
|
|
|
it('can get app information', getAppInfo);
|
2017-05-05 11:19:38 +00:00
|
|
|
|
2023-12-11 10:34:51 +00:00
|
|
|
it('can login', login.bind(null, username, password));
|
2017-05-08 09:47:39 +00:00
|
|
|
it('can load page', loadPage);
|
|
|
|
it('can add folder', addFolder);
|
2024-03-04 11:05:45 +00:00
|
|
|
it('can logout', logout);
|
2017-05-05 11:19:38 +00:00
|
|
|
|
2023-11-15 13:34:12 +00:00
|
|
|
it('backup app', async function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
|
2021-04-06 09:24:39 +00:00
|
|
|
it('restore app', async function () {
|
|
|
|
await browser.get('about:blank');
|
|
|
|
execSync('cloudron restore --app ' + app.id, EXEC_ARGS);
|
2023-11-13 14:54:18 +00:00
|
|
|
await timers.setTimeout(5000);
|
2021-04-06 09:24:39 +00:00
|
|
|
});
|
2017-05-05 11:19:38 +00:00
|
|
|
|
2023-12-11 10:34:51 +00:00
|
|
|
it('can login', login.bind(null, username, password));
|
2017-05-08 09:47:39 +00:00
|
|
|
it('can load page', loadPage);
|
2018-02-27 00:56:42 +00:00
|
|
|
it('can check folder', checkFolder);
|
2024-03-04 11:05:45 +00:00
|
|
|
it('can logout', logout);
|
2017-05-05 11:19:38 +00:00
|
|
|
|
2021-04-06 09:24:39 +00:00
|
|
|
it('move to different location', async function () {
|
|
|
|
await browser.get('about:blank');
|
|
|
|
execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_ARGS);
|
2023-11-13 14:54:18 +00:00
|
|
|
await timers.setTimeout(5000);
|
2017-05-05 11:19:38 +00:00
|
|
|
});
|
2020-05-05 10:42:59 +00:00
|
|
|
it('can get app information', getAppInfo);
|
2017-05-05 11:19:38 +00:00
|
|
|
|
2023-12-11 10:34:51 +00:00
|
|
|
it('can login', login.bind(null, username, password));
|
2017-05-23 19:45:05 +00:00
|
|
|
it('can load page', loadPage);
|
2018-02-27 00:56:42 +00:00
|
|
|
it('can check folder', checkFolder);
|
2024-03-04 11:05:45 +00:00
|
|
|
it('can logout', logout);
|
2017-05-05 11:19:38 +00:00
|
|
|
|
2021-04-06 09:24:39 +00:00
|
|
|
it('uninstall app', async function () {
|
|
|
|
await browser.get('about:blank');
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
2017-05-05 11:19:38 +00:00
|
|
|
});
|
|
|
|
|
2018-02-27 00:56:42 +00:00
|
|
|
// test update
|
2023-10-11 05:17:49 +00:00
|
|
|
it('can install app', async function () {
|
|
|
|
execSync('cloudron install --port-bindings SYNC_PORT=' + SYNC_PORT + ' --appstore-id net.syncthing.cloudronapp2 --location ' + LOCATION, EXEC_ARGS);
|
|
|
|
await timers.setTimeout(30000);
|
|
|
|
});
|
2020-05-05 10:42:59 +00:00
|
|
|
it('can get app information', getAppInfo);
|
2024-01-02 10:05:43 +00:00
|
|
|
it('can login', login.bind(null, username, password));
|
2018-02-27 00:56:42 +00:00
|
|
|
it('can load page', loadPage);
|
|
|
|
it('can add folder', addFolder);
|
2024-03-04 11:05:45 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
2021-04-06 09:24:39 +00:00
|
|
|
it('can update', async function () {
|
|
|
|
await browser.get('about:blank');
|
|
|
|
execSync('cloudron update --app ' + LOCATION, EXEC_ARGS);
|
2023-10-11 05:17:49 +00:00
|
|
|
await timers.setTimeout(30000);
|
2021-04-06 09:24:39 +00:00
|
|
|
});
|
2024-01-02 10:05:43 +00:00
|
|
|
it('can login', login.bind(null, username, password));
|
2018-02-27 00:56:42 +00:00
|
|
|
it('can check folder', checkFolder);
|
2020-05-05 10:42:59 +00:00
|
|
|
|
2021-04-06 09:24:39 +00:00
|
|
|
it('uninstall app', async function () {
|
|
|
|
await browser.get('about:blank');
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
2018-02-27 00:56:42 +00:00
|
|
|
});
|
2017-05-05 11:19:38 +00:00
|
|
|
});
|