Article

Using Selenium and Java for Database testing

Topic: Coach Training and CertificationPublished December 11, 2017
No ratings yet694 viewsSign in to rate

As we probably aware each application needs to keep up a database to store every one of its information. Selenium Webdriver is utilized for testing web applications and we perform numerous operations like submitting data and a few times recovering data and approve them.
In selenium contents, when there is a need of getting the Data from the database we may need to utilize APIs which communicates with database like JDBC. Java Database Connectivity (JDBC) is a Java API which is utilized to associate and collaborate with Database.
For what reason do we utilize JDBC rather ODBC?
ODBC is produced and written in C, which is stage Independent. Whereas JDBC API is a detail gives set of interfaces which are composed and created in Java programming dialect.
How to connect to database utilizing JDBC?
The beneath are the Steps to Connect to database, before continuing, you need MySQL Connector. You can download from here Download MySQL Connector Jar and include it the construct way as we include selenium webdriver jar.
• Load and Registering the Driver
• Setting up Connection.
• Making Statement Object
• Execute the Statement
• Shutting the association.
1. Load and Register the Driver:
For enrolling the Driver we Load the Driver class utilizing forName() strategy. forName() is the static manufacturing plant strategy which is available in predefined class called "Class". This strategy stacks the class which is specified as parameter.
Class.forName("com.mysql.jdbc.Driver");//class.forName stack the Driver class
Inside this Driver class will enlist the driver by utilizing static strategy called registerDriver().
2. Building up Connection:
For building up association with database we call static strategy called getConnection(...) introduce in DriverManager Class. This technique contains three contentions of string sort. i.e., url, username and secret key
DriverManager.getConnection("jdbc:mysql://localhost:3306/Employee","root","root");
URL contains "jdbc(main protocol):mysql(sub convention for mySql)://localhost:3306(sub name for mysql (host:prot))/Employee(database)" and this strategy return sort is Connection Object ie., Association
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Employee","root","root");
3. Making Statement Object:
For making articulation question we have to call a strategy called createStatement() which is available in Connection Interface.
con.createStatement();
What's more, this strategy returns Statement question and it is no contention technique.
statement st= con.createStatement();
4.Executing Queries:
For executing inquiries there are distinctive techniques exhibit in Statement Interface for recovering records and for refreshing records.
Recovering records:
for executing select queries(for bringing records) we call a strategy called executeQuery(String qry) by taking string as parameter.
st.executeQuery("Select * from Employee");
This strategy returns ResultSet protest.
Resultset rs= st.executeQuery("Select * from Employee");//once executeQuery() executes the inquiry and stores the records in to ResultSet question.
Presently we have to get the records from ResultSet question. To get to the resultset protest it utilizes a strategy called next() which displays in ResultSet Interface.
Naturally Resultset reference 'rs' focuses to before first column. it moves rs to next line and returns genuine. When it returns genuine we recover the information in first column. next() returns false when rs focuses to after the last column. this next() will rehashes the execution utilizing while circle till it returns false.
Refreshing records:
To refresh records in a table we utilize a technique called executeUpdate(String str) which returns whole number an incentive as what number of records have been refreshed.
5. Shutting the Connection:
When execution of all announcements were finished we have to close every one of the associations by utilizing strategy called close() show in Connection interface
There are fundamentally two things that we should need to test to confirm database with Selenium.
To begin with, in the wake of making any activity in the web application (Front-end), we might need to check the database if every one of the subtle elements we submitted are put away effectively. Presently for instance, while making a record, we will enter a few information email Id, username and so forth. To ensure a record is made, we can check record made in database with every one of the subtle elements client gave.
Other case can resemble, subsequent to playing out any activity, we might need to check the information showed in the UI is right by looking at the Database.

Further reading

Further Reading

4 total

Article

How Coaching Turns Knowledge Into Change Walk into any bookstore or scroll through your favorite podcast feed, and you’ll see the same thing: endless tips, strategies, and “life hacks” promising transformation.rnWe devour them. We highlight paragraphs. We even try to practice what we’ve learned. But somehow, the big shifts never stick. Weeks later, the old patterns creep back in.rnSo why does it happen? Why do so many smart, motivated people keep getting stuck — eve

October 6, 2025

Article

grinding and cutting a variety of materials across numerous industries. Understanding their construction, types and safety precautions is mandatory for anyone working with these powerful tools. This article will explore the basics of abrasive wheels, offering insights into their components, maintenance and legal requirements to ensure both effective and safe usage. Exploring the Basics of Abrasive Wheels Abrasive wheels are critical tools in various industrial applications, f

March 6, 2025

Article

The internet we use daily, known as the surface web, represents only a fraction of the entire digital landscape. Beneath this visible layer lies the deep web and the dark web, where anonymity, privacy, and unrestricted information exchange thrive. Among the most well-known directories for accessing dark web content is the Uncensored Hidden Wiki . This article delves into the history, significance, risks, and access methods of the Uncensored Hidden Wiki, providing a comprehens

January 31, 2025

Article

If you're searching for exceptional piano classes near you, there are several excellent options in Toronto to consider. For those eager to learn the piano, finding a school or instructor that offers expert guidance, comprehensive lesson plans, and a supportive environment is key. Catering to both beginners and advanced players, many schools in the Toronto area provide tailored lessons to help students achieve their musical aspirations. What to Look for in Piano Lessons When

January 1, 2025