是否可以在 Heroku Cedar 上运行 capybara-webkit (即分叉的 webkit_server)?

发布于 2024-12-28 20:25:45 字数 515 浏览 1 评论 0原文

我需要在 Rails 应用程序中运行 capybara-webkit,以启用具有 JavaScript 支持的无头 Web 浏览(即不用于测试/CI 目的,并且 webrat 或其他验收测试驱动程序/框架将无法工作)。我想知道这在 Heroku 部署上是否可行,特别是因为它需要 QtWebKit 以及通过套接字通信分叉 webkit_server 进程的能力。我对如何在 Heroku 上实现这项工作的创意持开放态度(例如,工人测功机池)。我希望有人能够更好地处理 Heroku 环境中存在的限制,或者可以明确排除这种可能性,以便我可以在必要时转向 AWS EC2。

搜索此内容往往会发现很多有关水豚测试和 CI 服务器附加组件的信息,但这些都与我的用例无关。我没有测试任何东西(至少不是传统的黄瓜/rspec/等意义上的) - 我正在使用 Capybara 与 webkit 驱动程序、查找器和节点/元素模型的集成来导航需要大量客户端的网站 -方JS才能工作。

我还愿意接受其他(原生 Ruby)解决方案,以便使用支持 JavaScript 的 DOM 以编程方式与网站进行交互。

I need to run capybara-webkit inside a Rails application to enable headless web browsing with JavaScript support (i.e. not for testing/CI purposes, and webrat or other acceptance testing drivers/frameworks will not work). I'm wondering if this is possible on a Heroku deployment, specifically because it requires QtWebKit and the ability to fork the webkit_server process with socket communication. I'm open to creative ideas on how to make this work on Heroku (e.g. a pool of worker dynos). I'm hoping someone has a better handle on what constraints exist in the Heroku environment, or can categorically rule out the possibility so I can move on to AWS EC2 if necessary.

Searching for this tends to turn up a lot about capybara testing and add-ons for CI servers, neither of which are relevant for my use case. I'm not testing anything (at least not in the traditional cucumber/rspec/etc sense) - I'm using Capybara's integration with the webkit driver, finders and node/element model to navigate a website that requires a significant amount of client-side JS in order to work.

I'm also open to other (native Ruby) solutions for programmatically interacting with web sites using JavaScript-enabled DOM.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南巷近海 2025-01-04 20:25:45

我与 Heroku 支持人员讨论了这个问题,他们的回答是,这基本上是 a) 不受支持; b) 非常困难,包括(除其他外)静态构建的 QtWebKit 版本。

我自己在 Amazon EC2 上对此进行的调查也让我意识到 QtWebKit 需要 Xvfb 的运行实例。我非常怀疑这在 Heroku 上是否可用,并且我怀疑让它发挥作用将非常困难。

我自己的方法是将此功能放在 EC2 实例上。在对 Amazon 的标准 AMI(其构建和 RHEL)进行一些尝试后,我发现通过 Ubuntu 的包管理系统提供的包使得启动运行变得更加容易。

长话短说:Heroku 是不可能的,Amazon EC2 和 Ubuntu 是最好的选择。

I spoke to Heroku support about this and their answer was that this is basically a) unsupported; b) very difficult, including (among other things) a statically built version of QtWebKit.

My own investigation into this on Amazon EC2 also made me realize that QtWebKit requires a running instance of Xvfb. I highly doubt this would be available on Heroku, and I suspect it would be extremely difficult to make it work.

My own approach has been to put this functionality on an EC2 instance. After making some attempts with Amazon's standard AMIs (their build and RHEL), I found that the packages available through Ubuntu's package management systems made it MUCH easier to get up an running.

Long story short: Heroku is a non-starter, Amazon EC2 with Ubuntu is the best way to go.

两相知 2025-01-04 20:25:45

我能够在 Heroku 上成功运行 Capybara + Poltergeist + PhantomJS

我已将 OSX(针对我的开发机器)和 linux-64(针对 Heroku)的已编译 phantomjs 二进制文件放在 Rails 应用程序的 bin/ 文件夹中。

initializers/capybara.rb

require 'capybara/poltergeist'

Capybara.register_driver :poltergeist do |app|
  phantomjs_path = if RUBY_PLATFORM['x86_64-darwin']
                     Rails.root.join('bin', 'phantomjs-osx').to_s
                   elsif RUBY_PLATFORM['x86_64-linux']
                     Rails.root.join('bin', 'phantomjs-linux-64').to_s
                   else
                     raise "Can't load PhantomJS for OS: #{RUBY_PLATFORM}"
                   end

  options = {
      phantomjs: phantomjs_path,
      phantomjs_logger: Logger.new('/dev/null'),
      phantomjs_options: %w[--load-images=no --ignore-ssl-errors=yes],
      js_errors: false,
      timeout: 90
  }
  Capybara::Poltergeist::Driver.new(app, options)
end

Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
Capybara.default_wait_time = 1

示例代码:

session ||= Capybara::Session.new(:poltergeist)
session.visit('http://google.com')

祝你好运!

I was able to successfully run Capybara + Poltergeist + PhantomJS on Heroku

I've placed compiled phantomjs binaries for OSX (for my development machine) and linux-64 (for Heroku) in bin/ folder of my Rails application.

initializers/capybara.rb

require 'capybara/poltergeist'

Capybara.register_driver :poltergeist do |app|
  phantomjs_path = if RUBY_PLATFORM['x86_64-darwin']
                     Rails.root.join('bin', 'phantomjs-osx').to_s
                   elsif RUBY_PLATFORM['x86_64-linux']
                     Rails.root.join('bin', 'phantomjs-linux-64').to_s
                   else
                     raise "Can't load PhantomJS for OS: #{RUBY_PLATFORM}"
                   end

  options = {
      phantomjs: phantomjs_path,
      phantomjs_logger: Logger.new('/dev/null'),
      phantomjs_options: %w[--load-images=no --ignore-ssl-errors=yes],
      js_errors: false,
      timeout: 90
  }
  Capybara::Poltergeist::Driver.new(app, options)
end

Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
Capybara.default_wait_time = 1

Example code:

session ||= Capybara::Session.new(:poltergeist)
session.visit('http://google.com')

Good luck!

云仙小弟 2025-01-04 20:25:45

您也许可以使用 PhantomJS 来完成您想要的事情。

该项目有一个 JavaScript,而不是 Ruby API,尽管浏览器实例可以公开 Web 服务器,允许您通过 HTTP 从 Ruby 与其进行通信。

http://code.google.com/p/phantomjs/wiki/Interface

You may be able to accomplish what you want using PhantomJS.

This project has a JavaScript, rather than Ruby API, although the browser instance can expose a web-server, allowing you to communicate with it from Ruby over HTTP.

http://code.google.com/p/phantomjs/wiki/Interface

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文