test.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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, callback) {
  38. browser.wait(until.elementLocated(elem), TEST_TIMEOUT).then(function () {
  39. browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT).then(function () {
  40. callback();
  41. });
  42. });
  43. }
  44. function login(callback) {
  45. browser.manage().deleteAllCookies();
  46. browser.get('https://' + app.fqdn);
  47. browser.executeScript('localStorage.clear();');
  48. browser.executeScript('sessionStorage.clear();');
  49. browser.get('https://' + app.fqdn + '/login?next=%252Fprofile');
  50. waitForElement(by.name('username'), function () {
  51. browser.findElement(by.name('username')).sendKeys(process.env.USERNAME);
  52. browser.findElement(by.name('password')).sendKeys(process.env.PASSWORD);
  53. browser.findElement(by.className('login-form')).submit();
  54. waitForElement(by.xpath('//h4[text()="Your profile"]'), callback);
  55. });
  56. }
  57. function userStoryExists(callback) {
  58. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/us/1');
  59. waitForElement(by.xpath('//span[text()="' + USER_STORY_SUBJECT + '"]'), callback);
  60. }
  61. function getAppInfo() {
  62. var inspect = JSON.parse(execSync('cloudron inspect'));
  63. app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
  64. expect(app).to.be.an('object');
  65. }
  66. function dismissTutorial(done) {
  67. browser.get('https://' + app.fqdn);
  68. waitForElement(by.className('introjs-skipbutton'), function () {
  69. browser.findElement(by.className('introjs-skipbutton')).sendKeys(Keys.ENTER);
  70. // give some time to ack
  71. setTimeout(done, 5000);
  72. });
  73. }
  74. function createProject(done) {
  75. browser.get('https://' + app.fqdn + '/project/new/scrum');
  76. waitForElement(by.name('project-name'), function () {
  77. browser.findElement(by.name('project-name')).sendKeys(PROJECT_NAME);
  78. browser.sleep(1000); // it needs some time to change focus!!
  79. browser.findElement(by.xpath('//textarea[@placeholder="Project Description"]')).sendKeys(PROJECT_DESCRIPTION);
  80. browser.sleep(1000);
  81. browser.findElement(by.xpath('//button[text()="Create Project"]')).click();
  82. browser.wait(until.elementLocated(by.xpath('//span[text()[contains(., "' + PROJECT_NAME + '")]]')), TEST_TIMEOUT).then(function () { done(); });
  83. });
  84. }
  85. function createUserStory(done) {
  86. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/backlog');
  87. waitForElement(by.xpath('//a[@tg-check-permission="add_us"]'), function () {
  88. // clicks don't work with taiga
  89. browser.findElement(by.xpath('//a[@tg-check-permission="add_us"]')).sendKeys(Keys.ENTER);
  90. waitForElement(by.name('subject'), function () {
  91. browser.findElement(by.name('subject')).sendKeys(USER_STORY_SUBJECT);
  92. browser.findElement(by.xpath('//button[@title="Create"]')).sendKeys(Keys.ENTER);
  93. waitForElement(by.xpath('//span[text()[contains(., "' + USER_STORY_SUBJECT + '")]]'), done);
  94. });
  95. });
  96. }
  97. xit('build app', function () {
  98. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  99. });
  100. it('install app', function () {
  101. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  102. });
  103. it('can get app information', getAppInfo);
  104. it('can login', login);
  105. it('can dismiss tutorial', dismissTutorial);
  106. it('can create project', createProject);
  107. it('can create user story', createUserStory);
  108. it('user story exists', userStoryExists);
  109. it('backup app', function () {
  110. execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  111. });
  112. it('restore app', function () {
  113. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  114. });
  115. it('user story is still present', userStoryExists);
  116. it('move to different location', function () {
  117. execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  118. });
  119. it('can get app information', getAppInfo);
  120. // origin change requires new login
  121. it('can login', login);
  122. it('user story is still present', userStoryExists);
  123. it('can delete project', function (done) {
  124. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/admin/project-profile/details');
  125. waitForElement(by.className('delete-project'), function () {
  126. browser.findElement(by.className('delete-project')).click();
  127. waitForElement(by.xpath('//a[@title="Yes, I\'m really sure"]'), function () {
  128. browser.findElement(by.xpath('//a[@title="Yes, I\'m really sure"]')).click();
  129. // give some time to redirect
  130. setTimeout(done, 5000);
  131. });
  132. });
  133. });
  134. it('uninstall app', function () {
  135. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  136. });
  137. // test update
  138. it('can install app', function () {
  139. execSync('cloudron install --new --wait --appstore-id ' + app.manifest.id + ' --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  140. });
  141. it('can get app information', getAppInfo);
  142. it('can login', login);
  143. it('can dismiss tutorial', dismissTutorial);
  144. it('can create project', createProject);
  145. it('can create user story', createUserStory);
  146. it('user story exists', userStoryExists);
  147. it('can update', function () {
  148. execSync('cloudron install --wait --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  149. });
  150. it('user story exists', userStoryExists);
  151. it('uninstall app', function () {
  152. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  153. });
  154. });