i18n.spec.js 3.0 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. // - http://selenium.googlecode.com/git/docs/api/javascript/namespace_webdriver_By.html
  6. // - http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_WebElement.html
  7. var test = require('tape')
  8. var path = require('path')
  9. var chalk = require('chalk')
  10. var webdriver = require('selenium-webdriver')
  11. var firefox = require('selenium-webdriver/firefox')
  12. var By = webdriver.By
  13. var profile = new firefox.Profile()
  14. profile.addExtension(path.join(__dirname, 'xpi', 'firebug-2.0.16.xpi'))
  15. profile.addExtension(path.join(__dirname, 'xpi', 'JSErrorCollector.xpi'))
  16. profile.setPreference('extensions.firebug.showChromeErrors', true)
  17. var options = new firefox.Options().setProfile(profile)
  18. var driver = new firefox.Driver(options)
  19. // A remote driver could look something like this:
  20. // var driver = new (require('selenium-webdriver')).Builder()
  21. // .forBrowser('firefox')
  22. // .usingServer('http://127.0.0.1:4444/wd/hub')
  23. // .setFirefoxOptions(options)
  24. // .build()
  25. var hexoServer = 'http://localhost:4000'
  26. test('make sure Uppy loads with Russion language pack', function (t) {
  27. driver.get(hexoServer + '/examples/i18n/')
  28. // Monitor for errors, and dump them
  29. const promise = driver.executeScript('return window.JSErrorCollector_errors.pump()')
  30. promise.then(function (errors) {
  31. if (!errors || !errors.length) {
  32. return
  33. }
  34. errors.forEach(function (error) {
  35. console.error([
  36. '[browser-error]',
  37. chalk.magenta(error.sourceName),
  38. chalk.dim('#' + error.lineNumber),
  39. chalk.red(error.errorMessage)
  40. ].join(' '))
  41. })
  42. })
  43. // Our success/fail message will be logged in the console element
  44. var consoleElement = driver.findElement(By.id('console-log'))
  45. // Wait 8 seconds, for our upload message to be logged
  46. driver.wait(isLoaded.bind(this, consoleElement), 8000)
  47. driver.findElement(By.css('.UppyDragDrop-label')).getText().then(function (val) {
  48. console.dir({val: val})
  49. t.equal(val, 'Выберите файл или перенесите его сюда.')
  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. })