如何在生产模式下的本地主机上运行Capybara / Poltergeist?

问题描述 投票:0回答:0

试图在Jenkins构建上进行一些无用的UI冒烟测试。 看起来Poltergeist将是必经之路,但是我很难让驾驶员拿走任何内容。

当前的策略是编译所有资产,就像将要进行生产部署一样。

第一步:进行“本地生产部署”

bundle install --deployment --retry=3
npm install
cd client # where all React.js code lives
node_modules/.bin/webpack -b --config webpack.production.config
cd ..
bundle exec rake assets:precompile RAILS_ENV=production
mkdir -p public/images;
cp -R app/assets/images/* public/images/

第二步:在生产模式下运行localhost:3000

RAILS_ENV=production bundle exec rails s
=> Rails 4.2.6 application starting in production on http://localhost:3000

第三步:运行指向localhost:3000的冒烟测试

bundle exec rspec spec/features

这是我对水豚/ poltergeist极其琐碎的测试示例:

require "rails_helper"

Capybara.javascript_driver = :poltergeist
Capybara.run_server = false
Capybara.app_host = "http://localhost:3000"

RSpec.describe "FooBar copyright", js: true do
  context "when on the homepage" do
    it "displays 'All rights reserved'" do
      Rails.env = "production"
      page.visit "/"
      expect(page).to have_content "All rights reserved"
    end
  end
end

您可能会认为这行得通……但事实并非如此。 测试失败,因为它们没有拾取任何内容。 我已经进行了一些调试,并且Rails.env是正确的,并且current_url也已正确设置为localhost:3000

在浏览器中手动转到localhost:3000可以正常工作。 资产正在正确编译。

出于某种原因,水豚/ poltergeist根本不选择内容。 得到这个错误:

 Failure/Error: expect(page).to have_content "All rights reserved"
   expected to find text "All rights reserved" in ""

感谢任何帮助!

ruby-on-rails jenkins capybara poltergeist
© www.soinside.com 2019 - 2024. All rights reserved.