The database is nothing but the stack of details, placed in an organized manner. It is like School Attendance Book; we can get the student and details about the student like that database stores different data with different data types.
We can filter these data using a Language called SQL, SQL (Structured Query language) helps retrieve, insert, update, and delete the data from the database. We can store large data in the database and retrieves in the required data in seconds.
We cannot perform database testing using selenium python, but we can use language (java/python...) APIs to automate the database in selenium.
Selenium does not provide any utility to do database testing; You will have to utilize features available in a python programming language.
For example, if you are using python, you need to add appropriate .bindings file & write your own method to read/write/manipulate data in database tables.
For database programming, the Python DB API is a widely used module that provides a database application programming interface.
Before we start using our database with python, we must connect to it. There are four steps of database communication using python:
# importing the module import MySQLdb # cerate a database connection db = MySQLdb.connect("localhost","userName","Password","DB_Name") # define a cursor object cursor = conn.cursor # drop table if exists Cursor.execute("if STUDENT table exists drop it") # query sql = "create table STUDENT (NAME CHAR(30) not null, CLASS char(5), AGE int, GENDER char(8), MARKS int" # execute query cursor.execute(sql) # close object cursor.close() # close connection conn.close()
You can use a connection object for performing operations like commit(), rollback() and close() as shown below:
|cur = conn.cursor()||creates new cursor object for executing SQL statements|
|conn.commit()||Roll back the transactions|
|conn.rollback()||Roll back the transactions|
|conn.close()||closes the connection, After interacting with the database you need to close the database connection to give up resources.|
|conn.callproc(proc,param)||call stored procedure for execution|
|conn.getsource(proc)||fetches stored procedure code|
I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.