在Ubuntu上尝试从ruby使用phantomjs时出现以下错误:
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在本地build立并添加到PATH。 如何让rubyfind幻影?
而不是在本地建立,使用brew install phantomjs
在您的Mac上使用自制软件,所有的路径将链接。 我自己有这个错误,你会得到免费的链接,并有能力更新容易。
你也可以做
$ sudo apt-get install phantomjs
这应该会自动将phantomjs添加到您的路径中,并执行其他所有必要的操作来正确运行。 这对我有效。
对于Mac Os El Capitan
使用以下命令:
npm install -g phantomjs
以上命令只有在安装了npm
下才能正常工作,用于安装npm
:
brew install npm
添加到Gemfile
gem 'phantomjs', :require => 'phantomjs/poltergeist'
或者把代码放在spec_helper.rb的下面
require 'phantomjs' Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path) end
显然,解决方案是不仅要将PATH添加到PATH,还要创建链接:
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
调整/home/myuser/phantomjs/bin/phantomjs
路径以将路径与机器上的phantomjs二进制文件相匹配。
其他可能的解决方案是将可执行权限添加到文件:
# download phantomjs $ curl --output /home/user/.rvm/bin/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1 # set rights $ chmod +x /home/user/.rvm/bin/phantomjs # check $ which phantomjs /home/user/.rvm/bin/phantomjs
另外, phantomjs
也不推荐使用官方Ubuntu回购版的phantomjs
:
不要使用官方的Ubuntu软件库中的phantomjs,因为它不适合poltergeist。