index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. // @todo This should become localhost to utilize the Travis saucelabs addon tunnel
  28. // But it seems Edge and Safar fail on that right now, so targeting uppy.io instead.
  29. // That is unideal, as we are then testing a previous deploy, and not the current build
  30. host = localHost
  31. // host = remoteHost
  32. } else if (isRemoteTest) {
  33. // We're not too sure about a working tunnel otherwise, best just test uppy.io
  34. host = remoteHost
  35. } else {
  36. // If we don't have any access keys set, we'll assume you'll be playing around with a local
  37. // firefox webdriver.
  38. host = localHost
  39. }
  40. console.log('Acceptance tests will be targetting: ' + host)
  41. // FYI: old Chrome on Windows XP — didn’t pass
  42. var platforms = [
  43. // { browser: 'Safari', version: '8.0', os: 'OS X 10.10' },
  44. // { browser: 'MicrosoftEdge', version: '13.10586', os: 'Windows 10' },
  45. { browser: 'Firefox', version: '38.0', os: 'Linux' },
  46. { browser: 'Internet Explorer', version: '10.0', os: 'Windows 8' },
  47. { browser: 'Internet Explorer', version: '11.103', os: 'Windows 10' },
  48. { browser: 'Chrome', version: '48.0', os: 'Windows XP' },
  49. { browser: 'Firefox', version: '34.0', os: 'Windows 7' }
  50. ]
  51. var tests = [
  52. require('./multipart.spec.js'),
  53. require('./i18n.spec.js')
  54. // require('./dragdrop.spec.js')
  55. ]
  56. function buildDriver (platform) {
  57. var driver
  58. if (isRemoteTest) {
  59. var capabilities = {
  60. 'browserName': platform.browser,
  61. 'platform': platform.os,
  62. 'version': platform.version,
  63. 'username': username,
  64. 'accessKey': accessKey
  65. }
  66. if (isTravisTest) {
  67. // @todo Do we need a hub_url = "%s:%s@localhost:4445" % (username, access_key)
  68. // as mentioned in https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-Sauce-Labs ?
  69. capabilities['tunnel-identifier'] = process.env.TRAVIS_JOB_NUMBER
  70. capabilities['build'] = process.env.TRAVIS_BUILD_NUMBER
  71. capabilities['name'] = 'Travis ##' + process.env.TRAVIS_JOB_NUMBER
  72. capabilities['tags'] = [process.env.TRAVIS_NODE_VERSION, 'CI']
  73. }
  74. driver = new webdriver
  75. .Builder()
  76. .withCapabilities(capabilities)
  77. .usingServer('http://' + username + ':' + accessKey +
  78. '@ondemand.saucelabs.com:80/wd/hub')
  79. .build()
  80. driver.setFileDetector(new remote.FileDetector())
  81. } else {
  82. driver = new webdriver
  83. .Builder()
  84. .forBrowser('firefox')
  85. .build()
  86. }
  87. return driver
  88. }
  89. if (isRemoteTest) {
  90. platforms.forEach(function (platform) {
  91. tests.forEach(function (test) {
  92. var driver = buildDriver(platform)
  93. test(driver, platform, host)
  94. })
  95. })
  96. } else {
  97. tests.forEach(function (test) {
  98. var driver = buildDriver()
  99. test(driver, { browser: 'Firefox', version: 'Version', os: 'Local' }, host)
  100. })
  101. }