test.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #!/usr/bin/env node
  2. 'use strict';
  3. require('chromedriver');
  4. var execSync = require('child_process').execSync,
  5. expect = require('expect.js'),
  6. path = require('path'),
  7. webdriver = require('selenium-webdriver');
  8. var by = webdriver.By,
  9. until = webdriver.until;
  10. var accessKey = 'admin',
  11. secretKey = 'secretkey';
  12. var bucket = 'cloudrontestbucket';
  13. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  14. describe('Application life cycle test', function () {
  15. this.timeout(0);
  16. var chrome = require('selenium-webdriver/chrome');
  17. var server, browser = new chrome.Driver();
  18. before(function (done) {
  19. var seleniumJar= require('selenium-server-standalone-jar');
  20. var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
  21. server = new SeleniumServer(seleniumJar.path, { port: 4444 });
  22. server.start();
  23. done();
  24. });
  25. after(function (done) {
  26. browser.quit();
  27. server.stop();
  28. done();
  29. });
  30. var LOCATION = 'test';
  31. var TEST_TIMEOUT = 10000;
  32. var app;
  33. function pageLoaded() {
  34. return browser.wait(until.elementLocated(by.className('page-load pl-0 pl-1')), TEST_TIMEOUT);
  35. }
  36. function visible(selector) {
  37. return browser.wait(until.elementLocated(selector), TEST_TIMEOUT).then(function () {
  38. return browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT);
  39. });
  40. }
  41. function login(callback) {
  42. browser.manage().deleteAllCookies();
  43. browser.get('https://' + app.fqdn).then(function () {
  44. return visible(by.id('accessKey'));
  45. }).then(function () {
  46. return browser.findElement(by.id('accessKey')).sendKeys(accessKey);
  47. }).then(function () {
  48. return browser.findElement(by.id('secretKey')).sendKeys(secretKey);
  49. }).then(function () {
  50. // return browser.findElement(by.className('lw-btn')).click();
  51. return browser.findElement(by.tagName('form')).submit();
  52. }).then(function () {
  53. return browser.wait(until.elementLocated(by.id('top-right-menu')), TEST_TIMEOUT);
  54. }).then(function () {
  55. callback();
  56. });
  57. }
  58. function logout(callback) {
  59. browser.get('https://' + app.fqdn);
  60. pageLoaded().then(function () {
  61. return visible(by.id('top-right-menu'));
  62. }).then(function () {
  63. return browser.findElement(by.id('top-right-menu')).click();
  64. }).then(function () {
  65. return visible(by.xpath('//*[text()="Sign Out "]'));
  66. }).then(function () {
  67. return browser.findElement(by.xpath('//*[text()="Sign Out "]')).click();
  68. }).then(function () {
  69. return browser.wait(until.elementLocated(by.id('accessKey')), TEST_TIMEOUT);
  70. }).then(function () {
  71. callback();
  72. });
  73. }
  74. function addBucket(callback) {
  75. browser.get('https://' + app.fqdn);
  76. pageLoaded().then(function () {
  77. return visible(by.className('fa fa-plus'));
  78. }).then(function () {
  79. return browser.findElement(by.className('fa fa-plus')).click();
  80. }).then(function () {
  81. return visible(by.className('fa fa-hdd-o'));
  82. }).then(function () {
  83. return browser.findElement(by.className('fa fa-hdd-o')).click();
  84. }).then(function () {
  85. return visible(by.xpath('//*[@class="modal-body"]/form/div/input'));
  86. }).then(function () {
  87. return browser.findElement(by.xpath('//*[@class="modal-body"]/form/div/input')).sendKeys(bucket);
  88. }).then(function () {
  89. return browser.findElement(by.xpath('//*[@class="modal-body"]/form')).submit();
  90. }).then(function () {
  91. return visible(by.xpath('//*[@class="main"]/a[text()="' + bucket + '"]'));
  92. }).then(function () {
  93. callback();
  94. });
  95. }
  96. function checkBucket(callback) {
  97. browser.get('https://' + app.fqdn);
  98. pageLoaded().then(function () {
  99. return browser.findElement(by.xpath(`//a[contains(text(), ${bucket})]`));
  100. }).then(function () {
  101. callback();
  102. });
  103. }
  104. function openSettings(callback) {
  105. browser.get('https://' + app.fqdn);
  106. pageLoaded().then(function () {
  107. return visible(by.id('top-right-menu'));
  108. }).then(function () {
  109. return browser.findElement(by.id('top-right-menu')).click();
  110. }).then(function () {
  111. return visible(by.xpath('//*[contains(text(), "Change Password")]'));
  112. }).then(function () {
  113. return browser.findElement(by.xpath('//*[contains(text(),"Change Password")]')).click();
  114. }).then(function () {
  115. return browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "Change Password")]')), TEST_TIMEOUT);
  116. }).then(function () {
  117. callback();
  118. });
  119. }
  120. xit('build app', function () {
  121. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  122. });
  123. it('install app', function () {
  124. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  125. });
  126. it('can get app information', function () {
  127. var inspect = JSON.parse(execSync('cloudron inspect'));
  128. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  129. expect(app).to.be.an('object');
  130. });
  131. it('can login', login);
  132. it('can add bucket', addBucket);
  133. it('can open settings', openSettings);
  134. it('can logout', logout);
  135. it('can restart app', function (done) {
  136. execSync('cloudron restart --wait');
  137. done();
  138. });
  139. it('can login', login);
  140. it('has bucket', checkBucket);
  141. it('can logout', logout);
  142. it('backup app', function () {
  143. execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  144. });
  145. it('restore app', function () {
  146. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  147. });
  148. it('can login', login);
  149. it('has bucket', checkBucket);
  150. it('can open settings', openSettings);
  151. it('can logout', logout);
  152. it('move to different location', function () {
  153. browser.manage().deleteAllCookies();
  154. execSync('cloudron configure --wait --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  155. var inspect = JSON.parse(execSync('cloudron inspect'));
  156. app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
  157. expect(app).to.be.an('object');
  158. });
  159. it('can login', login);
  160. it('has bucket', checkBucket);
  161. it('can logout', logout);
  162. it('uninstall app', function () {
  163. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  164. });
  165. // test update
  166. it('can install app', function () {
  167. execSync('cloudron install --new --wait --appstore-id io.minio.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  168. var inspect = JSON.parse(execSync('cloudron inspect'));
  169. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  170. expect(app).to.be.an('object');
  171. });
  172. it('can login', login);
  173. it('can add buckets', addBucket);
  174. it('can logout', logout);
  175. it('can update', function () {
  176. execSync('cloudron install --wait --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  177. });
  178. it('can login', login);
  179. it('has bucket', checkBucket);
  180. it('can logout', logout);
  181. it('uninstall app', function () {
  182. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  183. });
  184. });