123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #!/usr/bin/env node
- 'use strict';
- 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;
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
- describe('Application life cycle test', function () {
- this.timeout(0);
- var chrome = require('selenium-webdriver/chrome');
- var server, browser = new chrome.Driver(), uploadedImageUrl;
- var username = 'admin', password = 'changeme';
- 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();
- done();
- });
- after(function (done) {
- browser.quit();
- server.stop();
- done();
- });
- var LOCATION = 'test';
- var TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 30000;
- var app;
- var email, token;
- function login(done) {
- browser.manage().window().setSize(1280,768);
- browser.manage().deleteAllCookies();
- browser.get('https://' + app.fqdn + '/login').then(function () {
- return browser.executeScript('localStorage.clear();');
- }).then(function () {
- return browser.get('https://' + app.fqdn + '/login');
- }).then(function () {
- return browser.sleep(5000); // takes some time for username to be visible
- }).then(function () {
- return browser.wait(until.elementLocated(by.id('username')), TEST_TIMEOUT);
- }).then(function () {
- return browser.findElement(by.id('username')).sendKeys(username);
- }).then(function () {
- return browser.findElement(by.id('password')).sendKeys(password);
- }).then(function () {
- return browser.findElement(by.id('login')).click();
- }).then(function () {
- return browser.wait(until.elementLocated(by.xpath('//a[contains(text(), "Announcements")]')), TEST_TIMEOUT);
- }).then(function () {
- done();
- });
- }
- function checkMailPlugin(done) {
- browser.get('https://' + app.fqdn + '/admin/emailers/local').then(function () {
- return browser.wait(until.elementLocated(by.id('host')), TEST_TIMEOUT);
- }).then(function () {
- return browser.sleep(5000);
- }).then(function () {
- return browser.findElement(by.id('host')).getAttribute('value');
- }).then(function (val) {
- if (val !== 'mail') return done(new Error('Incorrect mail server value: ' + val));
- done();
- });
- }
- function restartForum(done) {
- browser.get('https://' + app.fqdn + '/admin').then(function () {
- return browser.sleep(3000);
- }).then(function () {
- return browser.findElement(by.xpath('//button[text()="Restart"]')).click();
- }).then(function () {
- return browser.sleep(3000);
- }).then(function () {
- return browser.findElement(by.xpath('//button[text()="Confirm"]')).click();
- }).then(function () {
- console.log('Waiting for forum to restart');
- return browser.sleep(40000); // wait 30secs for reload
- }).then(function () {
- return browser.get('https://' + app.fqdn + '/admin');
- }).then(function () {
- return browser.sleep(3000);
- }).then(function () {
- return browser.findElement(by.xpath('//h1[text()="Dashboard"]'))
- }).then(function () { done(); });
- }
- function installCustomPlugin(done) {
- execSync('cloudron exec --app ' + app.id + ' -- /usr/local/bin/gosu cloudron:cloudron npm install nodebb-plugin-beep', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- done();
- }
- function activateCustomPlugin(done) {
- browser.get('https://' + app.fqdn + '/admin/extend/plugins#installed').then(function () {
- return browser.wait(until.elementLocated(by.xpath('//ul[contains(@class, "installed")]//strong[text()="nodebb-plugin-beep"]')), TEST_TIMEOUT);
- }).then(function () {
- return browser.sleep(10000);
- }).then(function () {
- return browser.findElement(by.xpath('//li[@id="nodebb-plugin-beep"]//button[@data-action="toggleActive"]')).click(); // activate the plugin
- }).then(function () {
- return browser.wait(until.elementLocated(by.xpath('//button[text()="Confirm"]')), TEST_TIMEOUT);
- }).then(function () {
- var button = browser.findElement(by.xpath('//button[text()="Confirm"]'));
- return browser.executeScript('arguments[0].scrollIntoView(false)', button);
- }).then(function () {
- return browser.findElement(by.xpath('//button[text()="Confirm"]')).click();
- }).then(function () {
- return browser.sleep(20000); // wait for the action to succeed
- }).then(function() {
- done();
- });
- }
- function listCustomPlugin(done) {
- browser.get('https://' + app.fqdn + '/admin/extend/plugins#installed').then(function () {
- return browser.wait(until.elementLocated(by.xpath('//strong[text()="nodebb-plugin-beep"]')), TEST_TIMEOUT);
- }).then(function () {
- done();
- });
- }
- function uploadImage(done) {
- browser.get('https://' + app.fqdn + '/user/admin/edit').then(function () {
- return browser.wait(until.elementLocated(by.xpath('//a[text()="Change Picture"]')), TEST_TIMEOUT);
- }).then(function () {
- var button = browser.findElement(by.xpath('//a[text()="Change Picture"]'));
- return browser.executeScript('arguments[0].scrollIntoView(false)', button);
- }).then(function () {
- return browser.findElement(by.xpath('//a[text()="Change Picture"]')).click();
- }).then(function () {
- return browser.sleep(4000);
- }).then(function () {
- return browser.findElement(by.xpath('//button[@data-action="upload"]')).click();
- }).then(function () {
- return browser.sleep(4000);
- }).then(function () {
- return browser.findElement(by.xpath('//input[@type="file"]')).sendKeys(path.resolve(__dirname, '../logo.png'));
- }).then(function () {
- browser.sleep(3000);
- }).then(function () { // upload it
- return browser.findElement(by.id('fileUploadSubmitBtn')).click();
- }).then(function () {
- browser.sleep(3000);
- }).then(function () {
- return browser.findElement(by.xpath('//button[text()="Crop and upload"]')).click();
- }).then(function () {
- return browser.sleep(3000);
- }).then(function () {
- done();
- });
- }
- function checkImage(done) {
- browser.get('https://' + app.fqdn + '/user/admin').then(function () {
- return browser.wait(until.elementLocated(by.xpath('//img[@src="/assets/uploads/profile/1-profileavatar.png"]')), TEST_TIMEOUT);
- }).then(function () {
- var img = browser.findElement(by.xpath('//img[@src="/assets/uploads/profile/1-profileavatar.png"]'));
- return browser.executeScript('return arguments[0].complete && arguments[0].naturalWidth', img);
- }).then(function (imageWidth) {
- done(imageWidth === 200 ? null : new Error('failed to load image'));
- });
- }
- xit('build app', function () {
- execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('install app', function () {
- execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('can get app information', function () {
- var inspect = JSON.parse(execSync('cloudron inspect'));
- app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
- expect(app).to.be.an('object');
- });
- it('can login', login);
- it('check mail plugin', checkMailPlugin);
- it('can install custom plugin', installCustomPlugin);
- it('can restart forum', restartForum); // required before activate!
- it('can activate custom plugin', activateCustomPlugin);
- it('can list custom plugin', listCustomPlugin);
- it('can upload image', uploadImage);
- it('can check image', checkImage);
- it('backup app', function () {
- execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('restore app', function () {
- execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('can login', login);
- it('can list custom plugin', listCustomPlugin);
- it('can check image', checkImage);
- it('can restart app', function (done) {
- execSync('cloudron restart --wait --app ' + app.id);
- done();
- });
- it('can login', login);
- it('can list custom plugin', listCustomPlugin);
- it('can check image', checkImage);
- it('move to different location', function () {
- execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- 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');
- });
- it('can login', login);
- it('can list custom plugin', listCustomPlugin);
- it('can check image', checkImage);
- it('uninstall app', function () {
- execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- // test update
- it('can install app', function () {
- execSync('cloudron install --new --wait --appstore-id org.nodebb.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- var inspect = JSON.parse(execSync('cloudron inspect'));
- app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
- expect(app).to.be.an('object');
- });
- it('can login', login);
- it('check mail plugin', checkMailPlugin);
- it('can update', function () {
- execSync('cloudron install --wait --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- it('check mail plugin', checkMailPlugin);
- it('uninstall app', function () {
- execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
- });
- });
|