dragdrop.spec.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. var testName = 'DragDrop: upload one file'
  8. var platformName = chalk.underline.yellow('[' +
  9. platform.os + ' ' +
  10. platform.browser + ' ' +
  11. platform.version +
  12. ']')
  13. test(testName + ' ' + platformName, function (t) {
  14. t.plan(1)
  15. // Go to the example URL
  16. driver.get(host + '/examples/dragdrop/')
  17. driver.manage().window().maximize()
  18. // Set Saucelabs test name
  19. driver.executeScript('sauce:job-name=' + testName).catch(function (err) {
  20. console.log('local test, so this is ok: ' + err)
  21. })
  22. var platformBrowser = platform.browser.toLowerCase()
  23. if (platformBrowser === 'safari' || platformBrowser === 'microsoftedge') {
  24. console.log('fake-selecting a fake file')
  25. driver.executeScript(Driver.UppySelectFakeFile)
  26. driver.findElement({css: '#UppyDragDrop-Two .UppyDragDrop-uploadBtn'}).click()
  27. } else {
  28. console.log('selecting a real file')
  29. // Make file input “visible”
  30. driver.executeScript('document.querySelector(".UppyDragDrop-One .UppyDragDrop-input").style.opacity = 1')
  31. // Find input by css selector & pass absolute image path to it
  32. driver
  33. .findElement({css: '.UppyDragDrop-One .UppyDragDrop-input'})
  34. .sendKeys(path.join(__dirname, 'image.jpg'))
  35. }
  36. function isUploaded () {
  37. // return driver.findElement(By.id('console-log'))
  38. // .getAttribute('value')
  39. // .then(function (value) {
  40. // var isFileUploaded = value.indexOf('Download image.jpg') !== -1
  41. // return isFileUploaded
  42. // })
  43. // .getText() only work on visible elements, so we use .getAttribute('textContent'), go figure
  44. // http://stackoverflow.com/questions/21994261/gettext-not-working-on-a-select-from-dropdown
  45. // TODO: figure out how to deal with multiple Uppy instances on the page
  46. return driver.findElement({css: '.UppyProgressBar-percentage'})
  47. .getAttribute('textContent')
  48. .then(function (value) {
  49. var progress = parseInt(value)
  50. var isFileUploaded = progress === 100
  51. return isFileUploaded
  52. })
  53. }
  54. driver.wait(isUploaded, 15000, 'File image.jpg should be uploaded within 15 seconds')
  55. .then(function (result) {
  56. collectErrors(driver).then(function () {
  57. t.equal(result, true)
  58. driver.quit()
  59. })
  60. })
  61. .catch(function (err) {
  62. collectErrors(driver).then(function () {
  63. t.fail(err)
  64. driver.quit()
  65. })
  66. })
  67. })
  68. }