...

/

The Capybara API: Querying

The Capybara API: Querying

Learn about capybara testing, capybara queries, HTML attributes in capybara queries, minitest assertions and capybara screenshots.

Capybara has a few methods designed to query the simulated browser page to check for various selector patterns in the page. This is one case where the syntax differs slightly between Minitest and RSpec.

Capybara testing

Here the method current_url is used, which returns as a complete string the current URL that the simulated user is viewing. That’s useful for testing whether the navigation links take us where they should.

The most common query method in Capybara is written as the matcher have_selector in RSpec, and as assert_selector in Minitest. The two are identical in functionality. By default, Capybara looks for a CSS selector matching the argument to the query method, using the common # shortcut for DOM ID and a dot (.) for DOM class. The assertion passes if the selector is found.

Capybara queries

The Capybara query methods, ...