test.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. Keys = webdriver.Key,
  10. until = webdriver.until;
  11. process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
  12. if (!process.env.USERNAME || !process.env.PASSWORD) {
  13. console.log('USERNAME and PASSWORD env vars need to be set');
  14. process.exit(1);
  15. }
  16. describe('Application life cycle test SSO', function () {
  17. this.timeout(0);
  18. var chrome = require('selenium-webdriver/chrome');
  19. var server, browser = new chrome.Driver();
  20. before(function (done) {
  21. var seleniumJar= require('selenium-server-standalone-jar');
  22. var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
  23. server = new SeleniumServer(seleniumJar.path, { port: 4444 });
  24. server.start();
  25. done();
  26. });
  27. after(function (done) {
  28. browser.quit();
  29. server.stop();
  30. done();
  31. });
  32. var LOCATION = 'test';
  33. var TEST_TIMEOUT = 100000;
  34. var PROJECT_NAME = 'testproject';
  35. var PROJECT_DESCRIPTION = 'testdescription';
  36. var USER_STORY_SUBJECT = 'someteststory';
  37. var app;
  38. function waitForElement(elem) {
  39. return browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
  40. return browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
  41. });
  42. }
  43. function login(callback) {
  44. browser.manage().deleteAllCookies();
  45. browser.get('https://' + app.fqdn).then(function () {
  46. return browser.executeScript('localStorage.clear();');
  47. }).then(function () {
  48. browser.executeScript('sessionStorage.clear();');
  49. }).then(function () {
  50. browser.get('https://' + app.fqdn + '/login?next=%252Fprofile');
  51. }).then(function () {
  52. return waitForElement(by.name('username'));
  53. }).then(function () {
  54. return browser.findElement(by.name('username')).sendKeys(process.env.USERNAME);
  55. }).then(function () {
  56. return browser.findElement(by.name('password')).sendKeys(process.env.PASSWORD);
  57. }).then(function () {
  58. return browser.findElement(by.className('login-form')).submit();
  59. }).then(function () {
  60. return waitForElement(by.xpath('//h4[text()="Your profile"]'));
  61. }).then(function () {
  62. callback();
  63. });
  64. }
  65. function userStoryExists(callback) {
  66. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/us/1').then(function () {
  67. return waitForElement(by.xpath('//span[text()="' + USER_STORY_SUBJECT + '"]'));
  68. }).then(function () {
  69. callback();
  70. });
  71. }
  72. function getAppInfo() {
  73. var inspect = JSON.parse(execSync('cloudron inspect'));
  74. app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
  75. expect(app).to.be.an('object');
  76. }
  77. function dismissTutorial(done) {
  78. browser.get('https://' + app.fqdn);
  79. waitForElement(by.className('introjs-skipbutton')).then(function () {
  80. return browser.findElement(by.className('introjs-skipbutton')).sendKeys(Keys.ENTER);
  81. }).then(function () {
  82. // give some time to ack
  83. setTimeout(done, 5000);
  84. });
  85. }
  86. function createProject(done) {
  87. browser.get('https://' + app.fqdn + '/project/new/scrum').then(function () {
  88. return waitForElement(by.name('project-name'));
  89. }).then(function () {
  90. return browser.findElement(by.name('project-name')).sendKeys(PROJECT_NAME);
  91. }).then(function () {
  92. return browser.sleep(1000); // it needs some time to change focus!!
  93. }).then(function () {
  94. return browser.findElement(by.xpath('//textarea[@placeholder="Project Description"]')).sendKeys(PROJECT_DESCRIPTION);
  95. }).then(function () {
  96. return browser.sleep(1000);
  97. }).then(function () {
  98. return browser.findElement(by.xpath('//button[text()="Create Project"]')).click();
  99. }).then(function () {
  100. return browser.wait(until.elementLocated(by.xpath('//span[text()[contains(., "' + PROJECT_NAME + '")]]')), TEST_TIMEOUT);
  101. }).then(function () {
  102. done();
  103. });
  104. }
  105. function createUserStory(done) {
  106. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/backlog').then(function () {
  107. return waitForElement(by.xpath('//a[@tg-check-permission="add_us"]'));
  108. }).then(function () {
  109. // clicks don't work with taiga
  110. return browser.findElement(by.xpath('//a[@tg-check-permission="add_us"]')).sendKeys(Keys.ENTER);
  111. }).then(function () {
  112. return waitForElement(by.name('subject'));
  113. }).then(function () {
  114. return browser.findElement(by.name('subject')).sendKeys(USER_STORY_SUBJECT);
  115. }).then(function () {
  116. return browser.findElement(by.xpath('//button[@title="Create"]')).sendKeys(Keys.ENTER);
  117. }).then(function () {
  118. return waitForElement(by.xpath('//span[text()[contains(., "' + USER_STORY_SUBJECT + '")]]'));
  119. }).then(function () {
  120. done();
  121. });
  122. }
  123. function deleteProject(done) {
  124. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/admin/project-profile/details').then(function () {
  125. return waitForElement(by.className('delete-project'));
  126. }).then(function () {
  127. return browser.findElement(by.className('delete-project')).click();
  128. }).then(function () {
  129. return waitForElement(by.xpath('//a[@title="Yes, I\'m really sure"]'));
  130. }).then(function () {
  131. return browser.findElement(by.xpath('//a[@title="Yes, I\'m really sure"]')).click();
  132. }).then(function () {
  133. // give some time to redirect
  134. setTimeout(done, 5000);
  135. });
  136. }
  137. xit('build app', function () {
  138. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  139. });
  140. it('install app', function () {
  141. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  142. });
  143. it('can get app information', getAppInfo);
  144. it('can login', login);
  145. it('can dismiss tutorial', dismissTutorial);
  146. it('can create project', createProject);
  147. it('can create user story', createUserStory);
  148. it('user story exists', userStoryExists);
  149. it('backup app', function () {
  150. execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  151. });
  152. it('restore app', function () {
  153. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  154. });
  155. it('user story is still present', userStoryExists);
  156. it('move to different location', function () {
  157. execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  158. });
  159. it('can get app information', getAppInfo);
  160. // origin change requires new login
  161. it('can login', login);
  162. it('user story is still present', userStoryExists);
  163. it('can delete project', deleteProject);
  164. it('uninstall app', function () {
  165. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  166. });
  167. // test update
  168. it('can install app', function () {
  169. execSync('cloudron install --new --wait --appstore-id ' + app.manifest.id + ' --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  170. });
  171. it('can get app information', getAppInfo);
  172. it('can login', login);
  173. it('can dismiss tutorial', dismissTutorial);
  174. it('can create project', createProject);
  175. it('can create user story', createUserStory);
  176. it('user story exists', userStoryExists);
  177. it('can update', function () {
  178. execSync('cloudron install --wait --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  179. });
  180. it('user story exists', userStoryExists);
  181. it('uninstall app', function () {
  182. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  183. });
  184. });