i18n.spec.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Docs aren't that great to find. Mostly JAVA based. Here are few helpful resources:
  2. // - https://github.com/SeleniumHQ/selenium/wiki/WebDriverJs
  3. // - http://seleniumhq.github.io/selenium/docs/api/javascript/
  4. // - http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/firefox/index.html
  5. var test = require('tape')
  6. var path = require('path')
  7. var chalk = require('chalk')
  8. var webdriver = require('selenium-webdriver')
  9. var firefox = require('selenium-webdriver/firefox')
  10. var By = webdriver.By
  11. var profile = new firefox.Profile()
  12. profile.addExtension(path.join(__dirname, 'xpi', 'firebug-2.0.16.xpi'))
  13. profile.addExtension(path.join(__dirname, 'xpi', 'JSErrorCollector.xpi'))
  14. profile.setPreference('extensions.firebug.showChromeErrors', true)
  15. var options = new firefox.Options().setProfile(profile)
  16. var driver = new firefox.Driver(options)
  17. // A remote driver could look something like this:
  18. // var driver = new (require('selenium-webdriver')).Builder()
  19. // .forBrowser('firefox')
  20. // .usingServer('http://127.0.0.1:4444/wd/hub')
  21. // .setFirefoxOptions(options)
  22. // .build()
  23. var hexoServer = 'http://localhost:4000'
  24. test('make sure Uppy loads with Russion language pack', function (t) {
  25. driver.get(hexoServer + '/examples/i18n/')
  26. // Monitor for errors, and dump them
  27. const promise = driver.executeScript('return window.JSErrorCollector_errors.pump()')
  28. promise.then(function (errors) {
  29. if (!errors || !errors.length) {
  30. return
  31. }
  32. errors.forEach(function (error) {
  33. console.error([
  34. '[browser-error]',
  35. chalk.magenta(error.sourceName),
  36. chalk.dim('#' + error.lineNumber),
  37. chalk.red(error.errorMessage)
  38. ].join(' '))
  39. })
  40. })
  41. // Our success/fail message will be logged in the console element
  42. var consoleElement = driver.findElement(By.id('console-log'))
  43. // Wait for our upload message to be logged
  44. driver.wait(isLoaded.bind(this, consoleElement))
  45. // Get the result of our upload and test it
  46. getElementValue(consoleElement)
  47. .then(function (value) {
  48. var result = value.split('\n')[0]
  49. t.equal(result, '--> Uppy Bundled version with Tus10 & Russian language pack has loaded')
  50. })
  51. driver.quit()
  52. t.end()
  53. /**
  54. * Check if uploading is finished by looking for a result message
  55. * in the example's console output element.
  56. * @return {Boolean} If uploading is complete
  57. */
  58. function isLoaded (consoleElement) {
  59. return getElementValue(consoleElement)
  60. .then(function (value) {
  61. return value.indexOf('-->') !== -1
  62. })
  63. }
  64. /**
  65. * Get value attribute of element
  66. * @param {webdriver.WebElement} element Selenium element object
  67. * @return {webdriver.promise} Promise resolving to element value
  68. */
  69. function getElementValue (element) {
  70. return element.getAttribute('value')
  71. .then(function (value) {
  72. return value
  73. })
  74. }
  75. })