Fetching Data From MySQL Database Table For Selenium WebDriver Test

Earlier we learnt how to download and Install MySql database In THIS POST and create database and tables to store data In THIS POST. Both these steps are mandatory to read data through test script. Now this Is time to fetch data from MySQL database table using test script. You need to
follow bellow given steps to run data fetching script In eclipse.

Step 1 : Download required jar file
First of all you need "mysql-connector-java-3.1.13-bin.jar" file which will help us to create database connection In test script. You will find this jar file download link on THIS PAGE.

Step 2 : Add jar file In projects build path.
Now you need to add "mysql-connector-java-3.1.13-bin.jar" file In your project's build path. If you don't know, You can view THIS PAGE to learn how to add any jar file In projects build path.

Step 3 : Create test to fetch data from MySql database
Now you are all set to create test which will fetch data from MySql database table. I have created sample test script which will fetch data from "user" table of "test" database.

Note : Before running this example, Please verify database name, table name, user name and password. User name will be root for mysql database as per our configuration and use password which Is set by you during CONFIGURATION STEP. Modify all these detail accordingly before running test.

DOWNLOAD MySqlReadData.zip folder. You will get MySqlReadData.java test script file In zip folder when extract It. Import It In your eclipse and then execute.

If everything Is correct then console output of above example will be as bellow.

That means our MySql data fetching test Is successfully completed.

This Is sample test script to show you how to extract data from MySql database. If you have application which store data In MySql database then first you need to Insert data In database using Selenium WebDriver test and then you can verify that data directly from DB as given In this example script. NEXT POST  will describe you how to execute query with where clause to fetch specific record from db.

1 comment:

  1. above link to DOWNLOAD MySqlReadData.zip is not opening. Please provide the correct URL .