MySQL - Creating Data Tables To Use In Selenium WebDriver Test

Before creating tables In MySQL database, It must be Installed In your system. You can read my previous post to know how to download and Install MySQL In windows system. We are going to perform MySQL database testing using selenium WebDriver. So We need to create table Inside
database and need to Insert some data In It manually. Execute bellow given steps.

Step 1 : Connect MySQL Server from command line
  • Open MySQL command line client from Start menu.
  • It will ask you to enter password. Enter your login password which was set during MySQL config step.

  • It will print message as bellow In command prompt. Now you are connected with database.

Step 2 : View available databases In MySQL
To view available databases In mysql, you need to execute bellow given command In command prompt.
  • Execute show databases; command In MySQL command line client as bellow. It will show you list of all available databases.
  • As you can see In above Image, there Is one default database with name "test". We can use It to create our table.
Step 3 : Select database to create table.
Execute bellow given command In MySQL command line to select "test" database for creating table In It.
  • Execute use test command to select "test" database from list.
  • It will show you message Database changed as shown In above Image.
Step 4 : Create table In "test" database.
Now we are going to create new table Inside "test" database. Let's check If there Is any table available In "test" database before creating table In It.
  • Execute show tables; command In command line. It will show you bellow given result.
  • There Is not available any table Inside "test" database. Let's create new table "user" In test database with four columns id, name, city and age.
  • To create "user" table, execute query CREATE TABLE user (id INT(6), name VARCHAR(20), city VARCHAR(20), age INT(6)); In command line as bellow.

  • It will create "user" table Inside "test" database with four columns.
Step 5 : Insert data In "user" table
Now we can Insert data In user table. Execute bellow given queries one by one In MySQL command line client. It will Insert record one by one In "user" table.

  • INSERT INTO user (id, name, city, age) VALUES (1, 'smith', 'London', 25);
  • INSERT INTO user (id, name, city, age) VALUES (2, 'Daniel', 'Boston', 37);
  • INSERT INTO user (id, name, city, age) VALUES (3, 'Anup', 'Delhi', 22);
  • INSERT INTO user (id, name, city, age) VALUES (4, 'Joshua', 'Boston', 33);
  • INSERT INTO user (id, name, city, age) VALUES (5, 'Karan', 'Delhi', 45);
  • INSERT INTO user (id, name, city, age) VALUES (6, 'Karishma', 'Delhi', 21);

Step 6 : view table data
Now we can view "user" table data. 
  • Execute query "select * from user;" to view data from user table.

Now we have data table In MySQL database which we can use In selenium WebDriver test. Next step will tell you how to fetch data from table using select query In test script.

No comments:

Post a Comment