Skip to content

Instantly share code, notes, and snippets.

@killerswan
Last active January 2, 2016 04:49
Show Gist options
  • Save killerswan/8253205 to your computer and use it in GitHub Desktop.
Save killerswan/8253205 to your computer and use it in GitHub Desktop.
Node.JS <--> Selnium

Although there are some more minimal official looking things, and various tools to start or package Selenium, it looks as though wd [11] is the state of the art... This is what Sauce Labs uses from Node.JS. [28]

Wd implements the WebDriver wire protocol, and supports capabilities... [12] [13] And there are some interesting extensions for sync [14] and querying [15]. Not to mention experimental generator support (avoiding callback hell) with yiewd [16] on node versions >= 0.11.3! :D

Karma [1] (formerly Testacular) looks cool, uses JavaScript in the browser which must be in focus [2] so inadequate for us, but super fast. There's also Karma-webdriver-launcher [3], which was built to let you farm out a bunch of Karma managed JavaScript tests across a farm of Selenium WebDriver systems [5]...

Soda is Selenium RC client [4] by some of same developer now doing wd. Selenium RC is dead.

That is, here is some Selenium history:

  • Selenium RC is old stuff, superseded by WebDriver.
  • Selenium IDE is a Firefox GUI thing which does record and play back [7]
  • Selenium Server is a service which can be used to remotely access WebDrivers.
  • The WebDriver JSON wire protocol describes how to communicate with a browser-specific WebDriver. [9]
  • WebDriver APIs implement this, and you don't always need a Selenium Server. [8] (Java classes which implement WebDriver APIs include "AndroidDriver, ChromeDriver, EventFiringWebDriver, FirefoxDriver, HtmlUnitDriver, InternetExplorerDriver, IPhoneDriver, PhantomJSDriver, RemoteWebDriver, [and] SafariDriver". [10])

The point of WebDriver is "[d]riving a browser natively as a user would either locally or on a remote machine..." [6]

So, to use WebDriver, you need (a1) some browser with a WebDriver or (a2) a Selenium Server connnected to some browser with a WebDriver, and (b) something to talk to it.

Other useful tools

  • wd >>= grunt-mocha-selenium [22] =<< selenium-launcher (to dl and run server jars) [23] [better than 18]
  • wd >>= intern [17]
  • selenium-webdriver [19] [25] >>= protractor [20] (also includes a webdriver-manager tool, but otherwise all angularjs) >>= saucer [21]
  • BrowserStig [24] >>= karma
  • terminus [26] (with browser selection API [27]) >>= capybara

[28] https://saucelabs.com/selenium [27] http://terminus.jcoglan.com/ [26] https://github.com/jcoglan/terminus ((more js-only)) [25] https://code.google.com/p/selenium/wiki/WebDriverJs#Installing_from_NPM [24] https://npmjs.org/package/browserstig ((not selenium, more js-only)) [23] https://npmjs.org/package/selenium-launcher [22] https://npmjs.org/package/grunt-mocha-selenium [21] https://npmjs.org/package/saucer-js [20] https://npmjs.org/package/protractor [19] https://npmjs.org/package/selenium-webdriver ((official)) [18] https://npmjs.org/package/selenium-standalone-wrapper [17] https://npmjs.org/package/intern [16] https://npmjs.org/package/yiewd [15] https://npmjs.org/package/wd-query [14] https://npmjs.org/package/wd-sync [13] https://code.google.com/p/selenium/wiki/DesiredCapabilities [12] https://github.com/admc/wd [11] https://npmjs.org/package/wd [10] http://docs.seleniumhq.org/projects/webdriver/ [9] https://code.google.com/p/selenium/wiki/JsonWireProtocol [8] http://docs.seleniumhq.org/docs/03_webdriver.jsp#running-standalone-selenium-server-for-use-with-remotedrivers [7] http://docs.seleniumhq.org/ [6] http://docs.seleniumhq.org/projects/webdriver/ [5] http://hindsighttesting.com/blog/2013/08/14/Cross-browser-testing-JavaScript/ [4] https://npmjs.org/package/soda [3] https://github.com/karma-runner/karma-webdriver-launcher [2] https://github.com/karma-runner/karma "If you're testing in the browser, make sure the Karma tab is the active tab. If you're using LiveReload to develop, try opening a second browser window so Karma can always be active." [1] https://npmjs.org/package/karma

Yeoman might do everything, but I haven't found a generator which does exactly what I want.

And we have to learn grunt anyways. Here's a tutorial: http://kroltech.com/2013/12/boilerplate-web-app-using-backbone-js-expressjs-node-js-mongodb/

Express is easy to set up for static content (including by default): http://blog.modulus.io/nodejs-and-express-static-content

And we should probably use either Buster.JS or Jasmine. Buster is here: http://docs.busterjs.org/en/latest/ Both node.js and in-browser test runners are available, so I won't go nuts flipping from QUnit to nodeunit or whatever BS.

And for Selenium Server hub/node setup: http://www.packtpub.com/sites/default/files/downloads/Distributed_Testing_with_Selenium_Grid.pdf

jshint: https://raw.github.com/jshint/jshint/2.x/examples/.jshintrc

http://tech.pro/tutorial/1190/package-managers-an-introductory-guide-for-the-uninitiated-front-end-developer#what_is_bower http://requirejs.org/docs/start.html

http://jessewarden.com/archives/node-bower-grunt-cheat-sheet-v1-jessewarden.com.pdf

https://npmjs.org/package/grunt-browserify-bower

Yeoman: http://yeoman.io/gettingstarted.html

npm run: http://substack.net/task_automation_with_npm_run

also: lodash: http://lodash.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment