dragdrop.spec.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var test = require('tape')
  2. var path = require('path')
  3. var tools = require('./tools')
  4. module.exports = function (driver, platform, host) {
  5. var testName = 'DragDrop: upload one file'
  6. test(tools.prettyTestName(testName, platform), function (t) {
  7. t.plan(1)
  8. // Go to the example URL
  9. driver.get(host + '/examples/dragdrop/')
  10. driver.manage().window().maximize()
  11. // Set Saucelabs test name
  12. tools.setSauceTestName(driver, testName)
  13. driver.executeScript(tools.uppySelectFakeFile)
  14. driver.findElement({css: '.UppyDragDrop-Two-Upload'}).click()
  15. var platformBrowser = platform.browser.toLowerCase()
  16. if (platformBrowser === 'safari' || platformBrowser === 'microsoftedge') {
  17. console.log('fake-selecting a fake file')
  18. driver.executeScript(tools.uppySelectFakeFile)
  19. driver.findElement({css: '.UppyDragDrop-Two-Upload'}).click()
  20. } else {
  21. console.log('selecting a real file')
  22. // Make file input “visible”
  23. driver.executeScript('document.querySelector(".UppyDragDrop-One .uppy-DragDrop-input").style.opacity = 1')
  24. // Find input by css selector & pass absolute image path to it
  25. driver
  26. .findElement({css: '.UppyDragDrop-One .uppy-DragDrop-input'})
  27. .sendKeys(path.join(__dirname, 'image.jpg'))
  28. }
  29. function isUploaded () {
  30. // return driver.findElement(By.id('console-log'))
  31. // .getAttribute('value')
  32. // .then(function (value) {
  33. // var isFileUploaded = value.indexOf('Download image.jpg') !== -1
  34. // return isFileUploaded
  35. // })
  36. // .getText() only work on visible elements, so we use .getAttribute('textContent'), go figure
  37. // http://stackoverflow.com/questions/21994261/gettext-not-working-on-a-select-from-dropdown
  38. // TODO: figure out how to deal with multiple Uppy instances on the page
  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, 12000, 'File image.jpg should be uploaded within 15 seconds')
  48. .then(function (result) {
  49. tools.testEqual(driver, t, result)
  50. driver.quit()
  51. })
  52. .catch(function (err) {
  53. tools.collectErrors(driver).then(function () {
  54. tools.testFail(driver, t, err)
  55. driver.quit()
  56. })
  57. })
  58. })
  59. }