index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Docs aren't that great to find. Mostly JAVA based. Here are few helpful resources:
  2. // - https://www.browserstack.com/automate/node#testing-frameworks
  3. // - http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/firefox/index_exports_Driver.html
  4. // - https://github.com/SeleniumHQ/selenium/blob/8f988e07cc316a48e0ff94d8ff823c95142532e9/javascript/webdriver/webdriver.js
  5. // - https://github.com/SeleniumHQ/selenium/blob/c10e8a955883f004452cdde18096d70738397788/javascript/node/selenium-webdriver/test/upload_test.js
  6. //
  7. // - https://github.com/SeleniumHQ/selenium/wiki/WebDriverJs
  8. // - http://seleniumhq.github.io/selenium/docs/api/javascript/
  9. // - http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/firefox/index.html
  10. // - http://selenium.googlecode.com/git/docs/api/javascript/namespace_webdriver_By.html
  11. // - http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_WebElement.html
  12. require('babel-register')
  13. var webdriver = require('selenium-webdriver')
  14. var remote = require('selenium-webdriver/remote')
  15. // The Travis Sauce Connect addon exports the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables,
  16. // and relays connections to the hub URL back to Sauce Labs.
  17. // See: https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-Sauce-Labs
  18. var username = process.env.SAUCE_USERNAME
  19. var accessKey = process.env.SAUCE_ACCESS_KEY
  20. var remoteHost = 'http://uppy.io'
  21. var localHost = 'http://localhost:4000'
  22. // if accessKey is supplied as env variable, this is a remote Saucelabs test
  23. var isTravisTest = process.env.TRAVIS === 'true'
  24. var isRemoteTest = !!accessKey
  25. var host = localHost
  26. if (isTravisTest) {
  27. // We have a tunnel via the saucelabs addon on Travis
  28. host = localHost
  29. } else if (isRemoteTest) {
  30. // We're not too sure about a working tunnel otherwise, best just test uppy.io
  31. host = remoteHost
  32. } else {
  33. // If we don't have any access keys set, we'll assume you'll be playing around with a local
  34. // firefox webdriver.
  35. host = localHost
  36. }
  37. console.log('Acceptance tests will be targetting: ' + host)
  38. // FYI: old Chrome on Windows XP — didn’t pass
  39. var platforms = [
  40. { browser: 'Safari', version: '8.0', os: 'OS X 10.10' },
  41. { browser: 'MicrosoftEdge', version: '13.10586', os: 'Windows 10' },
  42. { browser: 'Firefox', version: '38.0', os: 'Linux' },
  43. { browser: 'Internet Explorer', version: '10.0', os: 'Windows 8' },
  44. { browser: 'Internet Explorer', version: '11.103', os: 'Windows 10' },
  45. { browser: 'Chrome', version: '48.0', os: 'Windows XP' },
  46. { browser: 'Firefox', version: '34.0', os: 'Windows 7' }
  47. ]
  48. var tests = [
  49. require('./multipart.spec.js'),
  50. require('./i18n.spec.js')
  51. // require('./dragdrop.spec.js')
  52. ]
  53. function buildDriver (platform) {
  54. var driver
  55. if (isRemoteTest) {
  56. var capabilities = {
  57. 'browserName': platform.browser,
  58. 'platform': platform.os,
  59. 'version': platform.version,
  60. 'username': username,
  61. 'accessKey': accessKey
  62. }
  63. if (isTravisTest) {
  64. // @todo Do we need a hub_url = "%s:%s@localhost:4445" % (username, access_key)
  65. // as mentioned in https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-Sauce-Labs ?
  66. capabilities['tunnel-identifier'] = process.env.TRAVIS_JOB_NUMBER
  67. capabilities['build'] = process.env.TRAVIS_BUILD_NUMBER
  68. capabilities['name'] = 'Travis ##' + process.env.TRAVIS_JOB_NUMBER
  69. capabilities['tags'] = [process.env.TRAVIS_NODE_VERSION, 'CI']
  70. }
  71. driver = new webdriver
  72. .Builder()
  73. .withCapabilities(capabilities)
  74. .usingServer('http://' + username + ':' + accessKey +
  75. '@ondemand.saucelabs.com:80/wd/hub')
  76. .build()
  77. driver.setFileDetector(new remote.FileDetector())
  78. } else {
  79. driver = new webdriver
  80. .Builder()
  81. .forBrowser('firefox')
  82. .build()
  83. }
  84. return driver
  85. }
  86. if (isRemoteTest) {
  87. platforms.forEach(function (platform) {
  88. tests.forEach(function (test) {
  89. var driver = buildDriver(platform)
  90. test(driver, platform, host)
  91. })
  92. })
  93. } else {
  94. tests.forEach(function (test) {
  95. var driver = buildDriver()
  96. test(driver, { browser: 'Firefox', version: 'Version', os: 'Local' }, host)
  97. })
  98. }