$ npm install phantom-proxy
PhantomJs is an incredibly useful tool for functional and unit testing. PhantomJs runs in its own process, making it difficult to drive from node. Phantom-proxy solves this problem, allowing you to fully drive phantomjs from node.
npm install phantom-proxy
See the API documentation for more usage information.
var phantomProxy = require('phantom-proxy');
phantomProxy.create({}, function (proxy) {
var page = proxy.page;
page.open('http://www.w3.org', function () {
page.waitForSelector('body', function () {
console.log('body tag present');
proxy.end();
});
});
});
phantomProxy.create({"debug":true}, function (proxy) {
proxy.page.open('http://www.w3.org', function (result) {
assert.equal(result, true);
proxy.page.waitForSelector('body', function (result) {
assert.equal(result, true);
proxy.page.render('./scratch/scratch.png', function (result) {
assert.equal(result, true);
proxy.end(function () {
console.log('done');
});
});
}, 1000);
});
});
phantomProxy.create({"debug":true}, function (proxy) {
self.proxy.page.on('navigationRequested', function (url) {
console.log('at %s', url);
if (url === 'http://www.w3.org') {
console.log('at w3.org');
}
else {
console.log('how did we get here?');
}
});
proxy.page.open('http://www.w3.org', function (result) {
proxy.page.on('alert', function (msg) {
if (msg.trim() === 'hello') {
console.log('it said hello');
}
});
proxy.end(function () {
console.log('done');
});
});
});
© 2010 - cnpmjs.org x YWFE | Home | YWFE