Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find phantomjs

Getting the following error when trying to use phantomjs from ruby on Ubuntu:

 Failure/Error: visit root_path
 Cliver::Dependency::NotFound:
   Could not find an executable ["phantomjs"] on your path.
 # ./spec/features/search_spec.rb:17:in `block (2 levels) in <top (required)>'
 # ./spec/support/vcr.rb:23:in `block (3 levels) in <top (required)>'
 # ./spec/support/vcr.rb:23:in `block (2 levels) in <top (required)>'

phantomjs was built locally and added to PATH. How do I make ruby find phantomjs?

like image 614
Sergey Evstifeev Avatar asked Jun 08 '15 07:06

Sergey Evstifeev


People also ask

What is the use of PhantomJS?

PhantomJS is a discontinued headless browser used for automating web page interaction. PhantomJS provides a JavaScript API enabling automated navigation, screenshots, user behavior and assertions making it a common tool used to run browser-based unit tests in a headless system like a continuous integration environment.


5 Answers

Instead of building locally, use homebrew on your mac with brew install phantomjs and all the paths will link after. I had this error myself, and you'll get the links for free and have the ability to update easily.

like image 174
pjammer Avatar answered Nov 02 '22 21:11

pjammer


You can also do

$ sudo apt-get install phantomjs                               

That should automatically add phantomjs to your path, and do everything else necessary for it to run correctly. This worked for me.

like image 41
Matthew Avatar answered Nov 02 '22 22:11

Matthew


For Mac Os El Capitan use following command:

npm install -g phantomjs

Above command only works if you have installed npm, for installing npm:

 brew install npm
like image 31
Aamir Avatar answered Nov 02 '22 21:11

Aamir


add to Gemfile

gem 'phantomjs', :require => 'phantomjs/poltergeist'

or put code below to spec_helper.rb

require 'phantomjs' 
Capybara.register_driver :poltergeist do |app|
    Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path)
end

https://github.com/colszowka/phantomjs-gem

like image 38
gayavat Avatar answered Nov 02 '22 22:11

gayavat


Apparently, the solution was to add phantomjs not only to the PATH, but also create links:

sudo ln -s /home/myuser/phantomjs/bin/phantomjs /usr/bin/phantomjs
sudo ln -s /home/myuser/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /home/myuser/phantomjs/bin/phantomjs /usr/local/share/phantomjs

Adjust the /home/myuser/phantomjs/bin/phantomjs paths to match the path to phantomjs binary on your machine.

like image 42
Sergey Evstifeev Avatar answered Nov 02 '22 20:11

Sergey Evstifeev