As far as Selenium is concerned, there is no direct facility given by Selenium to connect with any database to check any stored value. To check the saved value you have to connect to databases depending on used db like mysql, oracle etc. You have to use supported api to make connection to database first then execute query. 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.
In our last Selenium blogs we learned below Some Selenium frameworks Concepts:
- Part1: Data Driven Framework in Selenium Webdriver Using Apache POI
- Part2: Passing data to DataProvider from Excel Sheet in TestNG
- Part3: Creating ,Updating and Deleting Excel Workbook and Sheet By Selenium
We discussed some Advanced concepts like how we deal with Data Manipulation in Excel sheet by Selenium WebDriver. So moving ahead with our advance topics of selenium blog series we will introduce you with concepts of Database Testing using Selenium WebDriver.
We would discuss the basic process like Database Connection, executing queries, fetching data and disconnecting database instances etc. As we know that all the web applications need a backend to store the Data. Databases like MySQL, oracle, and SQL server are popularly use in these days
Here I take a example of Bookingcommerce in which i explain how user can register in bookingcommerce.com , So Bookingcommerce is basically a Saas based online booking and Appointment scheduling software.
Consider a following scenarios
1) In any application we make sure that the data entered by code is consistently reflected in our databases. Thus we are able to retrieve the information by executing a sql query and verify the retrieved information against information we pass in our application by code. for examples, registration forms, user data, user profiles, and delete user data. Thus after Running our registered user Test code we need to make sure that whatever information we pass by Test code will get successfully saved into the Database as soon as user registered in our application.
2) Another use case of performing database testing with Selenium WebDriver by building mysql connection either with our localhost and either with another system IP.
Below Code with mention all scenarios for User Register in Bookingcommerce.com
Below is my Excel sheet :