We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
RailsConf 2023 - Teaching Capybara Testing - An Illustrated Adventure by Brandon Weaver
Teaching Capybara testing in an illustrated adventure, covering its limitations, and best practices for writing effective tests with a focus on accessibility and debugging.
- Test suites are not about providing 100% coverage, but about proving that the application works as expected
- Capybara is brittle and can be sensitive to changes in the application’s HTML structure
- Using semantic HTML and ARIA properties can make the application more accessible and easier to test
- The first part of the test is to set up the driver and configuration
-
The
visit
method is used to navigate to a page and thewithin
method is used to constrain the scope of the query -
The
fill_in
method is used to fill in a form field and theclick_on
method is used to simulate a click on an element -
The
have_button
andhave_link
helpers are used to find elements on the page -
The
login
helper is used to authenticate to the site -
The
save_and_open_page
method is used to open the page in the default browser -
The
expectation
method is used to specify what should happen on a page -
The
have_selector
method is used to find a specific element on the page -
The
have_text
method is used to find text on the page -
The
have_content
method is used to find the content of an element -
The
with
method is used to constrain the scope of a query - Capybara can be used to test JavaScript-heavy applications, but it’s not always possible to test everything
- Debugging capybara tests can be challenging
- Tests should be written with the assumption that they will be run frequently
-
The
binding.pry
command is used to enter the Ruby console and inspect the state of the application -
The
visit
method is not always possible, especially when testing JavaScript-heavy applications - Capybara is not always the best tool for testing complex applications
-
The
save_and_open_page
method is not always necessary, especially when testing small applications - Capybara can be slow and resource-intensive if used improperly
- Tests should be written with the assumption that they will be run in a headless environment
-
The
headless
method is used to run the tests in a headless environment - Capybara can be used with various drivers, including WebKit, Firefox, and Google Chrome