Headless Testing with GhostDriver and PhantomJs
One major use case of PhantomJS is headless testing of web applications. It is suitable for general command-line based testing, as well as with the CI system.
Bringing you here the WebDriver Implementation of PhantomJs Headless Testing.
PhantomJS itself is not a test framework, it is only used to launch the tests via a suitable test runner. Here is a list of different test framework and test runner.
WebDriver Implementation for PhantomJs == GhostDriver
WebDriver bindings == PhantomJsDriver
Architecture Implementation of GhostDriver
Below is a diagrammatic representation of GhostDriver implementation.
How to use it ?
- Download PhantomJs as per your OS.
I am using Mac and hence this blog post will follow Setting up PhantomJs with Selenium WebDriver
Download and extract the package. or windows its an exe file and for Mac its just a zip package you will need to extract and SET the phantomjs in the PATH.
You will need to setup the Phantomjs executable that is in the bin folder to some PATH.
Starting the PhantomJs in a Remote WebDriver mode
PhantomJs will launch the GhostDriver…
We are done with the Setup, now we can use any RemoteWebDriver implementation to send commands to it.
PhantomJsDriver Implementations expects a value to be passed and we will pass the Desired capabilities Instance.
Below is the Sample Code, which shows us the PhantomJsDriver implementation.
Hope this blog post helps people who wants to get started with the GhostDriver and phantomJs Headless Testing using WebDriver.
A special Thanks to Ivan De Marino and Ariya Hidayat for creating this wonderful projects.