download-tests.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* global browser */
  2. const assert = require('assert');
  3. const fs = require('fs');
  4. const path = require('path');
  5. const DownloadPage = require('./pages/desktop/download_page');
  6. const HomePage = require('./pages/desktop/home_page');
  7. describe('Send', function() {
  8. const homePage = new HomePage();
  9. const downloadDir =
  10. browser.desiredCapabilities['moz:firefoxOptions']['prefs'][
  11. 'browser.download.dir'
  12. ];
  13. const testFilesPath = path.join(__dirname, 'fixtures');
  14. const testFiles = fs.readdirSync(testFilesPath);
  15. beforeEach(function() {
  16. homePage.open();
  17. });
  18. testFiles.forEach(file => {
  19. it(`should upload and download files, file: ${file}`, function() {
  20. browser.chooseFile(homePage.uploadInput, `${testFilesPath}/${file}`);
  21. browser.waitForExist(homePage.uploadButton);
  22. browser.click(homePage.uploadButton);
  23. browser.waitForExist(homePage.shareUrl);
  24. const downloadPage = new DownloadPage(
  25. browser.getValue(homePage.shareUrl)
  26. );
  27. downloadPage.open();
  28. downloadPage.download();
  29. browser.waitForExist(downloadPage.downloadComplete);
  30. assert.ok(fs.existsSync(path.join(downloadDir, file)));
  31. });
  32. });
  33. it('should update the download count on home page after 1 download', function() {
  34. browser.chooseFile(
  35. homePage.uploadInput,
  36. `${testFilesPath}/${testFiles[0]}`
  37. );
  38. browser.waitForExist(homePage.uploadButton);
  39. browser.waitForExist(homePage.downloadCountSelect);
  40. browser.selectByIndex(homePage.downloadCountSelect, 1);
  41. browser.click(homePage.uploadButton);
  42. browser.waitForExist(homePage.shareUrl);
  43. const downloadPage = new DownloadPage(browser.getValue(homePage.shareUrl));
  44. downloadPage.open();
  45. downloadPage.download();
  46. browser.waitForExist(downloadPage.downloadComplete);
  47. browser.back();
  48. browser.waitForExist('send-archive');
  49. assert(
  50. browser
  51. .getText('send-archive > div:first-of-type')
  52. .includes('Expires after 1 download')
  53. );
  54. });
  55. it('should ensure that the downloaded file size matches the uploaded file size', function() {
  56. browser.chooseFile(
  57. homePage.uploadInput,
  58. `${testFilesPath}/${testFiles[0]}`
  59. );
  60. // get the file size for upload
  61. const uploadSize = fs.statSync(`${testFilesPath}/${testFiles[0]}`).size;
  62. browser.waitForExist(homePage.uploadButton);
  63. browser.click(homePage.uploadButton);
  64. browser.waitForExist(homePage.shareUrl);
  65. const downloadPage = new DownloadPage(browser.getValue(homePage.shareUrl));
  66. downloadPage.open();
  67. downloadPage.download();
  68. browser.waitForExist(downloadPage.downloadComplete);
  69. // get the file size for download
  70. const downloadFile = path.join(downloadDir, `${testFiles[0]}`);
  71. const downloadSize = fs.statSync(downloadFile).size;
  72. // check if upload and download file sizes are equal
  73. assert.equal(uploadSize, downloadSize);
  74. });
  75. it(`should upload and download file with added tracking parameter`, function() {
  76. const trackingUrl =
  77. '?fbclid=IaMFak3Tr4ck1ng1d_SDlP0shBk8SM2EN3cCLFKpHVl-k-Pvv0sf9Zy0tnTu9srqVY';
  78. const password = 'strongpassword';
  79. browser.chooseFile(
  80. homePage.uploadInput,
  81. `${testFilesPath}/${testFiles[0]}`
  82. );
  83. browser.waitForExist(homePage.addPassword);
  84. browser.click(homePage.addPassword);
  85. browser.waitForExist(homePage.passwordInput);
  86. browser.setValue(homePage.passwordInput, password);
  87. browser.click(homePage.uploadButton);
  88. browser.waitForExist(homePage.shareUrl);
  89. const shareUrl = browser.getValue(homePage.shareUrl);
  90. const downloadPage = new DownloadPage(
  91. shareUrl.replace('#', `${trackingUrl}#`)
  92. );
  93. downloadPage.open();
  94. downloadPage.downloadUsingPassword(password);
  95. browser.waitForExist(downloadPage.downloadComplete);
  96. assert.ok(fs.existsSync(path.join(downloadDir, testFiles[0])));
  97. });
  98. });