[英]Heroku rake task with poltergeist
我正在編寫一個測試應用程序的rake任務。 要測試它,我需要Capybara和Poltergeist。 耙任務如下所示:
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
此代碼檢查來自解析數據的主站點是否仍然相同(css選擇器中沒有更改)。 這個rake任務在本地運行良好,但是當我將其推送到heroku時,我遇到了一個錯誤:
rake aborted!
Cliver::Dependency::NotFound: Could not find an executable ["phantomjs"] on your path.
我用谷歌搜索了一下,安裝了phantomJS但仍然出現相同的錯誤(使用phantomJS的Poltergeist)。 有可能解決我的問題嗎?
您需要在您的Heroku實例上安裝PhantomJS。 通常這涉及添加將為您安裝的構建包,例如https://github.com/stomita/heroku-buildpack-phantomjs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.