API Testing:



Database Testing Using Selenium WebDriver – MySQL

Database Testing Using Selenium WebDriver

In this post, let’s see how to do Database Testing using Selenium WebDriver. As we all know Selenium WebDriver is a tool to automate User Interface. We could only interact with Browser using Selenium WebDriver.

Sometimes, we may face a situation to get the data from the Database or to modify (update/delete) the data from the Database.  If we plan to automate anything outside the vicinity of a browser, then we need to use other tools to achieve our task. To achieve the Database connection and work on it, we need to use JDBC API Driver.

Must Read: What is Gecko Driver and how to use it in Selenium WebDriver. 

The Java Database Connectivity (JDBC) API provides universal data access from the Java programming language. Using the JDBC API, you can access virtually any data source, from relational databases to spreadsheets and flat files. It lets the user connect and interact with the Database and fetch the data based on the queries we use in the automation script. JDBC is a SQL level API that allows us to execute SQL statements. It creates a connectivity between Java Programming Language and the database.

Using JDBC Driver we could do the following

  1. Establish a Database connection
  2. Send SQL Queries to the Database
  3. Process the results

Loading the required JDBC (Java DataBase Connectivity) Driver class:

Note: The parameter varies between Data bases such as MSSQL Server, DB2 etc.,

Database Testing with MSSQL Server

Database Testing with DB2

Establishing a connection to the DataBase (MySQL Server):

DB Connection URL Syntax (MySQL Server):

Executing SQL Queries:

Results from the executed query are stored in the ResultSet Object.

Fetching data from result set:

Disconnecting the Database connection:

List of Methods to process the results:

Database Testing Methods Selenium

Note: Assuming that you have already Installed Database.

Steps to follow – Database Testing using Selenium WebDriver:

  1. Click here to download the jar files.
  2. Add the downloaded jar file to your project

Right click on your Java File – Click on Build Path – Configure build path – Select the libraries – Click on add external JARs – Select MySQL JDBC
jar – Click on open to add it to the project

3. Copy the below mentioned script and modify as per your requirement and execute it

Note: You could find the detailed explanation of the script in the code snippet below

Script to get the data from the Database – Database Testing:

I would like to conclude this post “MySQL Database testing using Selenium WebDriver” here. If you find anything difficult, please comment below. Also, I have hand-picked few posts which will help you to learn more interview related stuff:

If you have any more question, feel free to ask via comments. If you find this post useful, do share it with your friends on Social Networking.

Sharing is caring.

Share on facebook
Share on twitter
Share on linkedin

Like This Post?

We have a lot more where that came from?

We only send really good stuff occasionally, promise.

Rajkumar SM

3 thoughts on “Database Testing Using Selenium WebDriver – MySQL”

  1. Hi , I am willing to learn database testing but I don’t know about selenium . Can anyone learn database testing without learning selenium.And what topics have to cover for database testing.

  2. Hi , I am willing to learn database testing but I don’t know about selenium . Can anyone learn database testing without learning selenium.And what topics have to cover for database testing.

    1. Hi Gureet, You could learn Database testing without learning Selenium. In database testing we do test Data integrity, data validity, fine tunning performance of database, validating stored procedures, indexes, etc., Currently we are not dealing with database testing. But sure we write on that too. You could learn SQL for software testers by clicking here.

Leave a Comment

Your email address will not be published. Required fields are marked *

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on whatsapp

Recent Posts:

Scroll to Top
API Testing eBook