尝试在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在本地构建并添加到PATH中。如何让ruby找到phantomjs?
答案 0 :(得分:30)
您也可以
$ sudo apt-get install phantomjs
这应该会自动将phantomj添加到您的路径中,并执行其正确运行所需的一切。这对我有用。
答案 1 :(得分:30)
不要在本地构建,而是使用brew install phantomjs
在Mac上使用自制软件,然后将链接所有路径。我自己有这个错误,你可以免费获得链接,并且能够轻松更新。
答案 2 :(得分:15)
对于Mac Os El Capitan
,请使用以下命令:
npm install -g phantomjs
以上命令仅在您安装npm
时才有效,用于安装npm
:
brew install npm
答案 3 :(得分:8)
添加到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
答案 4 :(得分:4)
显然,解决方案是将phantomjs不仅添加到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二进制文件的路径。
答案 5 :(得分:0)
其他可能的解决方案是向文件添加可执行权限:
# 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
并且poltergeist不建议使用官方Ubuntu回购中的phantomjs
:
不要使用官方Ubuntu存储库中的phantomjs,因为它 对于恶作剧者来说,它并不适合。