index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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: 'firefox', version: '34.0', os: 'Windows 7' },
  24. { browser: 'chrome', version: '48.0', os: 'Windows XP' }
  25. ]
  26. var tests = [
  27. require('./i18n.spec.js'),
  28. require('./dragdrop.spec.js')
  29. ]
  30. function buildDriver (platform) {
  31. var driver
  32. if (isRemoteTest) {
  33. driver = new webdriver
  34. .Builder()
  35. .withCapabilities({
  36. 'browserName': platform.browser,
  37. 'platform': platform.os,
  38. 'version': platform.version,
  39. 'username': username,
  40. 'accessKey': accessKey
  41. })
  42. .usingServer('http://' + username + ':' + accessKey +
  43. '@ondemand.saucelabs.com:80/wd/hub')
  44. .build()
  45. driver.setFileDetector(new remote.FileDetector())
  46. } else {
  47. driver = new webdriver
  48. .Builder()
  49. .forBrowser('firefox')
  50. .build()
  51. }
  52. return driver
  53. }
  54. if (isRemoteTest) {
  55. platforms.forEach(function (platform) {
  56. tests.forEach(function (test) {
  57. var driver = buildDriver(platform)
  58. test(driver, platform, host)
  59. })
  60. })
  61. } else {
  62. tests.forEach(function (test) {
  63. var driver = buildDriver()
  64. test(driver, { browser: 'Firefox', version: 'Version', os: 'Local' }, host)
  65. })
  66. }