test.js 9.2 KB

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