test.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 = 'wptest';
  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 upload media', function (done) {
  81. browser.get('https://' + app.fqdn + '/wp-admin/media-new.php?browser-uploader');
  82. browser.wait(until.elementLocated(by.id('async-upload')), 4000);
  83. browser.findElement(by.xpath('//input[@id="async-upload" and @type="file"]')).sendKeys(path.resolve(__dirname, '../icon.png'));
  84. browser.findElement(by.id('html-upload')).click();
  85. browser.wait(function () {
  86. return browser.getCurrentUrl().then(function (url) {
  87. return url === 'https://' + app.fqdn + '/wp-admin/upload.php';
  88. });
  89. }, 4000).then(function () { done(); });
  90. });
  91. var mediaLink;
  92. it('can see media', function (done) {
  93. browser.get('https://' + app.fqdn + '/wp-admin/upload.php?item=5'); // there's got to be a better way..
  94. browser.wait(until.elementLocated(by.xpath('//*[text()="Attachment Details"]')), 4000);
  95. browser.findElement(by.xpath('//img[@class="details-image"]')).getAttribute('src').then(function (srcLink) {
  96. console.log('media is located at ', srcLink);
  97. mediaLink = srcLink;
  98. done();
  99. });
  100. });
  101. it('can restart app', function (done) {
  102. execSync('cloudron restart');
  103. done();
  104. });
  105. it('can see updated post', function (done) {
  106. browser.get('https://' + app.fqdn);
  107. browser.findElement(by.xpath('//*[text()="Hello Cloudron!"]')).then(function () { done(); });
  108. });
  109. it('can see media', function (done) {
  110. superagent.get(mediaLink).end(function (error, result) {
  111. expect(error).to.be(null);
  112. expect(result.statusCode).to.be(200);
  113. done();
  114. });
  115. });
  116. it('backup app', function () {
  117. execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  118. });
  119. it('restore app', function () {
  120. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  121. });
  122. it('can see updated post', function (done) {
  123. browser.get('https://' + app.fqdn);
  124. browser.findElement(by.xpath('//*[text()="Hello Cloudron!"]')).then(function () { done(); });
  125. });
  126. it('can see media', function (done) {
  127. superagent.get(mediaLink).end(function (error, result) {
  128. expect(error).to.be(null);
  129. expect(result.statusCode).to.be(200);
  130. done();
  131. });
  132. });
  133. it('can login', function (done) {
  134. browser.get('https://' + app.fqdn + '/wp-login.php');
  135. browser.findElement(by.id('user_login')).sendKeys(username);
  136. browser.findElement(by.id('user_pass')).sendKeys(password);
  137. browser.findElement(by.tagName('form')).submit();
  138. browser.wait(until.elementLocated(by.xpath('//h1[text()="Dashboard"]')), 4000).then(function () { done(); });
  139. });
  140. it('move to different location', function () {
  141. browser.manage().deleteAllCookies();
  142. execSync('cloudron install --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  143. var inspect = JSON.parse(execSync('cloudron inspect'));
  144. app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
  145. expect(app).to.be.an('object');
  146. mediaLink = mediaLink.replace(LOCATION, LOCATION + '2');
  147. });
  148. it('can see updated post', function (done) {
  149. browser.get('https://' + app.fqdn);
  150. browser.findElement(by.xpath('//*[text()="Hello Cloudron!"]')).then(function () { done(); });
  151. });
  152. it('can see media', function (done) {
  153. superagent.get(mediaLink).end(function (error, result) {
  154. expect(error).to.be(null);
  155. expect(result.statusCode).to.be(200);
  156. done();
  157. });
  158. });
  159. it('can login', function (done) {
  160. browser.get('https://' + app.fqdn + '/wp-login.php');
  161. browser.findElement(by.id('user_login')).sendKeys(username);
  162. browser.findElement(by.id('user_pass')).sendKeys(password);
  163. browser.findElement(by.tagName('form')).submit();
  164. browser.wait(until.elementLocated(by.xpath('//h1[text()="Dashboard"]')), 4000).then(function () { done(); });
  165. });
  166. it('uninstall app', function () {
  167. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  168. });
  169. });