Data base is nothing but the stack of details, placed in organized manner. It is like School Attendance Book, we can get the studen and details about the student like that database stores different data with different datatypes.
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 database and retrievs 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 feature available in python programming language.
For example, if you are using python, you need to add appropriate .bindings file & write 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:
Database Operations | Description |
---|---|
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 |
Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know.
Knowledge is the only thing that doubles when you spend it.
I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation