lundi 16 février 2015

Using createPage() twice for the same phantom instance


I'm trying to set up mocha tests with PhantomJS and I've encountered a problem where I can't use the same phantom instance to create multiple pages. The first test case runs just fine, but the second one times-out. I'd like to use just one instance, because it should be faster.



var assert = require('assert');
var phantom = require('phantom');
var path = require('path');

var ph;

describe('document', function() {
before(function(done) { // Create only one phantom instance for the whole suite
this.timeout(10000); // Prevent test case from aborting while phantom loads
phantom.create(function(p) {
ph = p;
done();
}, {
dnodeOpts: {weak: false}
});
});

it('should have a title', function(done) {
ph.createPage(function(page) {
var url = 'file:///' + path.resolve(__dirname + '/index.html');
page.open(url, function(status) {
page.evaluate(function() {
return document.title;
}, function(title) {
assert.equal('This is a title', title);
ph.exit();
done();
});
});
});
});

it('should have the same title', function(done) {
ph.createPage(function(page) {
var url = 'file:///' + path.resolve(__dirname + '/index.html');
page.open(url, function(status) {
page.evaluate(function() {
return document.title;
}, function(title) {
assert.equal('This is a title', title);
ph.exit();
done();
});
});
});
});
});


Why won't it open the page the second time?





Aucun commentaire:

Enregistrer un commentaire