fallback.spec.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. var test = require('tape')
  2. var path = require('path')
  3. var chalk = require('chalk')
  4. var Driver = require('./Driver')
  5. module.exports = function (driver, platform, host) {
  6. var testName = 'fallback: fall back to regular <form> upload when JS is not working, or not loaded yet, or browser is not supported by Uppy'
  7. var platformName = chalk.underline.yellow('[' +
  8. platform.os + ' ' +
  9. platform.browser + ' ' +
  10. platform.version +
  11. ']')
  12. test(testName + ' ' + platformName, function (t) {
  13. t.plan(1)
  14. console.log('0')
  15. driver.get(host + '/examples/multipart')
  16. console.log('1')
  17. driver.manage().window().maximize()
  18. console.log('2')
  19. Driver.setSauceTestName(driver, testName)
  20. console.log('3')
  21. driver
  22. .findElement({css: '.UppyForm input'})
  23. .sendKeys(path.join(__dirname, 'image.jpg'))
  24. // driver.switchTo().alert().dismiss()
  25. // .catch(function (err) {
  26. // console.log(err)
  27. // })
  28. console.log('4')
  29. driver.findElement({css: '.UppyForm button'}).click()
  30. function isRedirectedAfterUpload () {
  31. // this should close the “Do you want to save this file?” alert when Travis runs the test
  32. return driver.getCurrentUrl().then(function (val) {
  33. console.log('current url is ', val)
  34. var isPageRedirected = val.indexOf('api2.transloadit.com') !== -1
  35. return isPageRedirected
  36. })
  37. }
  38. console.log('5')
  39. driver.wait(isRedirectedAfterUpload, 12000, 'Browser should navigate to api2.transloadit.com after upload')
  40. .then(function (isPageRedirected) {
  41. console.log('6')
  42. driver.switchTo().alert().dismiss()
  43. .catch(function (err) {
  44. console.log(err)
  45. })
  46. Driver.testEqual(driver, t, isPageRedirected === true)
  47. driver.quit()
  48. // Driver.collectErrors(driver).then(function () {
  49. // Driver.testEqual(driver, t, isPageRedirected === true)
  50. // driver.quit()
  51. // })
  52. })
  53. .catch(function (err) {
  54. Driver.collectErrors(driver).then(function () {
  55. Driver.testFail(driver, t, err)
  56. driver.quit()
  57. })
  58. })
  59. })
  60. }