Performance 水豚与页面模型是非常缓慢的
我正在重构我的集成规范,以使用页面对象模式。我正在测试一个没有数据库的JS应用程序。我用的是poltergest 当我把选择器抽象成一个页面对象时,我的测试速度会大大降低Performance 水豚与页面模型是非常缓慢的,performance,rspec,capybara,poltergeist,Performance,Rspec,Capybara,Poltergeist,我正在重构我的集成规范,以使用页面对象模式。我正在测试一个没有数据库的JS应用程序。我用的是poltergest 当我把选择器抽象成一个页面对象时,我的测试速度会大大降低 require 'benchmark' class HostsPage include Capybara::DSL def has_search_results? has_css?('.results') end end feature 'blaa blaa' do let(:host) { Ho
require 'benchmark'
class HostsPage
include Capybara::DSL
def has_search_results?
has_css?('.results')
end
end
feature 'blaa blaa' do
let(:host) { HostsPage.new }
before do
visit('/')
click_link 'Query Hosts'
end
scenario 'User does something' do
puts Benchmark.measure { host.has_search_results? }
puts Benchmark.measure { have_css('.results') }
skip
end
end
这将产生:
0.030000 0.010000 0.040000 ( 2.051050)
0.000000 0.000000 0.000000 ( 0.000008)
如您所见,第一个结果比第二个结果慢得多,除了页面对象抽象之外,测试基本相同
我的spec_助手是:
require 'capybara/rspec'
require 'capybara/poltergeist'
Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f| require f }
RSpec.configure do |config|
config.order = :random
config.warnings = false
Capybara.default_driver = :poltergeist
Capybara.app = App.new # this points to a basic Sinatra app that serves index.html
end
我怎样才能找到这个?原因是什么?与页面模型无关:
puts Benchmark.measure { has_css?('.results') }
puts Benchmark.measure { have_css('.results') }
返回
0.030000 0.010000 0.040000 ( 2.005658)
0.000000 0.000000 0.000000 ( 0.000008)
那么,你有什么想法?have_css方法完全不同
对于有css?
,水豚正在等待超时过期