Running PhantomJS in Vagrant

Some time ago I came across a weird error when trying to run RSpec test suite involving PhantomJS in Vagrant. Here’s the solution.

The error in question is:

The detector #{@detector} failed to detect the version of the executable at '#{executable_path}

Here is the snipped of the failures:

139.3) Failure/Error:
                raw_version || raise(ArgumentError,
                                     "The detector #{@detector} failed to detect the" +
                                     "version of the executable at '#{executable_path}'")

              ArgumentError:
                The detector <struct Cliver::Detector command_arg=nil, version_pattern=nil> failed to detect theversion of the executable at '/usr/bin/phantomjs'


140) Document details management when visiting index secret_admin can see it
       Got 0 failures and 3 other errors:

       140.1) Failure/Error: visit new_user_session_path

              ArgumentError:
                The detector <struct Cliver::Detector command_arg=nil, version_pattern=nil> failed to detect theversion of the executable at '/usr/bin/phantomjs'

What helped me to fix it in the end was setting the QT_QPA_PLATFORM variable to offscreen:

vagrant$ QT_QPA_PLATFORM=offscreen rspec

You should also be able to pass the -platform offscreen option to the PhantomJS executable.

← BUY THE PRE-RELEASE

I am writing a complete guide on web application deployment. Ruby with Puma, Python with Gunicorn, NGINX, PostgreSQL, Redis, networking, processes, systemd, backups, and all your usual suspects. 23 chapters and 3 scripted demonstrations already available.

More →