RE: Backend testing using selenium


How to do backend testing using selenium. how to run SQL queries in selenium

anu17 Doctor Asked on September 2, 2014 in Selenium WebDriver.
Add Comment
2 Answers

Hi Anu,

Virender is right, selenium will not support backend testing and we will be not using any selenium methods/actions for backend testing.

First, want to know which database want to use?. Please find the below code samples for Oracle and Mysql.

NOTE: Please add particular JAR file to your project.


import java.sql.Connection;

import java.sql.DatabaseMetaData;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

public class DeleteRow {
public static final String DBURL = "jdbc:oracle:thin:@localhost:1234:XE";

public static final String DBUSER = "DBUSER";

public static final String DBPASS = "DBPASS";
public static void main(String[] args) throws ClassNotFoundException, SQLException {

Connection con = DriverManager.getConnection(DBURL, DBUSER, DBPASS);

Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM Table4");

while ({

int un1 = rs.getInt(1);

String un2 = rs.getString(6);

System.out.println(un1 +"--" +un2);

ResultSetMetaData md = rs.getMetaData(); // Dealing with the column

System.out.println("Column Name of 1st column: "+md.getColumnName(1));

System.out.println("Column Name of 2nd column: "+md.getColumnName(2));

System.out.println("Column Name of 3rd column: "+md.getColumnName(3));

System.out.println("Column Name of 4th column: "+md.getColumnName(4));

System.out.println("Column Name of 5th column: "+md.getColumnName(5));

System.out.println("Column Name of 6th column: "+md.getColumnName(6));

int col_count= md.getColumnCount(); // Column count

System.out.println("Column count is: "+col_count);




import java.sql.*;
public class Login {
public static void main(String[] args) throws ClassNotFoundException, SQLException {

WebDriver d =new FirefoxDriver();

String url = "jdbc:mysql://";

String un= "test1";

String pwd = "test2";

Connection con = DriverManager.getConnection(url, un, pwd);

Statement st = con.createStatement();

String str = "SELECT * FROM at_user WHERE username='s' ";

ResultSet rs= st.executeQuery(str);;

String name=rs.getString(2);

String pswd = rs.getString(3);



Vice Professor Answered on September 4, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.