I created phandom a few months ago, but yesterday finally found the time to make some needed changes to it. So, now is a good time to explain how Iâm using Phandom in some of my unit tests.
Before I get started, though, I should say a few words about phantomjs, which is a JavaScript interface for WebKit. WebKit, on the other hand, is a web browser without a user interface. WebKit is a C++ library that enables manipulation of HTML content, through DOM calls. For example, this is a simple JavaScript located code in example.js:
var page = require('webpage').create();
page.open(
'http://google.com',
function() {
console.log('loaded!');
phantom.exit(0);
}
);
We run phantomjs from the command line with the following code:
PhantomJS creates a page object (provided by webpage module inside phantomjs), and then asks it to open() a Web page. The object communicates with WebKit and converts this call into DOM instructions. After which, the page loads. The PhantomJS engine then terminates on line 6.