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:
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 ;~;
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();
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With