BLOG

Img
Ankush Bansal Author's Perspective
img
5 Minutes read

PERFORM DATABASE TESTING USING SELENIUM

As the industry moves into big data, databases play a significant role in maintaining information and holding the series. Database Validation and verification play an important role to ensure that there are no bugs while capturing the data and storing them.

There are two ways to achieve it either manually or through Automation.

During manual checking, one has to go through each entry that is getting maintained in the database when any transaction happens at the front end. However, since there are several movements on the computer, it gets more difficult, so it takes time to test all the tables one by one. So Selenium is one such method in Automation Software that aims to include functionalities for checking the database which is time-saving and cost-effective.

Selenium WebDriver is limited to using a Browser to check the applications. You need to use the JDBC (Java Database Connectivity) to use Selenium WebDriver for database verification.

JDBC (Java Database Connectivity) is a Database level API for running SQL statements. The communication between Java programming language and a broad variety of databases is responsible for this. The JDBC API contains the classes and interfaces below

  • Driver Manager: It is used to manage a list of database drivers. This driver recognizes a certain sub-protocol under JDBC in order to establish a database Connection
  • Driver: It is an interface that handles the communications with the database server.
  • Connection: It is an interface that consists of all the methods required to connect to a database. The connection object represents communication context wherein the entire communication with the database is through connection object only
  • Statement: interface is used to execute SQL statements against a relational database.
  • Result Set: It is an object which points the cursor to the current row
  • SQL Exception: An exemption that contains details about a mistake in accessing a database or other errors. Each SQLException offers knowledge of different kinds

A high-Level diagram of database testing

Steps to establish Database connection

1) Make a connection to the Database To make a connection with the database, the syntax will be
DriverManager.getConnection(URL, "userid", "password" )

Here,

  • Userid is the username configured in the database
  • The password of the configured user
  • URL is of format jdbc:<dbtype>://ipaddress:portnumber/db_name"
  • <dbtype> - The driver for the database you are trying to connect. To connect to the SQL server database this value will be "SQLEXPRESS2016"

For connecting to database with name "emp" in SQL Server URL will jdbc:sqlserver://<IPADDRESS>\\SQLEXPRESS2016:<PORTNUMBER>;databaseName=<DBNAME>;

And the end code will look like

Connection con = DriverManager.getConnection(dburl, username, password)

You also need to load the JDBC Driver using the below code

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")

2) Send Queries to the Database Once connection is made, you need to execute queries.

You can use the Statement Object to send queries.
Statement stmt = con.createStatement();

Once the statement object is created use the executeQuery method to execute the SQL queries
ResultSet rs = stmt.executeQuery(select * from employee;);

Ebook
Top 10 Sitecore 9 Form Features to Increase Lead Conversions

3) Process the results

Display the results using below code

while (rs.next()) {
String myName = rs.getString(0);
String myAge = rs.getString(1);
System.out.println(myName + " :::: " + myAge); }

4) Close the connection

con.close();

Ankush Bansal Sr. Practice Manager - Testing


Talk to our Experts

Talk to us about how we bring together 1:1 personalisation, deep Martech Expertise, CX & Demand Gen Strategy, Engagement Analytics & Cross-Channel Orchestration to drive award winning experiences that convert

Get in touch for a complimentary consultation or a demo today.

Expert Workshops

Free workshops, expert advice & demos- to help your realize value with Sitecore

Register

Session Presentations

  • Sitecore + SFMC= Marketing Success
  • Transforming The Future Of eCommerce
Meet Us

Giveaways:

Participate in our event survey , meet us at our booth , get free giveaways & a chance to win an iPhone 11

Let’s go
Close Button