Skip to content

Instantly share code, notes, and snippets.

@christian-bromann
Created September 2, 2013 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save christian-bromann/6416885 to your computer and use it in GitHub Desktop.
Save christian-bromann/6416885 to your computer and use it in GitHub Desktop.
run WebdriverJS with Mocha
var webdriverjs = require('webdriverjs'),
assert = require('assert');
describe('my webdriverjs tests', function(){
this.timeout(99999999);
var client = {};
before(function(){
client = webdriverjs.remote({ desiredCapabilities: {browserName: 'phantomjs'} });
client.init();
});
it('Github test',function(done) {
client
.url('https://github.com/')
.getElementSize('.header-logo-wordmark', function(err, result) {
assert(err === null);
assert(result.height === 32);
assert(result.width === 89);
})
.getTitle(function(err, title) {
assert(err === null);
assert(title === 'GitHub · Build software better, together.');
})
.getElementCssProperty('css selector','a[href="/plans"]', 'color', function(err, result){
assert(err === null);
assert(result === 'rgba(65,131,196,1)');
})
.call(done);
});
after(function(done) {
client.end(done);
});
});
@akloeber
Copy link

I think mocha's done callback has to be passed to client.init() like so:

before(function(done){
    client = webdriverjs.remote({ desiredCapabilities: {browserName: 'chrome'} });
    client.init(done);
});

Without passing the done() callback to init() the test fails upon the second re-execution due to a code change when using mocha -w (i.e watch mode):

[17:12:47]:  ERROR  COULDNT GET A SESSION ID
[17:12:47]:  Exiting process with 1
npm ERR! weird error 1
npm ERR! not ok code 0

@wayneseymour
Copy link

Worked for me! Woo-Hoo So, who will win WebDriver.io or WebDriverJS?! The race is on! lol

@sri85
Copy link

sri85 commented May 30, 2014

I get an error "describe is not defined" when i try to run the script. Am i missing something?

@marek-saji
Copy link

@sri85 Are you running it with mocha (and not node directly)?

mocha webdriverjs.with.mocha.js

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