简体   繁体   中英

Heroku rake task with poltergeist

I'm writing a rake task which tests an application. To test it I need Capybara and 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). This rake task works good locally, but when I pushed it to heroku I've got an error:

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). Is it possible to solve my problem?

You need to install PhantomJS onto your Heroku instance. Usually that involves adding a build pack which will install it for you, like https://github.com/stomita/heroku-buildpack-phantomjs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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