test.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/usr/bin/env node
  2. /* jslint node:true */
  3. /* global it:false */
  4. /* global xit:false */
  5. /* global describe:false */
  6. /* global before:false */
  7. /* global after:false */
  8. 'use strict';
  9. var execSync = require('child_process').execSync,
  10. ejs = require('ejs'),
  11. expect = require('expect.js'),
  12. fs = require('fs'),
  13. mkdirp = require('mkdirp'),
  14. path = require('path'),
  15. rimraf = require('rimraf'),
  16. superagent = require('superagent'),
  17. webdriver = require('selenium-webdriver');
  18. var by = require('selenium-webdriver').By,
  19. until = require('selenium-webdriver').until,
  20. Key = require('selenium-webdriver').Key;
  21. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  22. describe('Application life cycle test', function () {
  23. this.timeout(0);
  24. var firefox = require('selenium-webdriver/firefox');
  25. var server, browser = new firefox.Driver();
  26. var LOCATION = 'wptest3';
  27. var app;
  28. var username = process.env.USERNAME;
  29. var password = process.env.PASSWORD;
  30. before(function (done) {
  31. if (!process.env.USERNAME) return done(new Error('USERNAME env var not set'));
  32. if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set'));
  33. var seleniumJar= require('selenium-server-standalone-jar');
  34. var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
  35. server = new SeleniumServer(seleniumJar.path, { port: 4444 });
  36. server.start();
  37. done();
  38. });
  39. after(function (done) {
  40. browser.quit();
  41. server.stop();
  42. done();
  43. });
  44. xit('build app', function () {
  45. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  46. });
  47. it('install app', function () {
  48. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  49. });
  50. it('can get app information', function () {
  51. var inspect = JSON.parse(execSync('cloudron inspect'));
  52. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  53. expect(app).to.be.an('object');
  54. });
  55. it('can get the main page', function (done) {
  56. superagent.get('https://' + app.fqdn).end(function (error, result) {
  57. expect(error).to.be(null);
  58. expect(result.status).to.eql(200);
  59. done();
  60. });
  61. });
  62. it('can login', function (done) {
  63. browser.get('https://' + app.fqdn + '/wp-login.php');
  64. browser.findElement(by.id('user_login')).sendKeys(username);
  65. browser.findElement(by.id('user_pass')).sendKeys(password);
  66. browser.findElement(by.tagName('form')).submit();
  67. browser.wait(until.elementLocated(by.xpath('//h1[text()="Dashboard"]')), 4000).then(function () { done(); });
  68. });
  69. it('is an admin dashboard', function (done) {
  70. browser.wait(until.elementLocated(by.xpath('//div[@class="wp-menu-name" and contains(text(), "Plugins")]')), 4000).then(function () { done(); });
  71. });
  72. it('can edit', function (done) {
  73. browser.get('https://' + app.fqdn + '/wp-admin/post.php?post=1&action=edit');
  74. browser.wait(until.elementLocated(by.xpath('//input[@id="title"]')), 4000);
  75. browser.findElement(by.xpath('//input[@id="title"]')).sendKeys(Key.chord(Key.CONTROL, 'a'));
  76. browser.findElement(by.xpath('//input[@id="title"]')).sendKeys('Hello Cloudron!');
  77. browser.findElement(by.xpath('//input[@id="publish"]')).click();
  78. browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "Post updated.")]')), 4000).then(function () { done(); });
  79. });
  80. it('can restart app', function (done) {
  81. execSync('cloudron restart');
  82. done();
  83. });
  84. it('can see updated post', function (done) {
  85. browser.get('https://' + app.fqdn);
  86. browser.findElement(by.xpath('//*[text()="Hello Cloudron!"]')).then(function () { done(); });
  87. });
  88. it('backup app', function () {
  89. execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  90. });
  91. it('restore app', function () {
  92. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  93. });
  94. it('can see updated post', function (done) {
  95. browser.get('https://' + app.fqdn);
  96. browser.findElement(by.xpath('//*[text()="Hello Cloudron!"]')).then(function () { done(); });
  97. });
  98. it('can login', function (done) {
  99. browser.get('https://' + app.fqdn + '/wp-login.php');
  100. browser.findElement(by.id('user_login')).sendKeys(username);
  101. browser.findElement(by.id('user_pass')).sendKeys(password);
  102. browser.findElement(by.tagName('form')).submit();
  103. browser.wait(until.elementLocated(by.xpath('//h1[text()="Dashboard"]')), 4000).then(function () { done(); });
  104. });
  105. it('move to different location', function () {
  106. browser.manage().deleteAllCookies();
  107. execSync('cloudron install --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  108. var inspect = JSON.parse(execSync('cloudron inspect'));
  109. app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
  110. expect(app).to.be.an('object');
  111. });
  112. it('can see updated post', function (done) {
  113. browser.get('https://' + app.fqdn);
  114. browser.findElement(by.xpath('//*[text()="Hello Cloudron!"]')).then(function () { done(); });
  115. });
  116. it('can login', function (done) {
  117. browser.get('https://' + app.fqdn + '/wp-login.php');
  118. browser.findElement(by.id('user_login')).sendKeys(username);
  119. browser.findElement(by.id('user_pass')).sendKeys(password);
  120. browser.findElement(by.tagName('form')).submit();
  121. browser.wait(until.elementLocated(by.xpath('//h1[text()="Dashboard"]')), 4000).then(function () { done(); });
  122. });
  123. it('uninstall app', function () {
  124. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  125. });
  126. });