chai-webdriver-exec Build Status

Provides selenium-webdriver support for asserting executed scripts in Chai. This plugin is complementary to the chai-webdriver plugin which only adds support for dom-based assertions.


All assertions use an exec mechanism and work with chai.expect():

chai.expect('return document.childElementCount')
chai.expect('return document.childElementCount')

The script to be executed is the first argument to chai.expect() and will be passed to executeScript(). For the assertion to work the script must have a return value.

For a list of possible assertions see the test file. Basically all BDD assertions are supported except: arguments, itself, extensible, sealed, frozen, throw, respondTo, change, increase, decrease (due to the nature of executing a script remotely).

Asynchronous flow

All these assertions are presumed to be asynchronous (using selenium-webdriver’s promise chain). They can all take callbacks, or be chained with promises. For example:

expect(script)'string', function(){...})

Note that this usage is not required if using the selenium-webdriver/testing wrappers.


npm i --save-dev chai-webdriver-exec

and then in your test file:

var chaiWebdriverExec = require('chai-webdriver-exec')


var webdriver = require('selenium-webdriver'),
  test = require('selenium-webdriver/testing')
var driver = new webdriver.Builder()

var chai = require('chai')
var chaiWebdriverExec = require('chai-webdriver-exec')
chai.use(chaiWebdriverExec(driver)) // here you hook it up

test.describe('some cool feature', function() {
  this.timeout(10000)'should work as expected', function() {
    chai.expect('return window.scrollX')'number')


npm test