Commit 3809882a authored by Johannes Zellner's avatar Johannes Zellner

Update tests

parent 7ecbb2a7
#!/usr/bin/env node
/* global describe, before, after, xit, it */
'use strict'
'use strict';
require('chromedriver')
require('chromedriver');
const execSync = require('child_process').execSync
const expect = require('expect.js')
const net = require('net')
const path = require('path')
const selenium = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome')
const by = selenium.By
const until = selenium.until
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
selenium.promise.USE_PROMISE_MANAGER = false
const VPN_TCP_PORT = 7333
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }
const DEVICE_NAME = 'test_DeV1ce-3'
var execSync = require('child_process').execSync,
expect = require('expect.js'),
path = require('path'),
net = require('net'),
{ Builder, By, Key, 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)
console.log('USERNAME and PASSWORD env vars need to be set');
process.exit(1);
}
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
// selenium.promise.USE_PROMISE_MANAGER = false
describe('Application life cycle test', function () {
this.timeout(0)
let browser
const username = process.env.USERNAME
const password = process.env.PASSWORD
before(function () {
browser = new selenium.Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options().addArguments(['no-sandbox' /*, 'headless' */]))
.build()
})
after(function () {
browser.quit()
})
const LOCATION = 'test'
const TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 20000
let app
function waitForElement (elem) {
return browser.wait(until.elementLocated(elem), TEST_TIMEOUT)
.then(() => browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT))
}
function getAppInfo () {
const inspect = JSON.parse(execSync('cloudron inspect'))
app = inspect.apps.filter(a => a.location === LOCATION || a.location === LOCATION + '2')[0]
expect(app).to.be.an('object')
}
function login () {
console.log('Logging in...')
return browser.manage().deleteAllCookies()
.then(() => console.log('Cookies deleted'))
.then(() => browser.get('https://' + app.fqdn))
.then(() => console.log('Page loaded'))
.then(() => browser.wait(until.elementLocated(by.id('loginUsername')), TEST_TIMEOUT))
.then(() => console.log('Login page loaded'))
.then(() => browser.findElement(by.id('loginUsername')).sendKeys(username))
.then(() => browser.findElement(by.id('loginPassword')).sendKeys(password))
.then(() => browser.findElement(by.id('loginButton')).click())
.then(() => console.log('Login clicked'))
.then(() => browser.wait(until.elementLocated(by.id('logoutButton')), TEST_TIMEOUT))
.then(() => console.log('Logged in'))
}
function logout () {
console.log('Logging out...')
return waitForElement(by.id('logoutButton'))
.then(() => browser.findElement(by.id('logoutButton')).click())
.then(() => waitForElement(by.id('loginButton')))
.then(() => console.log('Logged out'))
}
function createDevice (name) {
console.log('Creating device...')
return waitForElement(by.id('newDeviceButton'))
.then(() => browser.findElement(by.id('newDeviceButton')).click())
.then(() => console.log('Open Dialog'))
.then(() => waitForElement(by.xpath('/html/body/div[2]/div/div[2]/div/div[1]/input')))
.then(() => browser.findElement(by.xpath('/html/body/div[2]/div/div[2]/div/div[1]/input')).sendKeys(name))
.then(() => browser.findElement(by.xpath('/html/body/div[2]/div/div[3]/button[2]')).click())
.then(() => console.log('Device created'))
.then(() => browser.sleep(2000))
}
function checkDeviceExists (name) {
return browser.wait(until.elementLocated(by.xpath(`//div[text()="${name}"]`)), TEST_TIMEOUT)
}
function checkVpn (done) {
const client = net.connect({host: app.fqdn, port: VPN_TCP_PORT}, () => {
client.end()
done()
})
client.on('error', done)
}
xit('build app', function () { execSync('cloudron build', EXEC_ARGS) })
it('install app', function () { execSync('cloudron install --location ' + LOCATION + ' -p VPN_TCP_PORT=' + VPN_TCP_PORT, EXEC_ARGS) })
it('can get app information', getAppInfo)
it('can login', login)
it('can create device', () => createDevice(DEVICE_NAME))
it('device exists', () => checkDeviceExists(DEVICE_NAME))
it('check vpn', checkVpn)
it('can logout', logout)
it('can restart app', function () { execSync('cloudron restart --app ' + app.id, EXEC_ARGS) })
it('can login', login)
it('device exists', () => checkDeviceExists(DEVICE_NAME))
it('check vpn', checkVpn)
it('can logout', logout)
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, EXEC_ARGS)
execSync('cloudron install --location ' + LOCATION + ' -p VPN_TCP_PORT=' + VPN_TCP_PORT, EXEC_ARGS)
getAppInfo()
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS)
});
it('can login', login)
it('device exists', () => checkDeviceExists(DEVICE_NAME))
it('check vpn', checkVpn)
it('can logout', logout)
it('move to different location', function () { execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_ARGS) })
it('can get new app information', getAppInfo)
it('can login', login)
it('device exists', () => checkDeviceExists(DEVICE_NAME))
it('check vpn', checkVpn)
it('can logout', logout)
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS) })
// test update (this test will only work after app is published)
it('can install app', function () { execSync('cloudron install --appstore-id io.cloudron.openvpn --location ' + LOCATION + ' -p VPN_TCP_PORT=' + VPN_TCP_PORT, EXEC_ARGS) })
it('can get app information', getAppInfo)
it('can login', login)
it('can create device', () => createDevice(DEVICE_NAME))
it('device exists', () => checkDeviceExists(DEVICE_NAME))
it('can logout', logout)
it('can update', function () { execSync('cloudron update --app ' + app.id, EXEC_ARGS) })
it('can login', login)
it('device exists', () => checkDeviceExists(DEVICE_NAME))
it('check vpn', checkVpn)
it('can logout', logout)
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS) })
})
this.timeout(0);
const VPN_TCP_PORT = 7333;
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
const DEVICE_NAME = 'test_DeV1ce-3';
const LOCATION = 'test';
const TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 20000;
const username = process.env.USERNAME;
const password = process.env.PASSWORD;
var browser;
var app;
before(function () {
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
});
after(function () {
browser.quit();
});
function waitForElement (elem) {
return browser.wait(until.elementLocated(elem), TEST_TIMEOUT)
.then(() => browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT));
}
function getAppInfo () {
const inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(a => a.location === LOCATION || a.location === LOCATION + '2')[0];
expect(app).to.be.an('object');
}
function login () {
console.log('Logging in...');
return browser.manage().deleteAllCookies()
.then(() => console.log('Cookies deleted'))
.then(() => browser.get('https://' + app.fqdn))
.then(() => console.log('Page loaded'))
.then(() => browser.wait(until.elementLocated(By.id('loginUsername')), TEST_TIMEOUT))
.then(() => console.log('Login page loaded'))
.then(() => browser.findElement(By.id('loginUsername')).sendKeys(username))
.then(() => browser.findElement(By.id('loginPassword')).sendKeys(password))
.then(() => browser.findElement(By.id('loginButton')).click())
.then(() => console.log('Login clicked'))
.then(() => browser.wait(until.elementLocated(By.id('logoutButton')), TEST_TIMEOUT))
.then(() => console.log('Logged in'));
}
function logout () {
console.log('Logging out...');
return waitForElement(By.id('logoutButton'))
.then(() => browser.findElement(By.id('logoutButton')).click())
.then(() => waitForElement(By.id('loginButton')))
.then(() => console.log('Logged out'));
}
function createDevice (name) {
console.log('Creating device...');
return waitForElement(By.id('newDeviceButton'))
.then(() => browser.findElement(By.id('newDeviceButton')).click())
.then(() => console.log('Open Dialog'))
.then(() => waitForElement(By.xpath('/html/body/div[2]/div/div[2]/div/div[1]/input')))
.then(() => browser.findElement(By.xpath('/html/body/div[2]/div/div[2]/div/div[1]/input')).sendKeys(name))
.then(() => browser.findElement(By.xpath('/html/body/div[2]/div/div[3]/button[2]')).click())
.then(() => console.log('Device created'))
.then(() => browser.sleep(2000));
}
function checkDeviceExists (name) {
return browser.wait(until.elementLocated(By.xpath(`//div[text()="${name}"]`)), TEST_TIMEOUT);
}
function checkVpn (done) {
const client = net.connect({host: app.fqdn, port: VPN_TCP_PORT}, () => {
client.end();
done();
});
client.on('error', done);
}
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
it('install app', function () { execSync('cloudron install --location ' + LOCATION + ' -p VPN_TCP_PORT=' + VPN_TCP_PORT, EXEC_ARGS); });
it('can get app information', getAppInfo);
it('can login', login);
it('can create device', () => createDevice(DEVICE_NAME));
it('device exists', () => checkDeviceExists(DEVICE_NAME));
it('check vpn', checkVpn);
it('can logout', logout);
it('can restart app', function () { execSync('cloudron restart --app ' + app.id, EXEC_ARGS); });
it('can login', login);
it('device exists', () => checkDeviceExists(DEVICE_NAME));
it('check vpn', checkVpn);
it('can logout', logout);
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 --app ${app.id}`));
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
execSync('cloudron install --location ' + LOCATION + ' -p VPN_TCP_PORT=' + VPN_TCP_PORT, EXEC_ARGS);
getAppInfo();
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
});
it('can login', login);
it('device exists', () => checkDeviceExists(DEVICE_NAME));
it('check vpn', checkVpn);
it('can logout', logout);
it('move to different location', function () { execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_ARGS); });
it('can get new app information', getAppInfo);
it('can login', login);
it('device exists', () => checkDeviceExists(DEVICE_NAME));
it('check vpn', checkVpn);
it('can logout', logout);
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
// test update (this test will only work after app is published)
it('can install app', function () { execSync('cloudron install --appstore-id io.cloudron.openvpn --location ' + LOCATION + ' -p VPN_TCP_PORT=' + VPN_TCP_PORT, EXEC_ARGS); });
it('can get app information', getAppInfo);
it('can login', login);
it('can create device', () => createDevice(DEVICE_NAME));
it('device exists', () => checkDeviceExists(DEVICE_NAME));
it('can logout', logout);
it('can update', function () { execSync('cloudron update --app ' + app.id, EXEC_ARGS); });
it('can login', login);
it('device exists', () => checkDeviceExists(DEVICE_NAME));
it('check vpn', checkVpn);
it('can logout', logout);
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment