- Ghost Driver PC settings: Configure PhantomJS bindings for Selenium WebDriver automation
- Core architecture: Ghost Driver runs as a JavaScript implementation inside PhantomJS
- Essential capability: Set
phantomjs.binary.pathto point to your local executable - Headless advantage: No display server required, ideal for CI/CD pipelines
- Custom switches: Pass CLI arguments via
phantomjs.cli.argsfor SSL and rendering control
Understanding Ghost Driver and PC Settings
Ghost Driver serves as the WebDriver implementation built into PhantomJS, enabling headless browser automation through the W3C WebDriver protocol. When configuring Ghost Driver PC settings, you are essentially bridging your Selenium client tests with the PhantomJS headless browser engine.
Video Highlights:
- Explains the dual nature of Ghost Driver as both a script and an embedded module
- Covers the sequence diagram of what happens during driver initialization
- Demonstrates how to pass custom capabilities and CLI arguments
- Details the differences between PhantomJS and HTMLUnit for testing
When you initialize a new PhantomJSDriver instance in your test suite, the system creates a driver service that spawns a separate PhantomJS process. This process executes the Ghost Driver script, which then listens on a local endpoint for WebDriver commands. Understanding this flow is critical for optimizing your local PC settings.
Do not confuse Ghost Driver with PhantomJSDriver bindings. Ghost Driver is the JavaScript implementation running inside PhantomJS. PhantomJSDriver refers to the Selenium client bindings (the classes you import in your test scripts) that communicate with Ghost Driver via HTTP.
| Component | Type | Language | Role |
|---|---|---|---|
| Ghost Driver | WebDriver Implementation | JavaScript | Runs inside PhantomJS, handles W3C protocol |
| PhantomJSDriver | Client Binding | Java/Python/Ruby/.NET | Classes used in test scripts to launch the browser |
| PhantomJS | Headless Browser | C++ | WebKit-based engine executing the page rendering |
| Selenium Grid | Hub/Node Architecture | Various | Distributes test instances across machines |
Essential PC Configuration Parameters
Configuring Ghost Driver PC settings requires defining specific Desired Capabilities in your Selenium tests. These capabilities tell the binding where the PhantomJS executable is located and how to launch it.
The most critical setting is phantomjs.binary.path. Without this parameter, your test script will not know where to find the PhantomJS executable on your machine. Additionally, you can pass command-line arguments directly to the PhantomJS process using phantomjs.cli.args.
Always verify that the path provided in phantomjs.binary.path points to the actual executable file, not just the directory. An incorrect path is the most common cause of initialization failures.
| Capability Key | Purpose | Example Value |
|---|---|---|
phantomjs.binary.path | Points to the PhantomJS executable | /usr/local/bin/phantomjs |
phantomjs.ghostdriver.path | Points to a custom Ghost Driver script (for contributors) | /path/to/ghostdriver/main.js |
phantomjs.cli.args | Array of CLI arguments passed to the process | ["--ignore-ssl-errors=true"] |
phantomjs.page.settings.X | Overrides page object properties (e.g., userAgent) | Mozilla/5.0 (iPhone...) |
Binary Path
- Required for local execution
- Must point directly to the executable file
- Use absolute paths to avoid resolution errors
CLI Arguments
- Passed as an array of strings
- Supports SSL error ignoring
- Enables remote debugger configuration
Page Settings
- Overrides default browser properties
- Custom User-Agent strings
- Applied to every new session
Step-by-Step Setup Guide
Follow these steps to configure Ghost Driver PC settings on your local machine. This guide assumes you have a basic Selenium project already set up in your preferred programming language.
Download PhantomJS
Download the appropriate PhantomJS build for your operating system from the official website. Unzip the package and note the location of the executable file. Alternatively, you can build PhantomJS from source, though this process can take over an hour on fast machines since it compiles the entire WebKit engine.
Add Selenium Bindings
Add the Selenium WebDriver bindings to your project. In Java, include the selenium-java and selenium-server dependencies via Maven or Gradle. For Python, simply install the selenium package. The PhantomJSDriver classes are bundled within the standard Selenium library.
Configure Desired Capabilities
Create a DesiredCapabilities object and set the phantomjs.binary.path capability to the absolute path of your PhantomJS executable. Add any necessary CLI arguments to the phantomjs.cli.args capability array.
Initialize the Driver
Pass the configured capabilities object to a new PhantomJSDriver instance. The driver service will automatically spawn the PhantomJS process, execute Ghost Driver, and establish a WebDriver session.
Run Tests Headlessly
Execute your test suite. PhantomJS will run completely headlessly without popping up browser windows, making it ideal for continuous integration environments and command-line execution.
After initialization, your test script will poll the /status endpoint on the local port. Once it receives an HTTP 200 OK response, a new session is created automatically. You can then use standard WebDriver commands like driver.get(url) to navigate.
SSL, Security, and Grid Settings
When running automated tests against internal or staging environments, you frequently encounter self-signed SSL certificates. Ghost Driver PC settings provide specific capabilities to handle these scenarios gracefully.
To ignore SSL certificate errors, pass the --ignore-ssl-errors=true argument through the phantomjs.cli.args capability. You can also pass --web-security=false to disable same-origin policy checks during testing.
Only disable SSL verification and web security in testing environments. Never use these settings in production or when handling sensitive user data.
| CLI Argument | Effect | Use Case |
|---|---|---|
--ignore-ssl-errors=true | Bypasses all certificate validation errors | Internal staging servers with self-signed certs |
--web-security=false | Disables cross-origin security policies | Testing iframe interactions and CORS behavior |
--remote-debugger-port=9000 | Enables remote debugging via Web Inspector | Debugging Ghost Driver JavaScript code |
--webdriver=8080 | Sets a custom port for the WebDriver listener | Running multiple instances simultaneously |
For Selenium Grid integration, you can register your PhantomJS instance to a hub by passing the --webdriver-selenium-grid-hub parameter with the hub URL. This allows the grid to distribute PhantomJS instances across multiple test machines.
To debug Ghost Driver internals, start PhantomJS with --remote-debugger-port=9000 and --remote-debugger-autorun=yes. Open Chrome or Safari's Web Inspector and connect to the PhantomJS instance to step through the JavaScript code.
Advanced Customization and Limitations
Ghost Driver PC settings support advanced page-level customizations through the phantomjs.page.settings capability prefix. This allows you to override properties on every page object created during a session.
A common use case is overriding the User-Agent string. Some websites filter traffic based on User-Agent to block screen scraping. By setting a custom User-Agent, you can simulate different devices such as iOS or Android browsers.
| Page Setting | Description | Common Value |
|---|---|---|
userAgent | Overrides the browser User-Agent string | Mozilla/5.0 (iPhone; CPU iPhone OS 10_0...) |
javascriptEnabled | Enables or disables JavaScript execution | true |
loadImages | Controls whether images are loaded | false (for faster scraping) |
resourceTimeout | Sets maximum resource load time in ms | 10000 |
As of version 1.0.2, several WebDriver commands are not yet implemented in Ghost Driver. Missing features include the Touch API, geolocation API, mobile emulation, local storage manipulation, and alert/confirm/prompt handling. Check the official implementation spreadsheet for current status.
Optimization Checklist:
- Set phantomjs.binary.path to absolute executable location
- Disable image loading for faster scraping performance
- Pass --ignore-ssl-errors=true for internal testing
- Override User-Agent when testing responsive layouts
- Register with Selenium Grid for distributed testing
Frequently Asked Questions
Q: What is the difference between Ghost Driver and PhantomJS?
PhantomJS is a headless WebKit browser written in C++. Ghost Driver is a JavaScript implementation of the WebDriver protocol that runs inside PhantomJS. When you configure Ghost Driver PC settings, you are telling Selenium how to communicate with PhantomJS through the Ghost Driver interface.
Q: How do I pass custom command-line arguments to PhantomJS?
Use the `phantomjs.cli.args` desired capability. Pass an array of strings where each string represents a CLI argument. For example, to ignore SSL errors, set the capability to an array containing `--ignore-ssl-errors=true`.
Q: Can I use Ghost Driver with Selenium Grid?
Yes. Start PhantomJS with the `--webdriver-selenium-grid-hub` parameter followed by your hub URL. The PhantomJS instance will automatically register itself with the grid and become available for distributed test execution.
Q: Why does my test fail with 'not implemented' errors?
Ghost Driver does not yet implement every WebDriver command. The Touch API, geolocation, local storage, and alert handling are among the features not currently supported. Check the official implementation status spreadsheet to verify if your specific command is available.