Email Subscription Form

Saturday, January 27, 2018

Automated Form Testing

Now that we have looked at all the different ways we can manually test forms, it's time to think about automating those tests so you don't have to run through all the tests again every time you need to do a regression test!  But before you jump into automation, think for a while about what tests you really want to run.  Let's take last week's form as our example again.


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

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!


2 comments:

  1. Very interesting, good job and thanks for sharing such a good blog. Your article is so convincing that I never stop myself to say something about it. You’re doing a great job. Keep it up But i ha have also something for you to check your Cps test and share with everyone.

    ReplyDelete
  2. I recently had the good fortune of reading your blog on "Automated Form Testing". Automation and test automation services are extremely popular these days, and you made the perfect decision by selecting this topic. It was well-written, and I liked it a lot.

    ReplyDelete

New Blog Location!

I've moved!  I've really enjoyed using Blogger for my blog, but it didn't integrate with my website in the way I wanted.  So I&#...