【问题标题】:capybara: save_and_open_page. Error - no display specified Couldn't find a suitable web browser水豚:save_and_open_page。错误 - 未指定显示 找不到合适的网络浏览器
【发布时间】:2016-04-20 10:39:17
【问题描述】:

在测试文件中,capybara方法save_and_open_page显示错误:
错误:没有指定显示 找不到合适的网络浏览器! 将 BROWSER 环境变量设置为所需的浏览器。 警告:程序返回非零退出代码 #1 用火狐浏览器打开“/home/ubuntu/workspace/tmp/capybara/capybara-201604201009291019595495.html”(文本/html)

Error: no display specified
/usr/bin/xdg-open: 461: /usr/bin/xdg-open: links2: not found
/usr/bin/xdg-open: 461: /usr/bin/xdg-open: links: not found
/usr/bin/xdg-open: 461: /usr/bin/xdg-open: lynx: not found
/usr/bin/xdg-open: 461: /usr/bin/xdg-open: w3m: not found
xdg-open: no method available for opening '/home/ubuntu/workspace/tmp/capybara/capybara-201604201009291019595495.html'

宝石文件

group :development, :test do
  gem 'pry-rails'
  gem 'factory_girl_rails'
  gem 'rspec-rails'
  gem 'launchy'
end

group :development do
  gem 'better_errors'
  gem "letter_opener"
  gem 'byebug'
  gem 'pry-byebug'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'

  gem 'annotate'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]


group :production do
  gem 'rack-cache', :require => 'rack/cache'
end

group :test do
  gem 'shoulda-matchers'
  gem 'capybara'

end

如何设置浏览器的chrome?

【问题讨论】:

  • 在您的spec_helper.rb 中,您有类似Capybara.default_driver = :webkit 的内容吗?
  • 不,我没有这个

标签: ruby-on-rails rspec capybara rspec-rails


【解决方案1】:

xdg-open 命令在您的设置中没有配置默认浏览器。您可以通过以下方式验证这一点:

$ xdg-settings get default-web-browser
# (probably will not print anything)

要为xdg-open 设置默认浏览器,请运行:

$ xdg-settings set default-web-browser google-chrome.desktop

如果这没有帮助,请尝试搜索为 google chrome 定义的所有 .desktop 文件:

$ locate .desktop | grep chrome

选择其中一个并将其提供给上面的xdg-settings 命令(没有路径,只有带有.desktop 扩展名的文件名)。

您总是可以通过尝试从命令行打开链接来测试它:

$ xdg-open http://google.com

请参阅xdg-settings man page 了解更多信息。

【讨论】:

  • 我在命令行中调用 xdg-settings 获取 default-web-browser,显示错误:xdg-settings: unknown desktop environment
  • 那是什么操作系统?是否使用图形显示环境(如 X-windows)?
  • 还有什么图形桌面 - gnome、unity、KDE ​​或其他?
  • 嗯,再次查看您的确切错误,您似乎根本没有使用图形显示 - 您是从 ssh / 控制台调用测试吗?
  • 所以你没有图形环境?抱歉,那么您想如何使用 chrome 呢?在这种情况下,我只需安装一个纯文本浏览器,例如links2
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-23
  • 1970-01-01
  • 1970-01-01
  • 2011-06-18
  • 1970-01-01
  • 2019-06-19
  • 2014-02-18
相关资源
最近更新 更多