Search⌘ K
AI Features

Testing our JavaScript Functionality

Explore how to write and run system tests in a Rails application to verify JavaScript functionality using ChromeDriver and Capybara. Understand the process of simulating user interactions in a browser and ensure your application features work as intended and remain stable during development.

Testing the functionality

Now that we have application-level functionality in JavaScript code, we are going to need to put tests in place to ensure that the function not only works as intended but continues to work as we make changes to the application.

Testing this functionality involves a lot of steps. We have to visit the store, select an item, add that item to the cart, click checkout, fill in a few fields, and select a payment type. From a testing perspective, we are also going to need both a Rails server and a browser.

To accomplish this, Rails makes use of a version of the popular Google Chrome web browser named ChromeDriver, which has been augmented to include programming interfaces to enable automation, and Capybara, which is a tool that drives this automation.

Tests that pull together a complete and integrated version of the software are called system tests, which is exactly what we will be doing. We will be testing a full end-to-end scenario with a web browser, web server, our application, and a database.

Automated generation of tests

When we ...