dragdrop.spec.js 2.0 KB

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