test.js 8.4 KB

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