• Stars
    star
    210
  • Rank 187,585 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Capybara::SlowFinderErrors

Raises an error when you use a capybara finder and it times out.

The goal of this gem is to aid in discovering errors in capybara usage to help speed up your test suite.

Example

If you do:

refute page.has_content?("An Error Occurred")

To make sure there's no error on the page, the full timeout will be reached because has_content? waits for the content to appear. The correct usage is:

assert page.has_no_content?("An Error Occurred")

Which would evaluate quickly.

This gem will raise a Capybara::SlowFinderError whenever the first situation occurs. In fact, it raises the error any time a Capybara synchronized piece of code reaches a timeout.

Installation

Add this line to your application's Gemfile:

gem 'capybara-slow_finder_errors'

And then execute:

$ bundle

Or install it yourself as:

$ gem install capybara-slow_finder_errors

Usage

Run your test suite as usual. If you have any slow finders, you'll get a stack trace like this:

Capybara::SlowFinderError (Capybara::SlowFinderError)
/path/to/capybara-slow_finder_errors/lib/capybara/slow_finder_errors.rb:11:in `rescue in synchronize_with_timeout_error'
/path/to/capybara-slow_finder_errors/lib/capybara/slow_finder_errors.rb:7:in `synchronize_with_timeout_error'
./features/support/signed_in_user.rb:31:in `signed_in?'
./features/support/user_helper.rb:59:in `sign_in_as'
features/configuring_a_project.feature:6:in `Given I am signed in as "[email protected]"'

execution expired (Timeout::Error)
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/web_socket_server.rb:72:in `select'
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/web_socket_server.rb:72:in `receive'
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/web_socket_server.rb:85:in `send'
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/server.rb:33:in `send'
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/browser.rb:270:in `command'
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/browser.rb:106:in `evaluate'
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/driver.rb:130:in `evaluate_script'
/path/to/.gems/gems/capybara-2.4.4/lib/capybara/session.rb:527:in `evaluate_script'
...

If you look at the lines below the gem's trace, you'll see that the slow finder is in signed_in_user.rb on line 31 in the signed_in? method. Just follow those traces and clean up your code!

RSpec

If you're using RSpec and the matchers provided by Capybara like:

expect(page).to_not have_content("abc")

then Capybara is already telling RSpec to use the negated method (has_no_content?) and thus Capybara is not waiting for the timeout before continuing.

Common Fixes

This section will hopefully grow as people contribute common situations and fixes.

Inverted Finder

Replace refute page.has_content?("abc") with assert page.has_no_content?("abc").

Boolean Finder

A method that returns a boolean shouldn't use a waiting finder. So:

def signed_in?
  page.has_content?("Sign out")
end

Returns true if they are signed in, but it waits a full timeout before returning false. Instead, perform a waiting finder for content that is always present (to ensure the page is loaded) then use a quick finder that doesn't wait:

def signed_in?
  page.has_content?("Dashboard")
  page.has_css?('a', :text => 'Home', :wait => false)
end

Contributing

  1. Fork it https://github.com/ngauthier/capybara-slow_finder_errors/fork
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

More Repositories

1

tubesock

Websocket interface on Rack Hijack w/ Rails support
Ruby
623
star
2

hydra

Distributed testing framework
JavaScript
390
star
3

domino

View abstraction for integration testing
Ruby
94
star
4

sock-chat

Demo of Tubesock and Redis for threaded chatting
Ruby
56
star
5

intro-to-backbone-js

JavaScript
52
star
6

knowsql

SQL Tips and Tricks - Presentation and Benchmarks
Ruby
34
star
7

postgis-on-rails-example

http://ngauthier.com/2013/08/postgis-and-rails-a-simple-approach.html
Ruby
24
star
8

slow-actions

Inspect a rails application's log file to find slow actions
Ruby
23
star
9

hubot-github-heroku-deploy

Deploy from Github to Heroku with Hubot
Shell
21
star
10

nicks-toolbox

A collection of helpful scripts
Python
11
star
11

backbone-presentation

JavaScript
10
star
12

domino_rspec

example of using domino with rspec
Ruby
10
star
13

preact-ssr-demo

TypeScript
8
star
14

Grease-Your-Suite

Tips and tricks for faster testing
Ruby
8
star
15

find_or_redirect

Refactor finder code in controllers
Ruby
7
star
16

minitest-parallel

Run MiniTest suites in parallel
Ruby
6
star
17

view-abstraction-demo

Integration Test View Abstraction Demo
Ruby
6
star
18

jslintrb-v8

jslint bindings for ruby in v8
JavaScript
6
star
19

capybara-jasmine

Run Jasmine Tests via Capybara
JavaScript
6
star
20

forque

Make forking easy in ruby
Ruby
6
star
21

aptinstaller

Automatically install a project's dependencies via apt-get
Ruby
5
star
22

multitest

Run your ruby tests in parallel
Ruby
5
star
23

quick_menu

Quickly turn a bunch of links into a javascript dropdown menu
Ruby
5
star
24

rack_attack

Ruby
4
star
25

testing-go-presentation

Go
4
star
26

watch_me

Watch multiple log files in a single terminal window
4
star
27

robust-tests

JumpstartLab Training Course on Robust Testing
Ruby
4
star
28

erlangies

exercises from erlangdc
Erlang
4
star
29

adv-rails-patterns

Advanced Rails Patterns presentation
Ruby
3
star
30

ngauthier.github.com

Nick Gauthier's Blog
JavaScript
3
star
31

test-pilot-demo

Demo of the TestPilot integration testing pattern
Ruby
3
star
32

rails_structure_loading

Generate and load SQL structure files for your migrations
Ruby
3
star
33

dot_chat

DOT to SVG
Ruby
3
star
34

active-listener

Event listening and firing system for ruby
Ruby
3
star
35

ruby-on-rails-polymorphism-benchmarks

Benchmarking tests of using RoR polymorphic relationships through strings versus integers, with and without indices.
Ruby
3
star
36

bpm

Bash Package Manager
Shell
2
star
37

tclub

JHU Tae Kwon Do Club Web Site
2
star
38

channel-fakes-post

Go
2
star
39

backbone-raphael-traer

Presentation on Backbone, Raphael, and Traer
JavaScript
2
star
40

minimal-go-containers-post

Go
2
star
41

compact_table

Table display plugin that allows you to hide specific HTML until the user requests it
Ruby
2
star
42

domino_example

Example Rails application using Domino
Ruby
2
star
43

ribs

A library of backbone.js extended classes
CoffeeScript
2
star
44

performance-testing

A guide to performance testing in rails
Ruby
2
star
45

smashingmag-mobile-ux

1
star
46

traffic_patterns

TODO: one-line summary of your gem
Ruby
1
star
47

hydra-console

Run tests repeatedly without booting your environment
Ruby
1
star
48

outside-in-demo

demo app for outside in testing talk
Ruby
1
star
49

six-ws-of-testing

A philosophical exploration of testing
Ruby
1
star
50

capybara-java_script_lint

Run JSLint on Rails JavaScript assets through the asset pipeline with Capybara Webkit
Ruby
1
star