dragdrop.spec.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. var platformBrowser = platform.browser.toLowerCase()
  18. if (platformBrowser === 'safari' || platformBrowser === 'microsoftedge') {
  19. console.log('fake-selecting a fake file')
  20. driver.executeScript(Driver.UppySelectFakeFile)
  21. } else {
  22. console.log('selecting a real file')
  23. // Make file input “visible”
  24. driver.executeScript('document.querySelector(".UppyDragDrop-One .UppyDragDrop-input").style.opacity = 1')
  25. // Find input by css selector & pass absolute image path to it
  26. driver
  27. .findElement({css: '.UppyDragDrop-One .UppyDragDrop-input'})
  28. .sendKeys(path.join(__dirname, 'image.jpg'))
  29. }
  30. function isUploaded () {
  31. // return driver.findElement(By.id('console-log'))
  32. // .getAttribute('value')
  33. // .then(function (value) {
  34. // var isFileUploaded = value.indexOf('Download image.jpg') !== -1
  35. // return isFileUploaded
  36. // })
  37. // .getText() only work on visible elements, so we use .getAttribute('textContent'), go figure
  38. // http://stackoverflow.com/questions/21994261/gettext-not-working-on-a-select-from-dropdown
  39. return driver.findElement({css: '.UppyDragDrop-One-Progress .UppyProgressBar-percentage'})
  40. .getAttribute('textContent')
  41. .then(function (value) {
  42. var progress = parseInt(value)
  43. var isFileUploaded = progress === 100
  44. return isFileUploaded
  45. })
  46. }
  47. driver.wait(isUploaded, 15000, 'File image.jpg should be uploaded within 15 seconds')
  48. .then(function (result) {
  49. collectErrors(driver).then(function () {
  50. t.equal(result, true)
  51. driver.quit()
  52. })
  53. })
  54. .catch(function (err) {
  55. collectErrors(driver).then(function () {
  56. t.fail(err)
  57. driver.quit()
  58. })
  59. })
  60. })
  61. }