mirror of
https://git.cloudron.io/cloudron/syncthing-app
synced 2026-04-25 03:43:02 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b3297ccc87 | |||
| efe0db3947 | |||
| b8c7faa37a | |||
| 7c3f77d272 | |||
| 653e6a11bb |
Generated
-3069
File diff suppressed because it is too large
Load Diff
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "test",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"chromedriver": "^147.0.1",
|
|
||||||
"expect.js": "^0.3.1",
|
|
||||||
"mocha": "^11.7.5",
|
|
||||||
"selenium-webdriver": "^4.41.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+38
-132
@@ -1,195 +1,101 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/* jshint esversion: 8 */
|
import { app, clearCache, click, cloudronCli, goto, password, sendKeys, setupBrowser, takeScreenshot, teardownBrowser, username, waitFor } from '@cloudron/charlie';
|
||||||
/* global it, xit, describe, before, after, afterEach */
|
|
||||||
|
|
||||||
'use strict';
|
/* global it, describe, before, after, afterEach */
|
||||||
|
|
||||||
require('chromedriver');
|
|
||||||
|
|
||||||
const execSync = require('child_process').execSync,
|
|
||||||
expect = require('expect.js'),
|
|
||||||
fs = require('fs'),
|
|
||||||
path = require('path'),
|
|
||||||
timers = require('timers/promises'),
|
|
||||||
{ Builder, By, until } = require('selenium-webdriver'),
|
|
||||||
{ Options } = require('selenium-webdriver/chrome');
|
|
||||||
|
|
||||||
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 () {
|
describe('Application life cycle test', function () {
|
||||||
this.timeout(0);
|
const FOLDER = 'xmf'; // keep small; long folder names fail in automation
|
||||||
|
|
||||||
const LOCATION = process.env.LOCATION || 'test';
|
|
||||||
const TEST_TIMEOUT = 30000;
|
|
||||||
const FOLDER = 'xmf'; // keep this small. long folder names fail in automation, not sure why
|
|
||||||
const SYNC_PORT = 22001;
|
const SYNC_PORT = 22001;
|
||||||
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
const adminUsername = 'admin';
|
||||||
|
const adminPassword = 'changeme';
|
||||||
|
|
||||||
let browser, app;
|
before(setupBrowser);
|
||||||
const adminUsername = 'admin', adminPassword = 'changeme';
|
after(teardownBrowser);
|
||||||
const username = process.env.USERNAME;
|
|
||||||
const password = process.env.PASSWORD;
|
|
||||||
|
|
||||||
before(function () {
|
|
||||||
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');
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function () {
|
|
||||||
browser.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async function () {
|
afterEach(async function () {
|
||||||
if (!process.env.CI || !app) return;
|
await takeScreenshot(this.currentTest.title);
|
||||||
|
|
||||||
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');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function getAppInfo() {
|
async function login(uname, pass) {
|
||||||
const inspect = JSON.parse(execSync('cloudron inspect'));
|
await clearCache();
|
||||||
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
|
await goto(`https://${app.fqdn}`, 'css=#user');
|
||||||
expect(app).to.be.an('object');
|
await sendKeys('css=#user', uname);
|
||||||
}
|
await sendKeys('css=#password', pass);
|
||||||
|
await click('xpath=//button[@type="submit"]');
|
||||||
async function waitForElement(elem) {
|
await waitFor('Actions');
|
||||||
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
|
|
||||||
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function login(username, password) {
|
|
||||||
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"]'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
await browser.get('https://' + app.fqdn);
|
await goto(`https://${app.fqdn}`, 'Actions');
|
||||||
await waitForElement(By.xpath('//span[text()="Actions"]'));
|
await click('text=Actions');
|
||||||
await browser.findElement(By.xpath('//span[text()="Actions"]')).click();
|
await click('text=Log Out');
|
||||||
await browser.sleep(4000);
|
await waitFor('css=#user');
|
||||||
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'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadPage() {
|
async function loadPage() {
|
||||||
await browser.get('https://' + app.fqdn);
|
await goto(`https://${app.fqdn}`, 'Actions');
|
||||||
await waitForElement(By.xpath('//span[text()="Actions"]'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addFolder() {
|
async function addFolder() {
|
||||||
await browser.get('https://' + app.fqdn);
|
await goto(`https://${app.fqdn}`, 'css=[ng-click*=addFolder]');
|
||||||
await browser.findElement(By.css('[ng-click*=addFolder]')).click();
|
await click('css=[ng-click*=addFolder]');
|
||||||
await browser.sleep(8000);
|
await waitFor('css=#folderPath');
|
||||||
await waitForElement(By.id('folderPath'));
|
await sendKeys('css=#folderLabel', FOLDER);
|
||||||
await browser.sleep(8000); // wait more, not sure why this is needed
|
await sendKeys('css=#folderPath', `/app/data/${FOLDER}`);
|
||||||
await browser.findElement(By.id('folderLabel')).sendKeys(FOLDER);
|
await click('css=[ng-click*=saveFolder]');
|
||||||
await browser.findElement(By.id('folderPath')).sendKeys(`/app/data/${FOLDER}`);
|
await waitFor(FOLDER);
|
||||||
await browser.sleep(8000); // without this sometimes only part of the folder name gets through
|
|
||||||
await browser.findElement(By.css('[ng-click*=saveFolder]')).click();
|
|
||||||
await browser.sleep(8000); // without this "stale element"
|
|
||||||
await waitForElement(By.xpath(`//span[contains(text(), '${FOLDER}')]`));
|
|
||||||
await browser.sleep(8000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkFolder() {
|
async function checkFolder() {
|
||||||
await browser.get('https://' + app.fqdn);
|
await goto(`https://${app.fqdn}`, FOLDER);
|
||||||
await browser.sleep(5000);
|
|
||||||
await browser.get('https://' + app.fqdn);
|
|
||||||
await browser.wait(until.elementLocated(By.xpath(`//span[text()="${FOLDER}"]`)), TEST_TIMEOUT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
|
|
||||||
|
|
||||||
// NO SSO
|
// NO SSO
|
||||||
it('install app (NO SSO)', function () { execSync('cloudron install --no-sso --port-bindings SYNC_PORT=' + SYNC_PORT + ' --location ' + LOCATION, EXEC_ARGS); });
|
it('install app (NO SSO)', () => cloudronCli.install({ noSso: true, tcpPortFlags: { SYNC_PORT } }));
|
||||||
it('can get app information', getAppInfo);
|
|
||||||
|
|
||||||
it('can admin login', login.bind(null, adminUsername, adminPassword));
|
it('can admin login', login.bind(null, adminUsername, adminPassword));
|
||||||
it('can load page', loadPage);
|
it('can load page', loadPage);
|
||||||
it('can add folder', addFolder);
|
it('can add folder', addFolder);
|
||||||
it('can check folder', checkFolder);
|
it('can check folder', checkFolder);
|
||||||
|
|
||||||
it('uninstall app', async function () {
|
it('uninstall app', cloudronCli.uninstall);
|
||||||
await browser.get('about:blank');
|
|
||||||
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
||||||
});
|
|
||||||
|
|
||||||
// SSO
|
// SSO
|
||||||
it('install app (SSO)', function () { execSync('cloudron install --port-bindings SYNC_PORT=' + SYNC_PORT + ' --location ' + LOCATION, EXEC_ARGS); });
|
it('install app (SSO)', () => cloudronCli.install({ noSso: false, tcpPortFlags: { SYNC_PORT } }));
|
||||||
it('can get app information', getAppInfo);
|
|
||||||
|
|
||||||
it('can login', login.bind(null, username, password));
|
it('can login', login.bind(null, username, password));
|
||||||
it('can load page', loadPage);
|
it('can load page', loadPage);
|
||||||
it('can add folder', addFolder);
|
it('can add folder', addFolder);
|
||||||
it('can logout', logout);
|
it('can logout', logout);
|
||||||
|
|
||||||
it('backup app', async function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
|
it('backup app', cloudronCli.createBackup);
|
||||||
it('restore app', async function () {
|
it('restore app', cloudronCli.restoreFromLatestBackup);
|
||||||
await browser.get('about:blank');
|
|
||||||
execSync('cloudron restore --app ' + app.id, EXEC_ARGS);
|
|
||||||
await timers.setTimeout(5000);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can login', login.bind(null, username, password));
|
it('can login', login.bind(null, username, password));
|
||||||
it('can load page', loadPage);
|
it('can load page', loadPage);
|
||||||
it('can check folder', checkFolder);
|
it('can check folder', checkFolder);
|
||||||
it('can logout', logout);
|
it('can logout', logout);
|
||||||
|
|
||||||
it('move to different location', async function () {
|
it('move to different location', cloudronCli.changeLocation);
|
||||||
await browser.get('about:blank');
|
|
||||||
execSync(`cloudron configure --location ${LOCATION}2 --app ${app.id}`, EXEC_ARGS);
|
|
||||||
await timers.setTimeout(5000);
|
|
||||||
});
|
|
||||||
it('can get app information', getAppInfo);
|
|
||||||
|
|
||||||
it('can login', login.bind(null, username, password));
|
it('can login', login.bind(null, username, password));
|
||||||
it('can load page', loadPage);
|
it('can load page', loadPage);
|
||||||
it('can check folder', checkFolder);
|
it('can check folder', checkFolder);
|
||||||
it('can logout', logout);
|
it('can logout', logout);
|
||||||
|
|
||||||
it('uninstall app', async function () {
|
it('uninstall app', cloudronCli.uninstall);
|
||||||
await browser.get('about:blank');
|
|
||||||
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
||||||
});
|
|
||||||
|
|
||||||
// test update
|
// test update
|
||||||
it('can install app', async function () {
|
it('can install app', () => cloudronCli.appstoreInstall({ tcpPortFlags: { SYNC_PORT } }));
|
||||||
execSync('cloudron install --port-bindings SYNC_PORT=' + SYNC_PORT + ' --appstore-id net.syncthing.cloudronapp2 --location ' + LOCATION, EXEC_ARGS);
|
|
||||||
await timers.setTimeout(30000);
|
|
||||||
});
|
|
||||||
it('can get app information', getAppInfo);
|
|
||||||
it('can login', login.bind(null, username, password));
|
it('can login', login.bind(null, username, password));
|
||||||
it('can load page', loadPage);
|
it('can load page', loadPage);
|
||||||
it('can add folder', addFolder);
|
it('can add folder', addFolder);
|
||||||
it('can logout', logout);
|
it('can logout', logout);
|
||||||
|
|
||||||
it('can update', async function () {
|
it('can update', cloudronCli.update);
|
||||||
await browser.get('about:blank');
|
|
||||||
execSync('cloudron update --app ' + LOCATION, EXEC_ARGS);
|
|
||||||
await timers.setTimeout(30000);
|
|
||||||
});
|
|
||||||
it('can login', login.bind(null, username, password));
|
it('can login', login.bind(null, username, password));
|
||||||
it('can check folder', checkFolder);
|
it('can check folder', checkFolder);
|
||||||
|
|
||||||
it('uninstall app', async function () {
|
it('uninstall app', cloudronCli.uninstall);
|
||||||
await browser.get('about:blank');
|
|
||||||
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user