UI validation with Database
Step 1:- Click on Add Test Case and create a new testcase.

Step 2:-Add the steps to the testcase to navigate to the screen where elements are visible which we need to validate in the database.

Step 3:-Declare the variables on the test case writer in which values are retrieved from the UI elements.

Step 4:- Declare the empty variables on Test case writer to save values from the database.

Step 5:- Add a custom script to access the data from the database.

Step 6:-Call the custom script to assign value to the empty variables declared in previous steps.

- In the custom script you can access the data from the database, which are further assigned to the variables declared by the user.
- Following is the example script to assign value to variables from the database.
Connection con = WebTestUtility.getConnection("localhost", "1433","BookList" , "admin", "aaaaaa66");
if(con == null)
{
System.out.println("Con is null");
}else{
System.out.println("Connection is done");
}
Statement myStmt = con.createStatement();
ResultSet myRs = myStmt.executeQuery("Select * from BOOKSLIST");
while(myRs.next())
{
System.out.println(myRs.getString(1)); //ISBN Column
System.out.println(myRs.getString(2)); //Title Column
System.out.println(myRs.getString(3)); //sub title Column
System.out.println(myRs.getString(4)); //Auther Column
System.out.println(myRs.getString(5)); //Totalpages Column
System.out.println("===========================");
System.out.println(var_ISBNFromUI); //ISBN Column
System.out.println(var_TitleFromUI1); //Title Column
System.out.println(var_SubTitleFromUI1); //sub title Column
System.out.println(var_AuthorFromUI1); //Auther Column
System.out.println(var_TotalPagesFromUI1); //Totalpages Column
var_ISBNFromDB = myRs.getString(1);
var_TitleFromDB = myRs.getString(2);
var_SubTitleFromDB = myRs.getString(3);
var_AuthorFromDB = myRs.getString(4);
var_TotalPagesFromDB = myRs.getString(5);
}
- Once the custom script is executed the next step is to check whether the UI element values are equal to values acquired from the database.
- For which we use the ‘Check’ function on the variables.
Step 7:- Add steps to check if the value retrieved from UI element is same as the value obtained from the database.

Step 8:- Click on ‘Save’ to save the testcase.
Step 9:- Once testcase is ready select the testcase and click on ‘Run’.

Step 10:- Enter the URL of the website you want to test and tap ‘Next’.

Step 11:- Select the browser and tap ‘Run Test’.

- As the test case starts to run you can see the log of the testcase execution.

- You can also see the both values, the one retrieved from the UI elements and the one extracted from the database in the log.

- If the test run is successfully executed, the user can see the message of “Completed” and “Test success” in the Detailed Log.
