0

I am creating UI tests for a web application that manages records. I want to test adding a record to the system. I have complete control over the test environment including access to the database where the web application stores records.

What is the best practice for validating that a new record was added?

Here are a few options that I have:

  1. Check a confirmation message that is shown on a web page after adding a record.
  2. Open another page that shows a list of records and check that the new record is there.
  3. Use REST API or connect directly to the database to check that the new record is in the database.

Here is a description of how the process of adding a record looks like from the user's point of view:

  • The user logs into the web site. The home page is shown.
  • The user navigates to the Records Management page using a link located on the home page. The Records Management page shows 10 most recently added records.
  • The user clicks Add Record button/link. The Add Record page is shown.
  • The user fills values into text fields and clicks Save button. The web page shows 'The record has been saved successfully' message and navigates user back to the Records Management page.

1 Answer 1

2

Your proposals have a few problems:

  • Check a confirmation message that is shown on a web page after adding a record.

It doesn't say anything about the interaction with the backend. Anyone can code the confirmation message to appear after clicking on Save

Open another page that shows a list of records and check that the new record is there

Aside from taking a longer time to access the other page, you will be fragile to errors on the another page itself. Unrelated problems may impede you to test the save action.

Use REST API or connect directly to the database to check that the new record is in the database.

Similar to the above situation. If the connection to the DB has any problem, you won't be able test your UI. Aside from being slow, since you are accessing an external system.

To be effective and efficient, you can use the Spy pattern. With it, you will be able to check if your UI component is calling the backend with the parameters required to save the record. In this way, you don't need to access any external system, saving you from fragility and slow runtime.

One approach to use Spies is contract testing (e.g. with Pact), with the additional benefit of being able to use the consumer contract to drive the development of the backend API.

Not the answer you're looking for? Browse other questions tagged or ask your own question.