README
WD.js -- A light weight WebDriver/Se2 client for node.js
Update node to latest
Install
npm install wd
Authors
- Adam Christian (admc)
- Ruben Daniels (javruben)
- Peter Braden (peterbraden)
- Seb Vincent (sebv)
License
- License - Apache 2: http://www.apache.org/licenses/LICENSE-2.0
Usage
): wd shell > x = wd.remote() or wd.remote("ondemand.saucelabs.com", 80, "username", "apikey") > x.init() or x.init({desired capabilities ovveride}) > x.get("http://www.url.com") > x.eval("window.location.href", function(e, o) { console.log(o) }) > x.quit()
Writing a test!
var webdriver = require('wd') , assert = require('assert'); var browser = webdriver.remote(); browser.on('status', function(info){ console.log('\x1b[36m%s\x1b[0m', info); }); browser.on('command', function(meth, path){ console.log(' > \x1b[33m%s\x1b[0m: %s', meth, path); }); desired = { browserName:'chrome' , tags: ["examples"] , name: "This is an example test" } browser.init(desired, function() { browser.get("http://saucelabs.com/test/guinea-pig", function() { browser.title(function(err, title) { assert.ok(~title.indexOf('I am a page title - Sauce Labs'), 'Wrong title!'); browser.elementById('submit', function(err, el) { browser.clickElement(el, function() { browser.eval("window.location.href", function(err, title) { assert.ok(~title.indexOf('#'), 'Wrong title!'); browser.quit() }) }) }) }) }) })
Supported Methods
JsonWireProtocol | wd |
GET /status Query the server's current status. |
status(cb) -> cb(err, status) |
POST /session Create a new session. |
init(desired, cb) -> cb(err, sessionID) |
GET /sessions Returns a list of the currently active sessions. |
|
GET /session/:sessionId Retrieve the capabilities of the specified session. |
sessionCapabilities(cb) -> cb(err, capabilities) |
DELETE /session/:sessionId Delete the session. |
quit(cb) -> cb(err) |
POST /session/:sessionId/timeouts Configure the amount of time that a particular type of operation can execute for before they are aborted and a |Timeout| error is returned to the client. |
|
POST /session/:sessionId/timeouts/async_script Set the amount of time, in milliseconds, that asynchronous scripts executed by /session/:sessionId/execute_async are permitted to run before they are aborted and a |Timeout| error is returned to the client. |
setAsyncScriptTimeout(ms, cb) -> cb(err) |
POST /session/:sessionId/timeouts/implicit_wait Set the amount of time the driver should wait when searching for elements. |
setImplicitWaitTimeout(ms, cb) -> cb(err) |
GET /session/:sessionId/url Retrieve the URL of the current page. |
url(cb) -> cb(err, url) |
POST /session/:sessionId/url Navigate to a new URL. |
get(url,cb) -> cb(err) |
POST /session/:sessionId/forward Navigate forwards in the browser history, if possible. |
forward(cb) -> cb(err) |
POST /session/:sessionId/back Navigate backwards in the browser history, if possible. |
back(cb) -> cb(err) |
POST /session/:sessionId/refresh Refresh the current page. |
refresh(cb) -> cb(err) |
POST /session/:sessionId/execute Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. |
|
POST /session/:sessionId/execute_async Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. |
|
DELETE /session/:sessionId/window Close the current window. |
close(cb) -> cb(err) |
GET /session/:sessionId/cookie Retrieve all cookies visible to the current page. |
allCookies() -> cb(err, cookies) |
POST /session/:sessionId/cookie Set a cookie. |
setCookie(cookie, cb) -> cb(err) |
DELETE /session/:sessionId/cookie Delete all cookies visible to the current page. |
deleteAllCookies(cb) -> cb(err) |
DELETE /session/:sessionId/cookie/:name Delete the cookie with the given name. |
deleteCookie(name, cb) -> cb(err) |
GET /session/:sessionId/title Get the current page title. |
title(cb) -> cb(err, title) |
POST /session/:sessionId/element Search for an element on the page, starting from the document root. |
|
POST /session/:sessionId/elements Search for multiple elements on the page, starting from the document root. |
|
POST /session/:sessionId/element/active Get the element on the page that currently has focus. |
active(cb) -> cb(err, element) |
POST /session/:sessionId/element/:id/click Click on an element. |
clickElement(element, cb) -> cb(err) |
GET /session/:sessionId/element/:id/text Returns the visible text for the element. |
|
POST /session/:sessionId/element/:id/value Send a sequence of key strokes to an element. |
|
POST /session/:sessionId/keys Send a sequence of key strokes to the active element. |
|
POST /session/:sessionId/element/:id/clear Clear a TEXTAREA or text INPUT element's value. |
clear(element, cb) -> cb(err) |
GET /session/:sessionId/element/:id/attribute/:name Get the value of an element's attribute. |
|
POST /session/:sessionId/accept_alert Accepts the currently displayed alert dialog. |
acceptAlert(cb) -> cb(err) |
POST /session/:sessionId/dismiss_alert Dismisses the currently displayed alert dialog. |
dismissAlert(cb) -> cb(err) |
POST /session/:sessionId/moveto Move the mouse by an offset of the specificed element. |
moveTo(element, xoffset, yoffset, cb) -> cb(err) |
POST /session/:sessionId/click Click any mouse button (at the coordinates set by the last moveto command). |
click(button, cb) -> cb(err) buttons: {left: 0, middle: 1 , right: 2} |
POST /session/:sessionId/buttondown Click and hold the left mouse button (at the coordinates set by the last moveto command). |
buttonDown(cb) -> cb(err) |
POST /session/:sessionId/buttonup Releases the mouse button previously held (where the mouse is currently at). |
buttonUp(cb) -> cb(err) |
POST /session/:sessionId/doubleclick Double-clicks at the current mouse coordinates (set by moveto). |
doubleclick(cb) -> cb(err) |
EXTRA: waitForCondition Waits for JavaScript condition to be true (polling within wd client). |
waitForCondition(conditionExpr, timeout, pollFreq, cb) -> cb(err, boolean)
|
EXTRA: waitForConditionInBrowser Waits for JavaScript condition to be true. (async script polling within browser) |
waitForConditionInBrowser(conditionExpr, timeout, pollFreq, cb) -> cb(err, boolean)
|
Full JsonWireProtocol mapping:
More docs!
WD is simply implementing the Selenium JsonWireProtocol, for more details see the official docs: - http://code.google.com/p/selenium/wiki/JsonWireProtocol
Run the tests!
- Run the selenium server with chromedriver: java -jar selenium-server-standalone-2.21.0.jar -Dwebdriver.chrome.driver=<PATH>/chromedriver - cd wd - npm install . - make test - look at the results!