I'm refactoring my integration specs to use a page objects pattern. I'm testing a JS application with no database. I'm using poltergest.
When I abstract out my selectors into a page object, my tests slow down considerably.
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
This outputs:
0.030000 0.010000 0.040000 ( 2.051050)
0.000000 0.000000 0.000000 ( 0.000008)
As you can see, the first result is much slower than the second and the tests are basically the same except the page object abstraction.
My spec_helper is:
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
How would I trace this down? What is the cause?
It has nothing to do with the page model:
puts Benchmark.measure { has_css?('.results') }
puts Benchmark.measure { have_css('.results') }
Returns
0.030000 0.010000 0.040000 ( 2.005658)
0.000000 0.000000 0.000000 ( 0.000008)
So, the has_css? have_css methods are quite different.
For has_css?
, Capybara is waiting for the timeout to expire.