What sorts of things would we want to make sure still work when we do our regression test?
- We'll want to make sure that every field can be populated with data and saved
- We'll want to make sure that all of the required fields are still required, and that we get an appropriate error message when we leave a required field blank
- We'll want to make sure that validation rules are respected in each field
- We'll want to verify that both the Save and the Cancel buttons work correctly
As I've discussed in a previous post, automated tests involving the GUI can often be slow and flaky. So we'll want to limit the number of times we spin up a browser for testing. But we'd also like our tests to only assert on one thing at a time. Here are my suggestions for a suite of tests that could be run on this form. I've written them in Cucumber for ease of reading:
Scenario: Happy Path
Given I am adding a new user
When I fill out all the fields and click the Save button
And I navigate to the Users page
Then I verify that all of the fields are displayed on the page
Then I verify that all of the fields are displayed on the page
Scenario: Required Fields
Given I am adding a new user
When I leave all fields empty
And I click the Save button
Then I verify that an error message is present for each required field
Scenario: Validation Rules
Given I am adding a new user
When I give each field an invalid value
And I click the Save button
Then I verify that an error message is present for each invalid field
Scenario: Cancel Button
Given I am adding a new user
When I give each field a value
And I click the Cancel button
Then I verify that all fields are now empty
So, we can cover a lot of territory with just four automated tests!
Our Happy Path tests that values in all of the fields will save correctly, and it also tests the Save button. If one of the values does not save, we will know we have an error. If all of the values do not save, we will know there is a problem either with the Save button or with the underlying data store.
Our Required Fields test checks to make sure that every field that is required displays an appropriate error message if it is not filled out. If even one required field does not display the message, we will know there is a problem.
Our Validation Rules test violates one rule for each text field. It would be a good idea to mix and match the different types of rule violations. For example:
First Name- send a value with numbers and non-letter characters, such as $23.00
Last Name- send a value with not enough letters, such as A
Personal Phone- send a value with the wrong number of digits, such as 008675309
Work Phone- send a value with non-number characters, such as 800*555-!@#$
Street Address 1- send a value with way too many characters, such as all the lyrics to "Frosty the Snowman" (my favorite song to test with)
Street Address 2- send a value with one too many characters
City- try sending a script, such as <script>alert("XSS Here!")</script>
State- send an invalid state, such as XX
Zip Code- send a Zip Code with the wrong number of digits, such as 0377
While this does not test every single way that the rules could be violated in every text field, it covers a wide variety of possibilities, and verifies that for each error, you receive an appropriate error message. You could always add more tests here if you felt that more coverage was needed.
Finally, we verify that the Cancel button works correctly.
With just these four automated tests, we're able to make sure no functionality is broken. Running these regression tests will free you up to do more exploratory testing in your application, and to test new and more interesting features!