What's in a test? Arrange, Act, and Assert!
Before we start running Capybara tests, there's a topic we need to talk about.
What exactly is a test?
For our automation, we'll be following a standard testing pattern described by William Wake, a software consultant back in the days of Kent Beck's extreme programming.
The software testing pattern of arrange, act, and assert has the following components:
Our test will follow the same pattern.
Arrange: Navigate to the area in the web application we'll be testing and find the web element we'll be interacting with, such as a checkbox, a textbox, a dropdown, or a label.
Act: Click that checkbox. Fill that textbox. Select a value from the dropdown or grab a text from a header.
Assert: When you check the checkbox or fill the log in form, did you get the correct user prompts you were expecting? Did the expected value of a page header match the actual value that's there on the page?
With RSpec, the test framework we'll be using, it allows you to describe the features you'll be testing by listing the various scenarios you need to test. Capybara works with the
capybara/rspec library to create descriptive acceptance tests.
Let’s look at our possible test with Capybara and Rspec.
feature 'Visit The-Internet Home Page' do
scenario 'Title: Welcome to the-internet' do
expect(page).to have_content('Welcome to the-internet')
In this test we're visiting a page and then expecting the page to have the content, "Welcome to the-internet."
This test follow the arrange, act, and assert pattern.
The background segment arranges the set up that needs to take place before the scenarios are kicked off, such as visiting the main page.
The features contain groups of test scenarios that outline each step to act out.
Expect compares the expected values found in the test and asserts they match the actual values found. If they do not match, the test fails.
In the next chapter, we'll go over this test with a bit more depth.
The quiz for this chapter can be found in section 2.4