Author - StudySection Post Views - 1,309 views
Selenium Database

Steps to Connect a Database to Selenium Test Cases


Every application requires a database like My SQL, Oracle, or any other database to store all its data. Selenium Webdriver is used for examining web applications. We can perform many operations like submitting information and some times retrieving information and validate them. Here we will discuss the steps to connect a database to a selenium test case.

How to connect a database to selenium test cases

Here are the following steps to connect your database with selenium:

  1. Download MYSQL and create a database
  2. JDBC connection with Java programming
  3. Selenium code to integrate with JDBC and retrieving data from the database.

Firstly, download the MYSQL from this link:


After installing the Mysql Workbench and made a connection by filling credentials to create Workbench access. Once we successfully log in to the workbench then we create a database and table to insert the data.


In this step, we integrate the database with JDBC API and for that, we need to download the Jar File.We can download this jar file directly from this link: “

Then we need to add this Jar file in eclipse.
Steps: project->properties->add external jars.

Make connection with database from your project with this code:
On running this whole code we retrieve data from the database and automate our test case which is entering username and password on the web:

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class jdbcconection {

public static void main(String[] args) throws SQLException, ClassNotFoundException {

//Initialization of variables
String host="localhost";
String port= "3306";

//Loading the required MYSQL JDBC Driver class

//creating connection to a database
Connection con=DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/demo", "root", "root");

//Executing SQL query and fetching the result
Statement s=con.createStatement();

ResultSet rs=s.executeQuery("select * from credentials where scenario ='demo'");
WebDriver driver= new FirefoxDriver();
//retrieving username and password from database


Now, This code executes the query and gets the username and password to login to the “” account.

As we have a username and password in the credential table:




Being the most extensively used JavaScript library, a jQuery certification will add enormous value to your skill-set. jQuery provides various functionalities to the developer in order to develop complex applications with ease and efficiency.

Leave a Reply

Your email address will not be published. Required fields are marked * cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri