Fixup tests

This commit is contained in:
Johannes Zellner 2022-01-02 16:43:53 +01:00
parent 404754f9a4
commit f3e4134dd5
3 changed files with 61 additions and 88 deletions

11
test/package-lock.json generated
View File

@ -15,7 +15,6 @@
"mkdirp": "^1.0.4",
"mocha": "^9.1.3",
"rimraf": "^3.0.2",
"selenium-server-standalone-jar": "^3.141.59",
"selenium-webdriver": "^4.1.0",
"superagent": "^6.1.0"
}
@ -1526,11 +1525,6 @@
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"node_modules/selenium-server-standalone-jar": {
"version": "3.141.59",
"resolved": "https://registry.npmjs.org/selenium-server-standalone-jar/-/selenium-server-standalone-jar-3.141.59.tgz",
"integrity": "sha512-gh7LagmKMkthQZo0q9qrDSWy+ISYnCUhOUW6IyRQIMGdg8Os/uMfChTDO17DYzxKmNIDx/h6+yfBj34QYALycw=="
},
"node_modules/selenium-webdriver": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-4.1.0.tgz",
@ -2991,11 +2985,6 @@
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"selenium-server-standalone-jar": {
"version": "3.141.59",
"resolved": "https://registry.npmjs.org/selenium-server-standalone-jar/-/selenium-server-standalone-jar-3.141.59.tgz",
"integrity": "sha512-gh7LagmKMkthQZo0q9qrDSWy+ISYnCUhOUW6IyRQIMGdg8Os/uMfChTDO17DYzxKmNIDx/h6+yfBj34QYALycw=="
},
"selenium-webdriver": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/selenium-webdriver/-/selenium-webdriver-4.1.0.tgz",

View File

@ -15,7 +15,6 @@
"mkdirp": "^1.0.4",
"mocha": "^9.1.3",
"rimraf": "^3.0.2",
"selenium-server-standalone-jar": "^3.141.59",
"selenium-webdriver": "^4.1.0",
"superagent": "^6.1.0"
}

View File

@ -1,5 +1,11 @@
#!/usr/bin/env node
/* jshint esversion: 8 */
/* global describe */
/* global before */
/* global after */
/* global it */
'use strict';
require('chromedriver');
@ -8,12 +14,8 @@ var execSync = require('child_process').execSync,
expect = require('expect.js'),
path = require('path'),
superagent = require('superagent'),
webdriver = require('selenium-webdriver');
var by = webdriver.By,
Keys = webdriver.Key,
until = webdriver.until,
Builder = require('selenium-webdriver').Builder;
{ Builder, By, Key, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome');
var username = 'admin',
password = 'changeme';
@ -21,32 +23,34 @@ var username = 'admin',
describe('Application life cycle test', function () {
this.timeout(0);
var server, browser = new Builder().forBrowser('chrome').build();
const LOCATION = 'test';
const TEST_TIMEOUT = 10000;
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
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();
var browser, app;
done();
before(function () {
const options = new Options().windowSize({ width: 1280, height: 1024 });
if (process.env.HEADLESS) options.addArguments('headless');
browser = new Builder().forBrowser('chrome').setChromeOptions(options).build();
});
after(function (done) {
after(function () {
browser.quit();
server.stop();
done();
});
var LOCATION = 'test';
var TEST_TIMEOUT = 10000;
var app;
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 exists(selector) {
return browser.wait(until.elementLocated(selector), TEST_TIMEOUT);
}
function visible(selector, callback) {
function visible(selector) {
return exists(selector).then(function () {
return browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT);
});
@ -62,9 +66,9 @@ describe('Application life cycle test', function () {
// https://stackoverflow.com/questions/49614217/selenium-clear-chrome-cache
// defaut clearance is 1 hour of cache
return browser.get('chrome://settings/clearBrowserData').then(function () {
return visible(by.css('* /deep/ #clearBrowsingDataConfirm'));
return visible(By.css('* /deep/ #clearBrowsingDataConfirm'));
}).then(function () {
return browser.findElement(by.css('* /deep/ #clearBrowsingDataConfirm')).click();
return browser.findElement(By.css('* /deep/ #clearBrowsingDataConfirm')).click();
}).then(function () {
return browser.sleep(5000);
});
@ -72,33 +76,33 @@ describe('Application life cycle test', function () {
function login(password, callback) {
browser.get('https://' + app.fqdn).then(function () {
return visible(by.id('loginButton'));
return visible(By.id('loginButton'));
}).then(function () {
return browser.findElement(by.id('username')).sendKeys(username);
return browser.findElement(By.id('username')).sendKeys(username);
}).then(function () {
return browser.findElement(by.id('passwordPlain')).sendKeys(password);
return browser.findElement(By.id('passwordPlain')).sendKeys(password);
}).then(function () {
return browser.findElement(by.id('loginButton')).click();
return browser.findElement(By.id('loginButton')).click();
}).then(function () {
return browser.wait(until.elementLocated(by.id('dropdown-configure')), TEST_TIMEOUT);
return browser.wait(until.elementLocated(By.id('dropdown-configure')), TEST_TIMEOUT);
}).then(function () {
callback();
});
}
function logout(callback) {
var logout_btn = by.xpath('//ul[@class="dropdown-menu"]/li/a[@class="signout"]');
var logout_btn = By.xpath('//li/a[@class="signout"]');
browser.get('https://' + app.fqdn).then(function () {
return visible(by.id('stream'));
return visible(By.id('stream'));
}).then(function () {
return browser.findElement(by.className('dropdown-toggle')).click();
return browser.findElement(By.className('dropdown-toggle')).click();
}).then(function () {
return visible(logout_btn);
}).then(function () {
return browser.findElement(logout_btn).click();
}).then(function () {
return browser.wait(until.elementLocated(by.id('loginButton')), TEST_TIMEOUT);
return browser.wait(until.elementLocated(By.id('loginButton')), TEST_TIMEOUT);
}).then(function () {
callback();
});
@ -109,13 +113,13 @@ describe('Application life cycle test', function () {
const addUrl = app.manifest.version === '1.10.0' ? `${baseUrl()}/i/?c=subscription` : `${baseUrl()}/i/?c=subscription&a=add`;
browser.get(addUrl).then(function () {
return visible(by.xpath('//input[@name="url_rss"]'));
return visible(By.xpath('//input[@name="url_rss"]'));
}).then(function () {
return browser.findElement(by.xpath('//input[@name="url_rss"]')).sendKeys(url);
return browser.findElement(By.xpath('//input[@name="url_rss"]')).sendKeys(url);
}).then(function () {
return browser.findElement(by.xpath('//button[@type="submit"]/ancestor::form[@id="add_rss"]')).submit();
return browser.findElement(By.xpath('//button[@type="submit"]/ancestor::form[@id="add_rss"]')).submit();
}).then(function () {
return visible(by.xpath('//div[@id="notification" and @class="notification good"]'));
return visible(By.xpath('//div[@id="notification" and @class="notification good"]'));
}).then(function () {
callback();
});
@ -125,15 +129,15 @@ describe('Application life cycle test', function () {
var test_username = 'test';
browser.get(`${baseUrl()}/i/?c=user&a=manage`).then(function () {
return visible(by.id('new_user_name'));
return visible(By.id('new_user_name'));
}).then(function () {
return browser.findElement(by.id('new_user_name')).sendKeys(test_username);
return browser.findElement(By.id('new_user_name')).sendKeys(test_username);
}).then(function () {
return browser.findElement(by.id('new_user_passwordPlain')).sendKeys(password);
return browser.findElement(By.id('new_user_passwordPlain')).sendKeys(password);
}).then(function () {
return browser.findElement(by.xpath('//button[text()="Create"]')).click();
return browser.findElement(By.xpath('//button[text()="Create"]')).click();
}).then(function () {
return visible(by.xpath('//div[@id="notification" and @class="notification good"]'));
return visible(By.xpath('//div[@id="notification" and @class="notification good"]'));
}).then(function () {
callback();
});
@ -141,9 +145,9 @@ describe('Application life cycle test', function () {
function enableApi(callback) {
browser.get(`${baseUrl()}/i/?c=auth`).then(function () {
return browser.findElement(by.id('api_enabled')).click();
return browser.findElement(By.id('api_enabled')).click();
}).then(function () {
return browser.findElement(by.xpath('//button[text()="Submit"]')).submit();
return browser.findElement(By.xpath('//button[text()="Submit"]')).click();
}).then(function () {
callback();
});
@ -151,23 +155,17 @@ describe('Application life cycle test', function () {
function checkApiConfiguration(callback) {
browser.get(`${baseUrl()}/api/`).then(function () {
return exists(by.xpath('//dd[@id="greaderOutput" and contains(text(), "PASS")]'));
return exists(By.xpath('//dd[@id="greaderOutput" and contains(text(), "PASS")]'));
}).then(function () {
return exists(by.xpath('//dd[@id="feverOutput" and contains(text(), "PASS")]'));
return exists(By.xpath('//dd[@id="feverOutput" and contains(text(), "PASS")]'));
}).then(function () {
callback();
});
}
function getAppInfo() {
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
expect(app).to.be.an('object');
}
function subscriptionExists(callback) {
browser.get(`${baseUrl()}/i/?get=c_1`).then(function () {
return visible(by.xpath('//span[text()="Cloudron"]'));
return visible(By.xpath('//span[text()="Cloudron"]'));
}).then(function () {
callback();
});
@ -184,13 +182,8 @@ describe('Application life cycle test', function () {
});
}
xit('build app', function () {
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('install app', function () {
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
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);
@ -203,16 +196,14 @@ describe('Application life cycle test', function () {
it('can get static extension file', getStaticExtensionFile);
it('can logout', logout);
it('backup app', function () {
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
it('restore app', function () {
const backups = JSON.parse(execSync('cloudron backup list --raw'));
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
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}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
});
it('can login', login.bind(null, password));
@ -223,7 +214,7 @@ describe('Application life cycle test', function () {
it('move to different location', function () {
browser.manage().deleteAllCookies();
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_ARGS);
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');
@ -235,14 +226,10 @@ describe('Application life cycle test', function () {
it('can get static extension file', getStaticExtensionFile);
it('can logout', logout);
it('uninstall app', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
// test update
it('can install app', function () {
execSync('cloudron install --appstore-id org.freshrss.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('can install app', function () { execSync('cloudron install --appstore-id org.freshrss.cloudronapp --location ' + LOCATION, EXEC_ARGS); });
it('can get app information', getAppInfo);
it('can login', login.bind(null, password));
@ -250,7 +237,7 @@ describe('Application life cycle test', function () {
it('can add users', addUser.bind(null, password));
it('can update', function () {
execSync('cloudron update --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
execSync('cloudron update --app ' + app.id, EXEC_ARGS);
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
expect(app).to.be.an('object');
@ -260,7 +247,5 @@ describe('Application life cycle test', function () {
it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile);
it('uninstall app', function () {
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
});
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
});