In every web application's back end, there is a database like SQL Server, My SQL, Oracle or other types of database support functions. When using Selenium to automate UI testing, we need to make sure any user data entered from the UI should be captured in the database. We can use database retrieve statement to retrieve data and then use the data to verify what is entered by the user.
Considering the example of a user registration. User registers himself/herself with a username and password. By establishing a DB connection and retrieving data from the DB, we can validate the username entered in the UI should match the username in the database.
Test Case: verify that user login information should be saved in the database when a user successfully registered in a site.
In this screenshot below, first two users were in the database. A new test user is entered from the application UI, so we will verify the username.