最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error: done() invoked with non-Error: {} - Stack Overflow

programmeradmin5浏览0评论

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 = "";
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 ;~;

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.";
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 ;~;

Share Improve this question edited Jun 17, 2016 at 15:24 Rob 15.2k30 gold badges48 silver badges73 bronze badges asked Jun 17, 2016 at 15:22 Michael ZhangMichael Zhang 1,8151 gold badge14 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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();
    });
});
发布评论

评论列表(0)

  1. 暂无评论