test.js 9.5 KB

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