index.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/c10e8a955883f004452cdde18096d70738397788/javascript/node/selenium-webdriver/test/upload_test.js
  5. //
  6. // - https://github.com/SeleniumHQ/selenium/wiki/WebDriverJs
  7. // - http://seleniumhq.github.io/selenium/docs/api/javascript/
  8. // - http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/firefox/index.html
  9. // - http://selenium.googlecode.com/git/docs/api/javascript/namespace_webdriver_By.html
  10. // - http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_WebElement.html
  11. require('babel-register')
  12. var webdriver = require('selenium-webdriver')
  13. var remote = require('selenium-webdriver/remote')
  14. var username = process.env.USERNAME
  15. var accessKey = process.env.ACCESS_KEY
  16. // if accessKey is supplied as env variable, this is a remote Saucelabs test
  17. var isRemoteTest = accessKey ? true : ''
  18. var host = isRemoteTest ? 'http://uppi.io' : 'http://localhost:4000'
  19. // FYI: old Chrome on Windows XP,
  20. // Opera 12 on Linux — didn’t pass
  21. var platforms = [
  22. // { browser: 'Opera', version: '12', os: 'Linux' },
  23. // { browser: 'iphone', version: '9.2', os: 'OS X 10.10' },
  24. { browser: 'firefox', version: '34.0', os: 'Windows 7' },
  25. { browser: 'chrome', version: '48.0', os: 'Windows XP' }
  26. ]
  27. var tests = [
  28. require('./multipart.spec.js')
  29. // require('./i18n.spec.js'),
  30. // require('./dragdrop.spec.js')
  31. ]
  32. function buildDriver (platform) {
  33. var driver
  34. if (isRemoteTest) {
  35. driver = new webdriver
  36. .Builder()
  37. .withCapabilities({
  38. 'browserName': platform.browser,
  39. 'platform': platform.os,
  40. 'version': platform.version,
  41. 'username': username,
  42. 'accessKey': accessKey
  43. })
  44. .usingServer('http://' + username + ':' + accessKey +
  45. '@ondemand.saucelabs.com:80/wd/hub')
  46. .build()
  47. driver.setFileDetector(new remote.FileDetector())
  48. } else {
  49. driver = new webdriver
  50. .Builder()
  51. .forBrowser('firefox')
  52. .build()
  53. }
  54. return driver
  55. }
  56. if (isRemoteTest) {
  57. platforms.forEach(function (platform) {
  58. tests.forEach(function (test) {
  59. var driver = buildDriver(platform)
  60. test(driver, platform, host)
  61. })
  62. })
  63. } else {
  64. tests.forEach(function (test) {
  65. var driver = buildDriver()
  66. test(driver, { browser: 'Firefox', version: 'Version', os: 'Local' }, host)
  67. })
  68. }