Convert Figma logo to code with AI

detro logoghostdriver

Ghost Driver is an implementation of the Remote WebDriver Wire protocol, using PhantomJS as back-end

1,913
339
1,913
156

Top Related Projects

30,518

A browser automation framework and ecosystem.

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

88,205

JavaScript API for Chrome and Firefox

46,847

Fast, easy and reliable testing for anything that runs in a browser.

18,791

Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol

Next-gen browser and mobile automation test framework for Node.js

Quick Overview

GhostDriver is a pure JavaScript implementation of the WebDriver Wire Protocol for PhantomJS. It allows you to control a headless browser using Selenium WebDriver, making it useful for web scraping, automated testing, and other scenarios where a visible browser is not necessary.

Pros

  • Headless operation, which is faster and more resource-efficient than full browser testing
  • Cross-platform compatibility, running on various operating systems
  • Integrates well with existing Selenium WebDriver-based test suites
  • Supports JavaScript execution within web pages

Cons

  • No longer actively maintained (last commit was in 2017)
  • Limited support for modern web technologies compared to newer headless browser solutions
  • Potential compatibility issues with the latest versions of Selenium WebDriver
  • Lack of visual rendering can make some types of testing challenging

Code Examples

  1. Creating a WebDriver instance:
from selenium import webdriver

driver = webdriver.PhantomJS()
  1. Navigating to a webpage and getting the title:
driver.get("https://www.example.com")
title = driver.title
print(f"Page title: {title}")
  1. Finding an element and interacting with it:
element = driver.find_element_by_id("search-input")
element.send_keys("GhostDriver")
element.submit()
  1. Taking a screenshot:
driver.save_screenshot("screenshot.png")

Getting Started

To get started with GhostDriver:

  1. Install PhantomJS:

    npm install -g phantomjs-prebuilt
    
  2. Install Selenium WebDriver for your preferred language (e.g., Python):

    pip install selenium
    
  3. Use the WebDriver in your code:

    from selenium import webdriver
    
    driver = webdriver.PhantomJS()
    driver.get("https://www.example.com")
    print(driver.title)
    driver.quit()
    

Note: Given the project's inactive status, it's recommended to consider more modern alternatives like headless Chrome or Firefox for new projects.

Competitor Comparisons

30,518

A browser automation framework and ecosystem.

Pros of Selenium

  • Broader browser support, including Chrome, Firefox, Safari, and Edge
  • More comprehensive feature set for web automation and testing
  • Larger community and ecosystem with extensive documentation and resources

Cons of Selenium

  • Heavier resource usage and slower execution compared to GhostDriver
  • More complex setup and configuration, especially for beginners
  • Potential for increased test flakiness due to its full browser approach

Code Comparison

Selenium (Python):

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.example.com")
element = driver.find_element_by_id("search")
element.send_keys("test")
driver.quit()

GhostDriver (Python with PhantomJS):

from selenium import webdriver

driver = webdriver.PhantomJS()
driver.get("https://www.example.com")
element = driver.find_element_by_id("search")
element.send_keys("test")
driver.quit()

Key Differences

  • GhostDriver is specifically designed for PhantomJS, a headless browser, while Selenium supports multiple browsers
  • Selenium offers more advanced features and integrations, making it suitable for complex testing scenarios
  • GhostDriver provides faster execution and lower resource consumption, ideal for simpler automation tasks

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

Pros of Playwright

  • Cross-browser support for Chromium, Firefox, and WebKit
  • Modern, async/await-based API for easier test scripting
  • Built-in auto-wait functionality for improved test stability

Cons of Playwright

  • Steeper learning curve due to more advanced features
  • Larger package size and potentially higher resource usage

Code Comparison

Playwright:

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await browser.close();
})();

GhostDriver:

var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder()
    .forBrowser('phantomjs')
    .build();

driver.get('https://example.com');
driver.quit();

Summary

Playwright offers a more modern and feature-rich approach to browser automation, with cross-browser support and improved stability. However, it may require more resources and have a steeper learning curve compared to GhostDriver. GhostDriver, being PhantomJS-based, is lighter but limited to headless testing and has an older API style. The code comparison shows Playwright's async/await syntax versus GhostDriver's more traditional callback-based approach.

88,205

JavaScript API for Chrome and Firefox

Pros of Puppeteer

  • More active development and larger community support
  • Built-in support for modern web features and JavaScript
  • Easier setup and integration with Node.js projects

Cons of Puppeteer

  • Larger footprint and resource usage
  • Limited to Chromium-based browsers

Code Comparison

GhostDriver (WebDriver protocol):

WebDriver driver = new PhantomJSDriver();
driver.get("https://example.com");
WebElement element = driver.findElement(By.id("myElement"));
element.click();

Puppeteer:

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.click('#myElement');

Key Differences

  • GhostDriver uses PhantomJS, a headless WebKit browser, while Puppeteer controls Chromium/Chrome
  • Puppeteer offers a more modern API with Promise-based operations
  • GhostDriver follows the WebDriver protocol, making it compatible with various testing frameworks
  • Puppeteer provides more fine-grained control over browser behavior and performance

Use Cases

GhostDriver is better suited for:

  • Legacy projects requiring PhantomJS
  • Cross-browser testing with WebDriver compatibility

Puppeteer excels in:

  • Modern web scraping and automation tasks
  • Generating PDFs and screenshots
  • Performance testing and monitoring
46,847

Fast, easy and reliable testing for anything that runs in a browser.

Pros of Cypress

  • More active development and larger community support
  • Built-in debugging tools and real-time reloading
  • Easier setup and configuration process

Cons of Cypress

  • Limited cross-browser testing (primarily focused on Chrome)
  • Potential performance issues with large test suites
  • Cannot interact with multiple browser tabs or windows

Code Comparison

GhostDriver (WebDriver-based):

var driver = new webdriver.Builder()
    .withCapabilities(webdriver.Capabilities.phantomjs())
    .build();

driver.get('http://www.example.com');
driver.findElement(webdriver.By.id('element-id')).click();

Cypress:

cy.visit('http://www.example.com');
cy.get('#element-id').click();

Key Differences

  • GhostDriver is a PhantomJS implementation of WebDriver, while Cypress is a complete testing framework
  • Cypress uses a unique architecture that runs tests inside the browser, whereas GhostDriver runs tests externally
  • GhostDriver supports headless testing out of the box, while Cypress requires additional configuration for headless mode
  • Cypress offers a more modern and user-friendly API compared to GhostDriver's WebDriver-based approach
18,791

Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol

Pros of Appium

  • Supports multiple platforms (iOS, Android, Windows) unlike GhostDriver's focus on PhantomJS
  • Offers a wider range of language bindings (Java, Python, Ruby, etc.)
  • More active development and larger community support

Cons of Appium

  • More complex setup and configuration compared to GhostDriver
  • Potentially slower execution due to its cross-platform nature
  • Steeper learning curve for beginners

Code Comparison

Appium (Python):

from appium import webdriver

desired_caps = {
    'platformName': 'Android',
    'deviceName': 'Android Emulator',
    'app': '/path/to/app.apk'
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

GhostDriver (JavaScript):

var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder()
    .forBrowser('phantomjs')
    .build();

Summary

Appium offers broader platform support and language options, making it suitable for diverse testing needs. However, it comes with increased complexity and potential performance trade-offs. GhostDriver, while more limited in scope, provides a simpler setup for PhantomJS-based testing. The choice between the two depends on specific project requirements and team expertise.

Next-gen browser and mobile automation test framework for Node.js

Pros of WebdriverIO

  • Active development with frequent updates and a large community
  • Supports multiple programming languages and frameworks
  • Comprehensive documentation and extensive API

Cons of WebdriverIO

  • Steeper learning curve for beginners
  • Requires more setup and configuration compared to GhostDriver

Code Comparison

GhostDriver (JavaScript):

var driver = new webdriver.Builder()
    .withCapabilities(webdriver.Capabilities.phantomjs())
    .build();
driver.get('http://www.example.com');

WebdriverIO (JavaScript):

const browser = await remote({
    capabilities: {
        browserName: 'chrome'
    }
});
await browser.url('http://www.example.com');

Key Differences

  • GhostDriver is specifically designed for PhantomJS, while WebdriverIO supports multiple browsers
  • WebdriverIO offers more advanced features and integrations
  • GhostDriver is simpler to set up but has limited functionality compared to WebdriverIO

Use Cases

  • GhostDriver: Lightweight testing with PhantomJS, simple scripts
  • WebdriverIO: Complex test suites, cross-browser testing, CI/CD integration

Community and Support

  • GhostDriver: Smaller community, less frequent updates
  • WebdriverIO: Large active community, regular updates, and extensive third-party plugins

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Release FOSSA Status

Ghost Driver

Ghost Driver is a pure JavaScript implementation of the WebDriver Wire Protocol for PhantomJS. It's a Remote WebDriver that uses PhantomJS as back-end.

GhostDriver is designed to be integral part of PhantomJS itself, but it's developed in isolation and progress is tracked by this Repository.

  • Current GhostDriver stable version: see releases
  • PhantomJS-integrated version is "1.2.0" (detro@2af7099a9) : contained in PhantomJS "2.1.1"
  • Current PhantomJSDriver Java bindings stable version: see Maven

For more info, please take a look at the changelog.

The project was created and is lead by Ivan De Marino.

IRC channel: #phantomjs-ghostdriver.

Setup

  • Download latest stable PhantomJS from here
  • Selenium version ">= 3.1.0"

THAT'S IT!! Because of latest stable GhostDriver being embedded in PhantomJS, you shouldn't need anything else to get started.

Register GhostDriver with a Selenium Grid hub

  1. Launch the grid server, which listens on 4444 by default: java -jar /path/to/selenium-server-standalone-<SELENIUM VERSION>.jar -role hub
  2. Register with the hub: phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4444
  3. Now you can use your normal webdriver client with http://127.0.0.1:4444 and just request browserName: phantomjs

(Java) Bindings

This project provides WebDriver bindings for Java under the name PhantomJSDriver. Here is the JavaDoc.

Bindings for other languages (C#, Python, Ruby, ...) are developed and maintained under the same name within the Selenium project itself.

Include Java Bindings in your Maven project

For versions >= 2.0.0, add the following to your pom.xml:

<repositories>
  <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
  </repository>
</repositories>
<dependency>
    <groupId>com.github.detro</groupId>
    <artifactId>ghostdriver</artifactId>
    <version>2.1.0</version>
</dependency>

Include Java Bindings in your Gradle project

Just add the following to your build.gradle:

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}
dependencies {
    ...
    testCompile 'com.github.detro:ghostdriver:2.1.0'
    ...
}

Alternative: how to use it via RemoteWebDriver

Launching PhantomJS in Remote WebDriver mode it's simple:

$ phantomjs --webdriver=PORT

Once started, you can use any RemoteWebDriver implementation to send commands to it. I advice to take a look to the /test directory for examples.

F.A.Q.

What extra WebDriver capabilities GhostDriver offers?

  • GhostDriver extra Capabilities
    • phantomjs.page.settings.SETTING = VALUE - Configure page.settings on PhantomJS internal page objects (windows in WebDriver context) (see reference)
    • phantomjs.page.customHeaders.HEADER = VALUE - Add extra HTTP Headers when loading a URL (see reference)
    • phantomjs.page.whitelist - an array of regex expressions of urls to accept. eg. ['my-awesome-website.com']
    • phantomjs.page.blacklist - array of regex expressions of urls to ignore. The blacklist overrides the whitelist. eg. ['google.com', 'github.com']
    • unhandledPromptBehavior - set to dismiss to automatically dismiss all user prompts or set to accept to automatically accept all user prompts
    • loggingPrefs - ghostdriver has two logs browser and har. The logs default to "OFF". follow the DesiredCapabilities documentation to enable the logs.
  • PhantomJSDriver Java-binding Capabilities
    • phantomjs.binary.path - Specify path to PhantomJS executable to use
    • phantomjs.ghostdriver.path - Specify path to GhostDriver main/src.js script to use; allows to use a different version of GhostDriver then the one embed in PhantomJS
    • phantomjs.cli.args - Specify command line arguments to pass to the PhantomJS executable
    • phantomjs.ghostdriver.cli.args - Specify command line argument to pass to GhostDriver (works only in tandem with phantomjs.ghostdriver.path)

Want to help? Read on!

GhostDriver pushed the evolution of PhantomJS from the start. All the features required by PhantomJS to fit GhostDriver were designed to still feel "consistent" and "at home" with PhantomJS alone.

To drive that effort, I worked on a PhantomJS fork, and then pushed changes to PhantomJS master once agreed with the rest of the team on the changes.

If you are planning to contribute, that is the PhantomJS you should use.

Run validation tests

Here I show how to clone this repo and kick start the (Java) tests. You need Java SDK to run them. ghostdriver requires Java 1.8.

  1. git clone https://github.com/detro/ghostdriver.git
  2. Configure phantomjs_exec_path inside ghostdriver/test/config.ini to point at the build of PhantomJS you just did
  3. cd ghostdriver/test/java; ./gradlew test

Alternative: Run GhostDriver yourself and launch tests against that instance

  1. phantomjs --webdriver=PORT
  2. Configure driver inside ghostdriver/test/config.ini to point at the URL http://localhost:PORT
  3. cd ghostdriver/test/java; ./gradlew test

Project Directory Structure

Here follows the output of the tree -hd -L 3 command, trimmed of files and "build directories":

.
├── [ 102]  binding
│   └── [ 510]  java
│       ├── [ 204]  build
│       ├── [ 136]  gradle
│       ├── [ 884]  jars            <--- JARs containing Binding, related Source and related JavaDoc
│       └── [ 102]  src             <--- Java Binding Source
├── [ 442]  src                     <--- GhostDriver JavaScript core source
│   ├── [ 306]  request_handlers    <--- JavaScript "classes/functions" that handle HTTP Requests
│   └── [ 204]  third_party         <--- Third party/utility code
│       └── [2.0K]  webdriver-atoms <--- WebDriver Atoms, automatically imported from the Selenium project
├── [ 204]  test
│   ├── [ 476]  java                <--- Java Tests
│   │   ├── [ 136]  gradle
│   │   ├── [ 136]  out
│   │   └── [ 102]  src
│   ├── [ 238]  python              <--- Python Tests
│   │   └── [ 102]  utils
│   └── [ 340]  testcase-issue_240
└── [ 238]  tools                   <--- Tools (import/export)
    └── [ 136]  atoms_build_dir

20 directories

WebDriver Atoms

Being GhostDriver a WebDriver implementation, it embeds the standard/default WebDriver Atoms to operate inside open webpages. In the specific, the Atoms cover scenarios where the "native" PhantomJS require('webpage') don't stretch.

Documentation about how those work can be found here and here.

How are those Atoms making their way into GhostDriver? If you look inside the /tools directory you can find a bash script: /tools/import_atoms.sh. That script accepts the path to a Selenium local repo, runs the CrazyFunBuild to produce the compressed/minified Atoms, grabs those and copies them over to the /src/third_party/webdriver-atoms directory.

The Atoms original source lives inside the Selenium repo in the subtree of /javascript. To understand how the build works, you need to spend a bit of time reading about CrazyFunBuild: worth your time if you want to contribute to GhostDriver (or any WebDriver, as a matter of fact).

One thing it's important to mention, is that CrazyFunBuild relies on the content of build.desc file to understand what and how to build it. Those files define what exactly is built and what it depends on. In the case of the Atoms, the word "build" means "run Google Closure Compiler over a set of files and compress functions into Atoms". The definition of the Atoms that GhostDriver uses lives at /tools/atoms_build_dir/build.desc.

Let's take this small portion of our build.desc:

js_library(name = "deps",
  srcs = "*.js",
  deps = ["//javascript/atoms:deps",
          "//javascript/webdriver/atoms:deps"])

js_fragment(name = "get_element_from_cache",
  module = "bot.inject.cache",
  function = "bot.inject.cache.getElement",
  deps = [ "//javascript/atoms:deps" ])

js_library(name = "build_atoms",
  deps = [
    ...
    "//javascript/webdriver/atoms:execute_script",
    ...
  ]

The first part (js_library(name = "deps"...) declares what are the dependency of this build.desc: with that CrazyFunBuild knows what to build before fulfilling our build.

The second part (js_fragment(...) defines an Atom: the get_element_from_cache is going to be the name of an Atom to build; it can be found in the module bot.inject.cache and is realised by the function named bot.inject.cache.getElement.

The third part (js_library(name = "build_atoms"...) is a list of the Atoms (either defined by something like the second part or in one of the files we declared as dependency) that we want to build.

If you reached this stage in understanding the Atoms, you are ready to go further by yourself.

Contributions and/or Bug Report

You can contribute by testing GhostDriver, reporting bugs and issues, or submitting Pull Requests. Any help is welcome, but bear in mind the following base principles:

  • Issue reporting requires a reproducible example, otherwise will most probably be closed without warning
  • Squash your commits by theme: I prefer a clean, readable log
  • Maintain consistency with the code-style you are surrounded by
  • If you are going to make a big, substantial change, let's discuss it first
  • I HATE CoffeeScript: assume I'm going to laugh off any "contribution" that contains such aberrational crap!
  • Open Source is NOT a democracy (and I mean it!)

License

GhostDriver is distributed under BSD License.

FOSSA Status

Release names

See here.