2020-12-11 05:27:08 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2024-10-22 19:02:19 +00:00
|
|
|
/* global it, xit, describe, before, after, afterEach */
|
2020-12-11 05:27:08 +00:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('chromedriver');
|
|
|
|
|
2021-11-02 16:04:49 +00:00
|
|
|
var execSync = require('child_process').execSync,
|
2020-12-11 05:27:08 +00:00
|
|
|
expect = require('expect.js'),
|
2024-10-22 19:02:19 +00:00
|
|
|
fs = require('fs'),
|
2021-11-02 16:04:49 +00:00
|
|
|
path = require('path'),
|
|
|
|
{ Builder, By, Key, until } = require('selenium-webdriver'),
|
|
|
|
{ Options } = require('selenium-webdriver/chrome');
|
2020-12-11 05:27:08 +00:00
|
|
|
|
|
|
|
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', function () {
|
|
|
|
this.timeout(0);
|
|
|
|
|
2024-10-22 19:02:19 +00:00
|
|
|
const LOCATION = process.env.LOCATION || 'test';
|
2021-11-02 16:04:49 +00:00
|
|
|
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
|
|
|
const TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 50000;
|
|
|
|
|
|
|
|
var browser;
|
2020-12-11 05:27:08 +00:00
|
|
|
var username = process.env.USERNAME;
|
|
|
|
var password = process.env.PASSWORD;
|
|
|
|
|
|
|
|
var app;
|
|
|
|
|
2021-11-02 16:04:49 +00:00
|
|
|
before(function () {
|
2024-10-22 19:02:19 +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');
|
2021-11-02 16:04:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
browser.quit();
|
|
|
|
});
|
|
|
|
|
2024-10-22 19:02:19 +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');
|
|
|
|
});
|
|
|
|
|
2021-11-02 16:04:49 +00:00
|
|
|
async function waitForElement(elem) {
|
|
|
|
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
|
|
|
|
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2020-12-11 05:27:08 +00:00
|
|
|
function getAppInfo() {
|
|
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
2021-11-02 16:04:49 +00:00
|
|
|
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
|
2020-12-11 05:27:08 +00:00
|
|
|
expect(app).to.be.an('object');
|
|
|
|
}
|
|
|
|
|
2024-05-10 12:48:19 +00:00
|
|
|
async function login(session = true) {
|
2024-04-16 09:47:28 +00:00
|
|
|
await browser.get(`https://${app.fqdn}`);
|
2024-05-10 12:48:19 +00:00
|
|
|
await waitForElement(By.id('loginProceedButton'));
|
|
|
|
await browser.findElement(By.id('loginProceedButton')).click();
|
|
|
|
|
|
|
|
if (!session) {
|
|
|
|
await waitForElement(By.id('inputUsername'));
|
|
|
|
await browser.findElement(By.id('inputUsername')).sendKeys(username);
|
|
|
|
await browser.findElement(By.id('inputPassword')).sendKeys(password);
|
|
|
|
await browser.findElement(By.id('loginSubmitButton')).click();
|
|
|
|
}
|
|
|
|
|
2021-11-02 16:04:49 +00:00
|
|
|
await waitForElement(By.xpath('//a[text()="Alerts"]'));
|
2020-12-11 05:27:08 +00:00
|
|
|
}
|
|
|
|
|
2021-11-02 16:04:49 +00:00
|
|
|
async function logout() {
|
|
|
|
await browser.get(`https://${app.fqdn}/logout`);
|
2024-05-10 12:48:19 +00:00
|
|
|
await waitForElement(By.id('loginProceedButton'));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loadApp() {
|
|
|
|
await browser.get(`https://${app.fqdn}`);
|
|
|
|
await waitForElement(By.xpath('//a[text()="Alerts"]'));
|
2020-12-11 05:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
|
|
|
|
it('install app', function () { execSync(`cloudron install --location ${LOCATION}`, EXEC_ARGS); });
|
|
|
|
|
|
|
|
it('can get app information', getAppInfo);
|
|
|
|
|
2024-05-10 12:48:19 +00:00
|
|
|
it('can login', login.bind(null, false));
|
|
|
|
it('can load app', loadApp);
|
2020-12-11 05:27:08 +00:00
|
|
|
|
|
|
|
it('can restart app', function () { execSync(`cloudron restart --app ${app.id}`, EXEC_ARGS); });
|
2024-05-10 12:48:19 +00:00
|
|
|
|
|
|
|
it('can load app', loadApp);
|
2020-12-11 05:27:08 +00:00
|
|
|
|
|
|
|
it('backup app', function () { execSync(`cloudron backup create --app ${app.id}`, EXEC_ARGS); });
|
|
|
|
it('restore app', function () {
|
2021-11-02 16:04:49 +00:00
|
|
|
const backups = JSON.parse(execSync(`cloudron backup list --raw --app ${app.id}`));
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
|
|
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
|
|
|
|
getAppInfo();
|
|
|
|
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
|
2020-12-11 05:27:08 +00:00
|
|
|
});
|
|
|
|
|
2024-05-10 12:48:19 +00:00
|
|
|
it('can load app', loadApp);
|
2020-12-11 05:27:08 +00:00
|
|
|
|
|
|
|
it('move to different location', function () { execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_ARGS); });
|
|
|
|
it('can get app information', getAppInfo);
|
2021-11-02 16:04:49 +00:00
|
|
|
|
2020-12-11 05:27:08 +00:00
|
|
|
it('can login', login);
|
2024-05-10 12:48:19 +00:00
|
|
|
it('can load app', loadApp);
|
2020-12-11 05:27:08 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
it('uninstall app', function () { execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS); });
|
|
|
|
|
|
|
|
// test update
|
|
|
|
it('can install app', function () { execSync(`cloudron install --appstore-id io.prometheus.cloudronapp --location ${LOCATION}`, EXEC_ARGS); });
|
|
|
|
it('can get app information', getAppInfo);
|
2024-05-10 12:48:19 +00:00
|
|
|
|
|
|
|
// it('can login', login);
|
|
|
|
it('can load app', loadApp);
|
|
|
|
|
2020-12-11 05:27:08 +00:00
|
|
|
it('can update', function () { execSync(`cloudron update --app ${app.id}`, EXEC_ARGS); });
|
2024-05-10 12:48:19 +00:00
|
|
|
|
|
|
|
it('can load app', loadApp);
|
2020-12-11 05:27:08 +00:00
|
|
|
it('can logout', logout);
|
2024-05-10 12:48:19 +00:00
|
|
|
|
2020-12-11 05:27:08 +00:00
|
|
|
it('uninstall app', function () { execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS); });
|
|
|
|
});
|
|
|
|
|