webdriverjs

webdriverjs (GitHub: camme/webdriverjs, License: MIT) is a module by Camilo Tapia that makes it possible to write super easy selenium tests in your favorite BDD or TDD test framework. webdriverjs is not the “official webdriverjs driver” says Christian Bromann in this thread:

We’re trying to provide a selenium runner which is easy to use, highly extendable and compatible with all common JavaScript test frameworks. It uses an own chain API to execute all async commands in right order. The specialty of this library is that we wrap all JSONWire protocol commands in useful actions commands. So you don’t have to care about to get an element first and then call the click command; you just execute the click with a selector as parameter.

 

1
npm install webdriverjs

Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var webdriverjs = require('webdriverjs');
var options = {
  desiredCapabilities: {
    browserName: 'chrome'
  }
};
webdriverjs
  .remote(options)
  .init()
  .title(function(err, res) {
    console.log('Title was: ' + res.value);
  })
  .end();

Selector API

The JsonWireProtocol provides several strategies to query an element. webdriverjs simplifies these to make it more familiar with the common existing selector libraries like Sizzle. The following selector types are supported:

  • CSS query selector
  • link text
  • partial link text
  • tag name
  • name attribute
  • xPath

More

Here is a simplified example of differences between the drivers:

selenium-webdriverjs:

1
2
3
driver.get('http://www.google.com');
driver.findElement(webdriver.By.id('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.id('btnG')).click();

WD.js:

1
2
3
4
5
6
browser
  .elementById('q')
  .sendKeys('webdriver')
  .elementById('btnG')
  .click()

webdriverjs:

1
2
3
4
client
    .url('http://google.com')
    .setValue('#q','webdriver')
    .click('#btnG')

webdriverjs has also almost all protocol commands implemented, so you can do the same with the standard JSONWire protocol commands.

1
2
3
4
5
6
7
8
client
    .url('http://google.com')
    .element('#q', function(err,res) {
        client.elementIdValue(res.value.ELEMENT, 'webdriver');
    })
    .element('#btnG', function(err,res) {
        client.elementIdClick(res.value.ELEMENT);
    });

Post navigation

Leave a comment

Leave a Reply

Your email address will not be published.