dragdrop.spec.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var test = require('tape')
  2. var path = require('path')
  3. var webdriver = require('selenium-webdriver')
  4. var chalk = require('chalk')
  5. var By = webdriver.By
  6. var Driver = require('./Driver')
  7. var collectErrors = Driver.collectErrors
  8. module.exports = function (driver, platform, host) {
  9. test('dragdrop: make sure DragDrop accepts and uploads 1 file via input ' +
  10. chalk.underline.yellow('[' +
  11. platform.os + ' ' +
  12. platform.browser + ' ' +
  13. platform.version +
  14. ']'),
  15. function (t) {
  16. t.plan(1)
  17. // Go to the example URL
  18. driver.get(host + '/examples/dragdrop/')
  19. // Make file input “visible”
  20. driver.executeScript('document.querySelector(".UppyDragDrop-One .UppyDragDrop-input").style.opacity = 1')
  21. // Find input by css selector & pass absolute image path to it
  22. driver
  23. .findElement(By.css('.UppyDragDrop-One .UppyDragDrop-input'))
  24. .sendKeys(path.join(__dirname, 'image.jpg'))
  25. function isUploaded () {
  26. // return driver.findElement(By.id('console-log'))
  27. // .getAttribute('value')
  28. // .then(function (value) {
  29. // var isFileUploaded = value.indexOf('Download image.jpg') !== -1
  30. // return isFileUploaded
  31. // })
  32. // .getText() only work on visible elements, so we use .getAttribute('textContent'), go figure
  33. // http://stackoverflow.com/questions/21994261/gettext-not-working-on-a-select-from-dropdown
  34. return driver.findElement(By.css('.UppyDragDrop-One-Progress .UppyProgressBar-percentage'))
  35. .getAttribute('textContent')
  36. .then(function (value) {
  37. var progress = parseInt(value)
  38. var isFileUploaded = progress === 100
  39. return isFileUploaded
  40. })
  41. }
  42. driver.wait(isUploaded, 15000, 'File image.jpg should be uploaded within 15 seconds')
  43. .then(function (result) {
  44. collectErrors(driver).then(function () {
  45. t.equal(result, true)
  46. driver.quit()
  47. })
  48. })
  49. .catch(function (err) {
  50. collectErrors(driver).then(function () {
  51. t.fail(err)
  52. driver.quit()
  53. })
  54. })
  55. })
  56. }