Michael Zhang Michael Zhang - 5 months ago 40
Node.js Question

Error: done() invoked with non-Error: {}

I'm trying to set up automatic testing, using Mocha and PhantomJS on Selenium with Node. I'm using

selenium-webdriver
library since it seems to be a popular one, but when I run the test and try to extract data from a page, it gives me this error:

1) Test "before each" hook for "Test":
Error: done() invoked with non-Error: {}
at ManagedPromise.invokeCallback_ (node_modules/selenium-webdriver/lib/promise.js:1379:14)
at TaskQueue.execute_ (node_modules/selenium-webdriver/lib/promise.js:2913:14)
at TaskQueue.executeNext_ (node_modules/selenium-webdriver/lib/promise.js:2896:21)
at node_modules/selenium-webdriver/lib/promise.js:2775:27
at node_modules/selenium-webdriver/lib/promise.js:639:7


I'm not sure why this problem is happening, and searching didn't help because the solutions I had didn't fit my scenario; I'm on:


  • Mac OS X 10

  • Node.js v4.4.5

  • PhantomJS 2.1.1



Here's my script:

var selenium = require("selenium-webdriver");
var should = require("should");

var URL = "https://android.com";
var driver;

describe("Test", function() {
this.timeout(15000);

beforeEach(function(done) {
driver = new selenium.Builder()
.withCapabilities(selenium.Capabilities.phantomjs())
.build();
driver.get(URL).then(done);
});

/* is this an HTML page? */
it("Test", function() {
driver
.getPageSource()
.should.eventually
.match(/(.*)\<\!doctype\ html\>(.*)/i);
});

afterEach(function(done) {
driver.quit().then(done);
});
});


I've also tried using some gulp scripts I found and other Node.js libraries but they all return different errors ;~;

Answer

Anything passed to the done callback as a parameter will be interpreted as an error. Change beforeEach to:

beforeEach(function(done) {
    driver = new selenium.Builder()
        .withCapabilities(selenium.Capabilities.phantomjs())
        .build();
    driver.get(URL).then(function(){
        done();
    });
});