test.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 = 50000;
  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 + '/login?next=%252Fprofile');
  47. waitForElement(by.name('username'), function () {
  48. browser.findElement(by.name('username')).sendKeys(process.env.USERNAME);
  49. browser.findElement(by.name('password')).sendKeys(process.env.PASSWORD);
  50. browser.findElement(by.className('login-form')).submit();
  51. waitForElement(by.xpath('//h4[text()="Your profile"]'), callback);
  52. });
  53. }
  54. function userStoryExists(callback) {
  55. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/us/1');
  56. waitForElement(by.xpath('//span[text()="' + USER_STORY_SUBJECT + '"]'), callback);
  57. }
  58. xit('build app', function () {
  59. execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  60. });
  61. it('install app', function () {
  62. execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  63. });
  64. it('can get app information', function () {
  65. var inspect = JSON.parse(execSync('cloudron inspect'));
  66. app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
  67. expect(app).to.be.an('object');
  68. });
  69. it('can login', login);
  70. it('can dismiss tutorial', function (done) {
  71. browser.get('https://' + app.fqdn);
  72. waitForElement(by.className('introjs-skipbutton'), function () {
  73. browser.findElement(by.className('introjs-skipbutton')).sendKeys(Keys.ENTER);
  74. // give some time to ack
  75. setTimeout(done, 5000);
  76. });
  77. });
  78. it('can create project', function (done) {
  79. browser.get('https://' + app.fqdn);
  80. waitForElement(by.className('create-project-button'), function () {
  81. // click wont work
  82. browser.findElement(by.className('create-project-button')).sendKeys(Keys.ENTER);
  83. waitForElement(by.name('name'), function () {
  84. browser.findElement(by.name('name')).sendKeys(PROJECT_NAME);
  85. browser.findElement(by.xpath('//textarea[@name="description"]')).sendKeys(PROJECT_DESCRIPTION);
  86. browser.findElement(by.xpath('//button[@title="Create project"]')).click();
  87. browser.wait(until.elementLocated(by.xpath('//span[text()[contains(., "' + PROJECT_NAME + '")]]')), TEST_TIMEOUT).then(function () { done(); });
  88. });
  89. });
  90. });
  91. it('can create user story', function (done) {
  92. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/backlog');
  93. waitForElement(by.xpath('//a[@title="+ Add a new User Story"]'), function () {
  94. browser.findElement(by.xpath('//a[@title="+ Add a new User Story"]')).sendKeys(Keys.ENTER);
  95. waitForElement(by.name('subject'), function () {
  96. browser.findElement(by.name('subject')).sendKeys(USER_STORY_SUBJECT);
  97. browser.findElement(by.xpath('//button[@title="Create"]')).sendKeys(Keys.ENTER);
  98. waitForElement(by.xpath('//span[text()[contains(., "' + USER_STORY_SUBJECT + '")]]'), done);
  99. });
  100. });
  101. });
  102. it('user story exists', userStoryExists);
  103. it('backup app', function () {
  104. execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  105. });
  106. it('restore app', function () {
  107. execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  108. });
  109. it('user story is still present', userStoryExists);
  110. it('move to different location', function () {
  111. browser.manage().deleteAllCookies();
  112. execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  113. var inspect = JSON.parse(execSync('cloudron inspect'));
  114. app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
  115. expect(app).to.be.an('object');
  116. });
  117. // origin change requires new login
  118. it('can login', login);
  119. it('user story is still present', userStoryExists);
  120. it('can delete project', function (done) {
  121. browser.get('https://' + app.fqdn + '/project/' + process.env.USERNAME + '-' + PROJECT_NAME + '/admin/project-profile/details');
  122. waitForElement(by.className('delete-project'), function () {
  123. browser.findElement(by.className('delete-project')).click();
  124. waitForElement(by.xpath('//a[@title="Yes, I\'m really sure"]'), function () {
  125. browser.findElement(by.xpath('//a[@title="Yes, I\'m really sure"]')).click();
  126. // give some time to redirect
  127. setTimeout(function () {
  128. waitForElement(by.className('create-project-button'), done);
  129. }, 5000);
  130. });
  131. });
  132. });
  133. it('uninstall app', function () {
  134. execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
  135. });
  136. });