GhostDriver is a project that lets you write Selenium WebDriver automation tests that run using the PhantomJS headless WebKit, instead of a traditional web browser.
Put another way, PhantomJS can replace Firefox and friends in your WebDriver scripts - and it doesn’t require a display, so testing complex web apps from the command line is just about as easy as using a GUI browser. Very cool!
Getting your system ready to run Python scripts that use GhostDriver can be done in a few brief steps, if you have homebrew on OS X.
First you’ll need the Selenium python package:
1
| |
Then, use homebrew to install PhantomJS:
1
| |
If you don’t want to use homebrew (or you’re not on a Mac) you can simply download the latest PhantomJS build manually and install it.
Believe it or not, that is all. GhostDriver is integrated into PhantomJS, so you should now be set up to take them for a test drive.
A typical Hello World program in the web automation world is one that performs a Google search. So, here’s what that looks like in Python and GhostDriver, using Python in interactive mode:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
A natural next step, when developing automated test cases based on experiments like the one above, is to start storing your code into a Python unittest script.
Here’s an example of how one might start organizing the code above:
If all is right with the world, running the above script will print output along the lines of the text below.
1 2 3 4 5 6 7 | |
That’s all for the moment. Now, go forth and Ghost Drive!




First, launch vim and write a small program - for example, Foo.java:
Then, compile your program without leaving vim by passing the file open in your vim buffer to javac, using the :! command sequence and %
If all goes well, you’ll temporarily be dropped to the shell, with no visible errors, and get prompted to press ENTER to continue back to vim:
Back in the editor, use :!java Foo to invoke the Java class file you just created with javac:
Finally, you’ll see your program’s output in the console.





