index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 Safari 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 = remoteHost
  31. host = localHost
  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. var platforms = [
  42. // { browser: 'Safari', version: '8.0', os: 'OS X 10.10' }
  43. // { browser: 'MicrosoftEdge', version: '13.10586', os: 'Windows 10' },
  44. { browser: 'Firefox', version: '38.0', os: 'Linux' },
  45. { browser: 'Internet Explorer', version: '10.0', os: 'Windows 8' },
  46. { browser: 'Internet Explorer', version: '11.103', os: 'Windows 10' },
  47. { browser: 'Chrome', version: '48.0', os: 'Windows 7' },
  48. { browser: 'Firefox', version: '34.0', os: 'Windows 7' }
  49. ]
  50. var tests = [
  51. require('./multipart.spec.js'),
  52. require('./i18n.spec.js'),
  53. require('./dragdrop.spec.js')
  54. ]
  55. function buildDriver (platform) {
  56. var driver
  57. if (isRemoteTest) {
  58. var capabilities = {
  59. 'browserName': platform.browser,
  60. 'platform': platform.os,
  61. 'version': platform.version,
  62. 'username': username,
  63. 'accessKey': accessKey
  64. }
  65. if (isTravisTest) {
  66. // @todo Do we need a hub_url = "%s:%s@localhost:4445" % (username, access_key)
  67. // as mentioned in https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-Sauce-Labs ?
  68. capabilities['tunnel-identifier'] = process.env.TRAVIS_JOB_NUMBER
  69. capabilities['build'] = process.env.TRAVIS_BUILD_NUMBER
  70. capabilities['name'] = 'Travis ##' + process.env.TRAVIS_JOB_NUMBER
  71. capabilities['tags'] = [process.env.TRAVIS_NODE_VERSION, 'CI']
  72. }
  73. driver = new webdriver
  74. .Builder()
  75. .withCapabilities(capabilities)
  76. .usingServer('http://' + username + ':' + accessKey +
  77. '@ondemand.saucelabs.com:80/wd/hub')
  78. .build()
  79. driver.setFileDetector(new remote.FileDetector())
  80. } else {
  81. driver = new webdriver
  82. .Builder()
  83. .forBrowser('firefox')
  84. .build()
  85. }
  86. return driver
  87. }
  88. var specificTests = {
  89. fallback: function () {
  90. var ancientPlatform = { browser: 'internet explorer', version: '8.0', os: 'Windows 7' }
  91. var driver = buildDriver({ browser: 'internet explorer', version: '8.0', os: 'Windows 7' })
  92. var test = require('./fallback.spec.js')
  93. test(driver, ancientPlatform, host)
  94. }
  95. }
  96. // RUN TESTS
  97. function runAllTests () {
  98. if (isRemoteTest) {
  99. // run custom platform-specific tests here
  100. // <form> fallback test
  101. console.log('Skipping the fallback test', specificTests.fallback)
  102. // specificTests.fallback()
  103. // run all tests for all platforms
  104. platforms.forEach(function (platform) {
  105. tests.forEach(function (test) {
  106. var driver = buildDriver(platform)
  107. test(driver, platform, host)
  108. })
  109. })
  110. } else {
  111. // run tests just for local Firefox
  112. tests.forEach(function (test) {
  113. var driver = buildDriver()
  114. test(driver, { browser: 'Firefox', version: 'Version', os: 'Local' }, host)
  115. })
  116. }
  117. }
  118. runAllTests()