简体   繁体   English

Heroku与Poltergeist的佣金任务

[英]Heroku rake task with poltergeist

I'm writing a rake task which tests an application. 我正在编写一个测试应用程序的rake任务。 To test it I need Capybara and Poltergeist. 要测试它,我需要Capybara和Poltergeist。 Rake task looks like this: 耙任务如下所示:

require "capybara"
require "capybara/poltergeist"
require "capybara/dsl"

namespace :almet do
  desc "Checking if something changed on tatar.ru"
  task check_news: :environment do
    Capybara.current_driver = :poltergeist
    Browser = Class.new { include Capybara::DSL }
    page = Browser.new.page
    page.visit("http://almetyevsk.tatar.ru")
    unless page.has_selector?(".home-events ul li") &
       page.has_selector?(".home-events__item-lead") &
       page.has_selector?(".home-events__item-date") &
       page.has_selector?("h2 a")
    then
       alert
    end
    news_link = page.find(:css, "h2 a", match: :first)[:href]
    page.visit(news_link)
    unless page.has_selector?(".page__content-i h2") &
       page.has_selector?(".page__content-i .news") &
       page.has_selector?("i")
    then
       alert
    end
  end

  def alert
    AlertMailer.alert.deliver_now
  end
end

This code checks if the main site from parsing data is still the same (no changes in css selectors). 此代码检查来自解析数据的主站点是否仍然相同(css选择器中没有更改)。 This rake task works good locally, but when I pushed it to heroku I've got an error: 这个rake任务在本地运行良好,但是当我将其推送到heroku时,我遇到了一个错误:

rake aborted!
Cliver::Dependency::NotFound: Could not find an executable ["phantomjs"] on your path.

I googled this, installed phantomJS but still got the same error.(Poltergeist using phantomJS). 我用谷歌搜索了一下,安装了phantomJS但仍然出现相同的错误(使用phantomJS的Poltergeist)。 Is it possible to solve my problem? 有可能解决我的问题吗?

You need to install PhantomJS onto your Heroku instance. 您需要在您的Heroku实例上安装PhantomJS。 Usually that involves adding a build pack which will install it for you, like https://github.com/stomita/heroku-buildpack-phantomjs 通常这涉及添加将为您安装的构建包,例如https://github.com/stomita/heroku-buildpack-phantomjs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM