test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var execSync = require('child_process').execSync,
  4. expect = require('expect.js'),
  5. path = require('path'),
  6. superagent = require('superagent'),
  7. webdriver = require('selenium-webdriver');
  8. var by = webdriver.By,
  9. Keys = webdriver.Key,
  10. until = webdriver.until;
  11. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  12. describe('Application life cycle test', function () {
  13. this.timeout(0);
  14. var chrome = require('selenium-webdriver/chrome');
  15. var server, browser = new chrome.Driver(), uploadedImageUrl;
  16. var username = 'admin', password = 'changeme';
  17. before(function (done) {
  18. var seleniumJar= require('selenium-server-standalone-jar');
  19. var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
  20. server = new SeleniumServer(seleniumJar.path, { port: 4444 });
  21. server.start();
  22. done();
  23. });
  24. after(function (done) {
  25. browser.quit();
  26. server.stop();
  27. done();
  28. });
  29. var LOCATION = 'nodebbtest';
  30. var TEST_TIMEOUT = parseInt(process.env.TEST_TIMEOUT, 10) || 5000;
  31. var app;
  32. var email, token;
  33. function login(done) {
  34. browser.manage().deleteAllCookies();
  35. browser.get('https://' + app.fqdn + '/login');
  36. browser.executeScript('localStorage.clear();')
  37. browser.get('https://' + app.fqdn + '/login');
  38. browser.wait(until.elementLocated(by.id('username')), TEST_TIMEOUT).then(function () {
  39. browser.findElement(by.id('username')).sendKeys(username);
  40. browser.findElement(by.id('password')).sendKeys(password);
  41. browser.findElement(by.id('login')).click();
  42. browser.wait(until.elementLocated(by.xpath('//a[contains(text(), "Announcements")]')), TEST_TIMEOUT).then(function () { done(); });
  43. });
  44. }
  45. xit('build app', function () {
  46. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  47. });
  48. it('install app', function () {
  49. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  50. });
  51. it('can get app information', function () {
  52. var inspect = JSON.parse(execSync('cloudron inspect'));
  53. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  54. expect(app).to.be.an('object');
  55. });
  56. it('can login', function (done) {
  57. login(done);
  58. });
  59. it('backup app', function () {
  60. execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  61. });
  62. it('restore app', function () {
  63. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  64. });
  65. it('can login', function (done) {
  66. login(done);
  67. });
  68. it('can restart app', function (done) {
  69. execSync('cloudron restart');
  70. done();
  71. });
  72. it('can login', function (done) {
  73. login(done);
  74. });
  75. it('move to different location', function () {
  76. execSync('cloudron install --wait --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  77. var inspect = JSON.parse(execSync('cloudron inspect'));
  78. app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
  79. expect(app).to.be.an('object');
  80. });
  81. it('can login', function (done) {
  82. login(done);
  83. });
  84. it('uninstall app', function () {
  85. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  86. });
  87. });