簡體   English   中英

最小的Capybara / Poltergeist測試返回空頁

[英]Minimal Capybara / Poltergeist test returning empty page

看來我正在回顧SO帖子中所采取的步驟: Capybara,Poltergeist和Phantomjs,並在身體上做出空洞的反應 (如果需要,請將此標記為重復,但我包含一個最小的獨立測試用例和版本號。)

問題

我做了什么明顯錯誤的事嗎? 我可以運行另一個可以幫助隔離問題的最小測試嗎?

file:pgtest.rb
$ ruby pgtest.rb
<html><head></head><body></body></html>

當按如下方式調用時,它會打印一個空頁面:

 $ ruby pgtest.rb <html><head></head><body></body></html> 

環境

  • OS X 10.8.5(12F45)
  • ruby 2.0.0p247(2013-06-27)[x86_64-darwin12.4.0]
  • 幻影1.9.2
  • 水豚(2.1.0)
  • 惡作劇者(1.4.1)

絕對的幻影

值得注意的是,我可以使用phantomjs從www.google.com中提取html:

file:pjs_dump.js
 var page = require('webpage').create(); page.open("http://www.google.com", function () { var html = page.evaluate(function () { return document.documentElement.outerHTML; }); console.log(html); phantom.exit(); }); 

當我運行'phantomjs pjs_dump.js'時,它會從www.google.com打印html,因此phantomjs似乎正常工作。

這對我有用:

require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'

Capybara.run_server = false
Capybara.current_driver = :poltergeist

class PGTest
  include Capybara::DSL

  def test
    visit "http://www.google.com"
    puts page.body
  end
end

PGTest.new.test

在使用rspec,capybara和poltergeist測試rails應用程序時,我遇到了類似的問題。 當主體為空時嘗試查找元素時,規范失敗。

事實證明,問題出在我的rails代碼中。 它導致錯誤,頁面沒有渲染,並且水豚收到一個空頁面。 我沒有任何堆棧跟蹤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM