Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If JavaScript appears not to run in a Capybara test using Poltergeist, first verify that Capybara is actually using Poltergeist and that it can find a compatible PhantomJS executable. Then enable JavaScript error reporting and inspect the failing page. If the application uses unsupported ES6 syntax such as let or const, waiting longer will not fix it: transpile the code, use a suitable polyfill for a missing API, or move the test to a modern browser driver. Poltergeist has been archived since November 27, 2020, so recurring engine problems are a reason to plan a migration.

Confirm that Capybara is running Poltergeist

A test can be labeled as a JavaScript test without actually using the intended driver. Check the test setup for all three pieces: the Poltergeist gem, its Capybara integration, and the JavaScript-driver assignment. Also verify that the PhantomJS executable is available to the process running the tests.

Check the gem, require, and driver setting

For an older Ruby application that still uses this stack, the basic setup is:

# Gemfile
gem 'capybara'
gem 'poltergeist'
# spec/support/capybara.rb, or the equivalent test setup file
require 'capybara/poltergeist'

Capybara.javascript_driver = :poltergeist

Keep the Poltergeist require in the test process’s setup path, not only in application code that may not be loaded by the test runner. If your project already has a driver registration or custom configuration, inspect that registration too; a later assignment or per-test driver choice may override the global setting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Capybara Hacker - Funny Coding Programming Capybara Hardcover Journal, Black
  • Awesome design - the perfect statement piece for anyone who wants to show their love for Code, Capybaras and funny humor. With its retro design and funny expression, it is sure to turn heads and start conversations.
  • Looking for unique and memorable gifts for women, kids or men? This eye-catching vintage design is the perfect choice! Great gifts for colleagues, friends and family.
  • Hardcover journal with 240 line-ruled pages (120 sheets)
  • Built-in elastic closure and ribbon bookmark
  • Includes an expandable inner storage pocket and a pen holder

Check the PhantomJS executable

Poltergeist controls PhantomJS as a separate executable. Run which phantomjs in the same environment where the tests run, then run phantomjs --version. If the command is absent, unavailable to the test process, or points to a different binary than expected, fix the executable path or installation before debugging page JavaScript.

On Linux, do not assume the distribution package is suitable: Poltergeist’s README specifically warns against the PhantomJS package from the official Ubuntu repositories because it does not work well with Poltergeist. Use a binary compatible with the Poltergeist version and environment instead. No single current PhantomJS version is established as compatible with every legacy project, so record the actual versions rather than copying an unverified version pin.

Make JavaScript errors visible

A page exception can otherwise look like an element that never appeared, an assertion that timed out, or a click that did nothing. Enable Poltergeist’s JavaScript error reporting so errors in the page are raised in the test output. For example, register a debugging driver explicitly:

Capybara.register_driver :poltergeist_debug do |app|
  Capybara::Poltergeist::Driver.new(app, js_errors: true, debug: true)
end

Capybara.javascript_driver = :poltergeist_debug

If the project already registers Poltergeist, add js_errors: true and debug: true to that registration rather than creating a second driver unnecessarily. Poltergeist options may be written with symbol keys or older hash-rocket syntax depending on the Ruby version; use the syntax accepted by the project’s Ruby. If turning on both settings changes the reported failure, separate them and retry with one setting at a time.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Capture evidence at the failing step

Save a screenshot close to the point where the page diverges from expectation. In a Capybara test, save_screenshot can capture the current page:

Rank #2
6pcs Capybara Magnetic Bookmarks - Cute Book Markers Clip for Reading Women, Capybara Fun Magnet Page Markers for Book Lovers Reader Men Boys Girls, Funny Capybara Gifts for Teachers Students
  • Cute bookmarks for Book Lovers:You'll receive 6pcs different capybara bookmarks, which are interesting gifts for Capibala lovers. These cute bookmarks make the perfect gift for capybara fans and bookworms alike. With their charming designs, this book mark add a touch of fun to reading, keeping your place in style. Great for kids and avid readers, they turn reading into a more enjoyable and engaging experience.
  • Capybara Themes Magnetic Bookmarks: These capybara theme bookmarks feature 6 kinds of funny Capibala designs, making them a fun gift for students, adults, pet lovers, and anyone who enjoys reading. These funny Capibala animal bookmarks are the perfect gift for bookworms and Capibala enthusiasts. With these cute bookmarks accompanying reading, you will love reading even more, making reading a more enjoyable and enjoyable thing.
  • Double-sided Magnet: The magnetic bookmarks for book lovers is made of high quality coated paper and magnetic material, reliable and durable, clear printing, not easy to fade or break, supports long time use, easy to use and store. Each book marks for reading women is machine-cut and colored to ensure a proper finish that lasts through countless readings. The bookmarkers are strong magnets, they have a strong hold on the page but they don't rip the page either.
  • Easy To Use: Each magnetic bookmarks are lightweight and portable, making them easy to take anywhere. Simply place them on your page and fold the magnets together—they’ll stay secure without slipping out. Plus, they’re designed for a smooth, hassle-free reading experience. Be careful not to clip too thick paper, as it can also affect the magnetic force and damage the book.
  • Exquisite Gifts: These Capybara magnetic book markers are as cute as they are practical! Their playful designs will bring a smile to any book lover’s face—perfect for classmates, friends, kids, teachers, or as reading rewards for students. This funny bookmark can be used as a gift for various holidays, such as Mother's Day, Father's Day, Children's Day, Halloween, Christmas. And if you’re a capybara fan, you'll especially love these charming capybara party favors bookmarks for your books.
save_screenshot('tmp/capybara-failure.png')

Keep the screenshot with the test log. It can reveal a consent overlay, a page that never loaded, a wrong viewport, a font or layout issue, or a control positioned differently than the test assumes. Poltergeist debug output can also report click coordinates, which helps distinguish a JavaScript failure from a target being covered or out of place.

For a reproducible failure, collect the Poltergeist and PhantomJS versions, operating system, complete stack trace, relevant browser-console output, the screenshot, and the smallest set of steps or test code that triggers the issue. This is especially useful for failures that occur only in CI or only intermittently.

Check whether PhantomJS can parse the application’s JavaScript

PhantomJS uses an old WebKit-based browser engine, not a current Chrome or Firefox engine. Poltergeist’s README says PhantomJS does not support ES6 features and specifically identifies let and const as possible silent failure points. A bundle that works in a current browser can therefore fail before Capybara has a chance to find the elements it expects.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Identify syntax and API compatibility separately

  • Syntax failure: If PhantomJS cannot parse the script, the application may stop initializing. Transpile the test bundle to syntax the engine understands, then rerun the failing case with JavaScript errors enabled.
  • Missing browser API: If the syntax parses but the code calls an API PhantomJS lacks, add a compatible polyfill through Poltergeist’s extensions option where that is practical.
  • Engine-dependent behavior: If the application depends on browser behavior that cannot be reproduced reliably in this engine, use a modern browser driver instead of accumulating patches.

Do not treat a longer Capybara wait as a remedy for a parse error or absent browser feature. A wait can help only when the application is still functioning and the expected state arrives later.

Separate asynchronous timing from failed JavaScript

Capybara retries many failed asynchronous lookups while waiting for the page to reach the requested state. Its documented default_max_wait_time is two seconds. When a legitimate client-side operation takes longer, raise the setting deliberately, preferably for the relevant test or suite, and assert the state the user would observe.

# In the test configuration, if this application legitimately needs more time:
Capybara.default_max_wait_time = 5

# Prefer an eventual-state assertion over a fixed sleep:
expect(page).to have_css('.results-loaded')

The five-second value above is an example project choice, not a universal requirement. Start with the observed delay and keep the timeout bounded; an inflated timeout can make real failures slow and obscure whether the page is progressing.

Avoid inserting arbitrary sleep calls as the default fix. Fixed sleeps waste time when the page is fast and still fail when it is slower than the chosen delay. First confirm that the script ran without errors; then wait for an observable state, such as a result element or updated text.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the right script-evaluation method

Use execute_script for JavaScript whose purpose is a side effect and whose return value is not needed. Use evaluate_script when the test needs a returned value, but keep the returned data simple: the representation of complex objects can vary by driver.

# Side effect only
page.execute_script("document.body.setAttribute('data-test-ready', 'true')")

# Simple returned value
ready = page.evaluate_script("document.body.getAttribute('data-test-ready')")

If a script call appears to fail, reduce it to a small expression and inspect the browser-side error output. Do not infer that the application bundle executed successfully merely because Capybara can evaluate a short, independent expression.

Diagnose clicks that appear to do nothing

Poltergeist performs coordinate-based, user-like clicks. A click can miss when an overlay covers the target, the page has not finished laying out, or the element is outside the expected position. Inspect a screenshot and the debug output before changing the test to force a click.

Rank #4
Sale
Cute Capybara Reading Books Funny Animal Capybara Bookworms T-Shirt
  • With capybara with glasses reading on design That includes illustrations.
  • This is a Great Design idea for Bookworms and students who love to read.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem
  • If a consent banner or modal covers the control, dismiss it or set up the page state the test actually intends to exercise.
  • If the element is not visible or is displaced, fix the page timing, viewport, or layout condition before clicking.
  • Use find_button('Save').trigger('click') only when dispatching a DOM event is the deliberate test intent. It does not verify that a user could physically reach and click the control.

Handle timeouts, DeadClient errors, and crashes

A timeout may mean the page is genuinely slow, the application script stopped on unsupported syntax, the selected driver is wrong, or PhantomJS itself has failed. Use the preceding checks to narrow the cause before changing timeouts. For a DeadClient error or other process crash, determine whether the failure reproduces consistently, preserve the stack trace, and record the OS and both driver and browser versions. A sporadic crash may be related to the old WebKit embedded in PhantomJS; repeated blind retries do not address that underlying risk.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the test creates a Capybara session manually rather than relying on normal test cleanup, quit the driver when finished to avoid leaving PhantomJS processes and consuming memory:

session.driver.quit

When the problem is isolated and reproducible, a focused issue report with a minimal example and the captured environment details is more useful than a report that only says JavaScript failed.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose between a patch and migration

Poltergeist’s repository has been archived and made read-only since November 27, 2020. Current Capybara documentation says JavaScript tests need a different driver and documents Selenium-based options. The practical choice depends on whether this is a short-lived legacy suite or a test suite that must keep tracking a modern application.

Option Addresses Trade-off
Enable errors, debug logs, and screenshots Hidden page exceptions, uncertain page state, and hard-to-reproduce failures Improves diagnosis but does not update PhantomJS’s engine.
Transpile syntax or add a polyfill A known syntax or missing-API incompatibility Can preserve a legacy stack, but retains old engine limits and adds compatibility maintenance.
Increase Capybara’s wait time A legitimately slow asynchronous update Helps synchronization only; it cannot fix an exception, parse failure, or crashed browser.
Move to a maintained Selenium-compatible driver Recurring incompatibility with the legacy browser engine Requires browser and driver setup, but provides a durable path for modern browser behavior.

For a short-term stabilization, first expose errors and establish whether the problem is syntax, an API, timing, or a click target. For an actively maintained application, recurring PhantomJS-only failures are a strong migration signal. Plan the new driver and browser in local development and CI, then move tests in a controlled sequence rather than assuming that a larger timeout will make the old engine current.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
InnoBeta Capybara Gifts for Capybara Lover, 7.8"x5" Embossed Refillable Notebook/Journal with Pen
  • Ideal Gift - This easy-to-carry and versatile journal book will be an excellent gift on Christmas, Birthday, etc to convey your best wishes.
  • Refined Design - Unique appearance, soft texture, easy to carry around. This journal book is suitable for home, office, outdoor adventure, and travel, etc. A classic cover ensures well protection. In addition, it comes with a strap to ensure that the paper and accessories will not be scattered.
  • Perfect size - 7.8" × 5" (20 cm * 12.5 cm) and has 70 sheets (140 pages), perfect for carrying and writing. It can be easily put into a pocket, backpack, or purse, and travel anytime, anywhere. This travel journal is also very suitable for use as bullet journals, daily planners, logbooks, food planners, artist sketchbooks, drawing, sketching, paintings, etc.
  • Multifunctional - Designed for easier reading and notes taking. It would be the perfect handy choice for you during daily uses, journeys, and work. Card slot bags are also included to organize your cards, tickets, photos, etc. And also a page-size slot with zipping for storing cash, cell phone, and more.
  • Nice Gifts - Surprise your friends, families, and colleagues with this journal!

Or skip the browser setup

If the task is to capture a page image or PDF rather than exercise Capybara interactions, ScreenshotNeo is an alternative to try first: it returns a screenshot or PDF from a single API request. It is not a substitute for an end-to-end test that clicks controls and asserts application behavior.

For example, capture a page as WebP with cURL (see the ScreenshotNeo API documentation):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

The same one-request pattern in Python is:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

In Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Every feature is on every plan. See ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Can I use Poltergeist to test JavaScript in Capybara today?

You can retain it in a legacy project if its dependencies and PhantomJS executable still work in your environment, but the archived project and old browser engine make it a poor default for new or modern-browser coverage.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does ScreenshotNeo run my Capybara test suite?

No. It captures a webpage through an API or MCP tool; it does not replace a Capybara driver for clicking through an application and asserting interactive behavior.

Quick Recap

Bestseller No. 1
Capybara Hacker - Funny Coding Programming Capybara Hardcover Journal, Black
Capybara Hacker - Funny Coding Programming Capybara Hardcover Journal, Black
Hardcover journal with 240 line-ruled pages (120 sheets); Built-in elastic closure and ribbon bookmark
$16.99
Bestseller No. 3
SaleBestseller No. 4
Cute Capybara Reading Books Funny Animal Capybara Bookworms T-Shirt
Cute Capybara Reading Books Funny Animal Capybara Bookworms T-Shirt
With capybara with glasses reading on design That includes illustrations.; This is a Great Design idea for Bookworms and students who love to read.
$14.44
Bestseller No. 5
InnoBeta Capybara Gifts for Capybara Lover, 7.8'x5' Embossed Refillable Notebook/Journal with Pen
InnoBeta Capybara Gifts for Capybara Lover, 7.8"x5" Embossed Refillable Notebook/Journal with Pen
Nice Gifts - Surprise your friends, families, and colleagues with this journal!
$17.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.