Writing a Browser-Driven System Test Case

Learn to write a system test case for the browser in our Rails application.

We’ll write a test case of the widget rating feature, which will look very much like the one we wrote before. To test the widget rating feature, we need to:

  1. Navigate to a widget page.
  2. Click a rating button.
  3. Check that the DOM reflects our rating.

We’ll create this test in test/system/rate_widget_test.rb, and it will look for an element matching [data-rating-present] that has the text content, including the rating the test will choose. Even though this content is not initially visible and some of it (the rating itself) isn’t even in the DOM, Capybara will wait a small amount of time for the matching markup and content to appear:

Get hands-on with 1200+ tech skills courses.