Skip to content

How Dalek Uses WebDriver

Rodney Rehm edited this page Apr 25, 2015 · 2 revisions

This document describes which components are involved in making WebDriver work for Dalek.

Dalek uses WD.js as the WebDriver client. Drivers (e.g. dalek-driver-phantomjs, dalek-driver-chrome) are used to start WebDriver servers for their browsers.

Within Dalek Drivers

It is the responsibility of the driver to provide a specification (JsonWireProtocol) compliant WebDriver server. If a given browser does not support WebDriver at all, but some other means to control the browser, e.g. Marionette, the driver has to provide the WebDriver service and translate that to the internally used protocol. If a browser provides WebDriver only partially or faulty, it is the driver's responsibility to fill that gap.

Because browsers need to be started with certain arguments to engage WebDriver, it is the driver's responsibility to provide a simple means to configure, start, stop and kill the browser binary accordingly.

As with every specification, WebDriver (actually JsonWireProtocol) does not describe every little detail. E.g. it does not say if POST :sessionId/url (or in Dalek's terms browser.open) should finish after "browser was told to load that URL", "browser started loading the document", "DOMContentLoaded Event", "Load Event". The spec says nothing about how "host could not be resolved" should be communicated, so opening http://asdlkfalsdkjvlkyxcjy.asd will always return with success, but any subsequent GET :sessionId/url will return some url depending on the browser (PhantomJS: about:blank, Chrome: data:text/html,chromewebdata). In these situations it is the driver's responsibility to maintain a capability mapping (defined in dalek-driver) for any client to consume and use as they please. The capability mapping is extended on demand.

Drivers, although called Dalek Drivers, do not contain Dalek specific code. They MUST be usable without Dalek.

Within Dalek

Dalek itself loads a Dalek driver like a normal node module to gain access to the process control (start, stop, kill) and capability map. Dalek takes care of starting, stopping and killing the driver in its lifecycle management. During the "load" phase the driver is initialized and exposed at dalek.driver. During the "start" phase the driver is started, when successful the WebDriver configuration returned by the driver is used to initialize WD.js, which is exposed at dalek.wd.

Dalek registers additional methods (eg matchElements) on WD.js for simpler plugin authoring. Only methods that are generic or used by multiple plugins should be registered on WD directly, by being placed in the dalek:src/wd/ directory. It is not planned to open this up to 3rd party development.

It's the action and assertion plugins that finally make use of WD.js. These plugins can make use of the driver's capability map to provide a better user experience.

Clone this wiki locally