test.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. webdriver = require('selenium-webdriver');
  7. var by = webdriver.By,
  8. until = webdriver.until;
  9. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  10. if (!process.env.USERNAME || !process.env.PASSWORD) {
  11. console.log('USERNAME and PASSWORD env vars need to be set');
  12. process.exit(1);
  13. }
  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 EVENT_TITLE = 'Meet the Cloudron Founders';
  32. var CONTACT_CN = 'Max Mustermann';
  33. var TEST_TIMEOUT = 50000;
  34. var app;
  35. function waitForElement(elem, callback) {
  36. browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
  37. browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT).then(function () {
  38. callback();
  39. });
  40. });
  41. }
  42. xit('build app', function () {
  43. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  44. });
  45. it('install app', function () {
  46. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  47. });
  48. it('can get app information', function () {
  49. var inspect = JSON.parse(execSync('cloudron inspect'));
  50. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  51. expect(app).to.be.an('object');
  52. });
  53. it('can login', function (done) {
  54. browser.manage().deleteAllCookies();
  55. browser.get('https://' + app.fqdn);
  56. waitForElement(by.id('input_1'),function () {
  57. browser.findElement(by.id('input_1')).sendKeys(process.env.USERNAME);
  58. browser.findElement(by.id('input_2')).sendKeys(process.env.PASSWORD);
  59. browser.findElement(by.name('loginForm')).submit();
  60. browser.wait(until.elementLocated(by.xpath('//*[@aria-label="New Event"]')), TEST_TIMEOUT).then(function () { done(); });
  61. });
  62. });
  63. it('can create event', function (done) {
  64. browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Calendar/view');
  65. waitForElement(by.xpath('//*[@aria-label="New Event"]'), function () {
  66. browser.findElement(by.xpath('//*[@aria-label="New Event"]')).click();
  67. // open animation
  68. browser.sleep(2000).then(function () {
  69. waitForElement(by.xpath('//*[@aria-label="Create a new event"]'), function () {
  70. browser.findElement(by.xpath('//*[@aria-label="Create a new event"]')).click();
  71. waitForElement(by.xpath('//*[@ng-model="editor.component.summary"]'), function () {
  72. browser.findElement(by.xpath('//*[@ng-model="editor.component.summary"]')).sendKeys(EVENT_TITLE);
  73. browser.findElement(by.xpath('//*[@ng-model="editor.component.summary"]')).submit();
  74. waitForElement(by.xpath('//*[@aria-label="' + EVENT_TITLE + '"]'), done);
  75. });
  76. });
  77. });
  78. });
  79. });
  80. it('event is present', function (done) {
  81. browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Calendar/view');
  82. waitForElement(by.xpath('//*[@aria-label="' + EVENT_TITLE + '"]'), done);
  83. });
  84. it('can create contact', function (done) {
  85. browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Contacts/view#/addressbooks/personal/card/new');
  86. waitForElement(by.xpath('//*[@aria-label="New Contact"]'), function () {
  87. browser.findElement(by.xpath('//*[@aria-label="New Contact"]')).click();
  88. // open animation
  89. browser.sleep(2000).then(function () {
  90. waitForElement(by.xpath('//*[@aria-label="Create a new address book card"]'), function () {
  91. browser.findElement(by.xpath('//*[@aria-label="Create a new address book card"]')).click();
  92. waitForElement(by.xpath('//*[@ng-model="editor.card.c_cn"]'), function () {
  93. browser.findElement(by.xpath('//*[@ng-model="editor.card.c_cn"]')).sendKeys(CONTACT_CN);
  94. browser.findElement(by.xpath('//*[@aria-label="Save"]')).click();
  95. waitForElement(by.xpath('//*[text()="' + CONTACT_CN + '"]'), done);
  96. });
  97. });
  98. });
  99. });
  100. });
  101. it('contact is present', function (done) {
  102. browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Contacts/view');
  103. waitForElement(by.xpath('//*[text()="' + CONTACT_CN + '"]'), function () {
  104. done();
  105. });
  106. });
  107. it('backup app', function () {
  108. execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  109. });
  110. it('restore app', function () {
  111. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  112. });
  113. it('can login', function (done) {
  114. browser.manage().deleteAllCookies();
  115. browser.get('https://' + app.fqdn);
  116. waitForElement(by.id('input_1'), function () {
  117. browser.findElement(by.id('input_1')).sendKeys(process.env.USERNAME);
  118. browser.findElement(by.id('input_2')).sendKeys(process.env.PASSWORD);
  119. browser.findElement(by.name('loginForm')).submit();
  120. waitForElement(by.xpath('//*[@aria-label="New Event"]'), done);
  121. });
  122. });
  123. it('event is still present', function (done) {
  124. browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Calendar/view');
  125. waitForElement(by.xpath('//*[@aria-label="' + EVENT_TITLE + '"]'), done);
  126. });
  127. it('contact is still present', function (done) {
  128. browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Contacts/view');
  129. waitForElement(by.xpath('//*[text()="' + CONTACT_CN + '"]'), done);
  130. });
  131. it('move to different location', function () {
  132. browser.manage().deleteAllCookies();
  133. execSync('cloudron configure --wait --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  134. var inspect = JSON.parse(execSync('cloudron inspect'));
  135. app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
  136. expect(app).to.be.an('object');
  137. });
  138. it('can login', function (done) {
  139. browser.manage().deleteAllCookies();
  140. browser.get('https://' + app.fqdn);
  141. waitForElement(by.id('input_1'), function () {
  142. browser.findElement(by.id('input_1')).sendKeys(process.env.USERNAME);
  143. browser.findElement(by.id('input_2')).sendKeys(process.env.PASSWORD);
  144. browser.findElement(by.name('loginForm')).submit();
  145. waitForElement(by.xpath('//*[@aria-label="New Event"]'), done);
  146. });
  147. });
  148. it('event is still present', function (done) {
  149. browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Calendar/view');
  150. waitForElement(by.xpath('//*[@aria-label="' + EVENT_TITLE + '"]'), done);
  151. });
  152. it('contact is still present', function (done) {
  153. browser.get('https://' + app.fqdn + '/SOGo/so/' + process.env.USERNAME + '/Contacts/view');
  154. waitForElement(by.xpath('//*[text()="' + CONTACT_CN + '"]'), done);
  155. });
  156. it('uninstall app', function () {
  157. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  158. });
  159. });