Uncategorized

How to fetch Key and value from My SQL…

A database is a software subsystem that offers an efficient way to store data and request said data via a structured query language known as SQL. Databases store critical business information, thus functioning as the backbone of an entire application. Database testing is a vital part of software testing that involves verifying the accuracy and completeness of data stored in a database.

Automated database testing can cover a wide range of tests, such as data integrity, performance, security, and integration. It can also detect defects or issues in the database, such as data corruption, missing data, incorrect data, and duplicate data.

Naturally, database testing is essential to ensure the system is working correctly. As automation testing with Selenium is most frequently used by QAs, this article will detail how to perform database testing using Selenium.

Java Database Connectivity

JDBC is the standard Java API required for database-independent connectivity between the Java programming language and many databases. This application program interface (API) lets users encode access request statements in a Structured Query Language (SQL). They are then passed to the program that manages the database. It involves opening a connection, creating a SQL Database, executing SQL queries, and arriving at the output.

Steps to create a JDBC Application

To create a JDBC application, follow the steps below:

  1. Import the packages: Include the packages that contain the JDBC classes required for database programming.
  2. Register the JDBC driver: Initialize a driver to open a communication channel with the database. Register to the database with the command:
    Class.forName(“com.mysql.jdbc.Driver”); // class.forName load the Driver class
  3. Open a connection: After the driver registration, use the getConnection() method to create a Connection object, representing a physical connection with the database.
  4. Execute a query: Use an object of type ‘Statement’ to build and submit a SQL statement to the database.
  5. Extract data from the result set: Use the appropriate getXXX() method.
  6. Clean up the environment: Close all database resources that rely on JVM garbage collection.

2. Selenium Database Connection

Selenium is one of the prominent automation testing tools. As mentioned before, Selenium performs only UI validations. Thus, this article will depict a JDBC connection as Selenium doesn’t support database testing directly, but it can be done with connectors like JDBC and ODBC. This article uses JDBC to connect to a database, and test cases are verified using TestNG framework.

3. Database testing using Selenium

Step 1: Create a database in command prompt and insert the tables.
Step 2: Establish a connection to the database using JDBC.
Step 3: Execute the MySQL queries and process records present in the database.
Step 4: Integrate TestNG with JDBC to perform Database Testing.

Have a look at the script below:

package com.test.traveltest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class SeleniumDatabaseTesting {
// Connection object
static Connection con = null;
// Statement object
private static Statement stmt;
// Constant for Database URL
public static String DB_URL = "jdbc:mysql://127.0.0.1:3306/hrmdb";
//Database Username
public static String DB_USER = "root";
// Database Password
public static String DB_PASSWORD = "rahul";

public static WebDriver driver;
public static String uname;
public static String uval;
public static String pwd;
public static String pval;
public static String loginbtn;

@BeforeTest
public void setUp() throws Exception {
	
	System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"\\src\\main\\java\\drivers\\chromedriver1.exe");
  	driver = new ChromeDriver();
	driver.manage().window().maximize();
	driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login");
try{
// Database connection
String dbClass = "com.mysql.cj.jdbc.Driver";
Class.forName(dbClass).newInstance();
// Get connection to DB
Connection con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
// Statement object to send the SQL statement to the Database
stmt = con.createStatement();
}
catch (Exception e)
{
e.printStackTrace();
}
}

@Test (priority = 0)
public void testuname() {
try{
String query = "select * from login where id = '" +1+"'";
// Get the contents of userinfo table from DB
ResultSet res = stmt.executeQuery(query);
// Print the result untill all the records are printed
// res.next() returns true if there is any next record else returns false
while (res.next())
{
System.out.print(res.getString(1));
System.out.print(" | " + res.getString(2));
System.out.print(" | " + res.getString(3));
System.out.println();
uname = res.getString(2);
uval = res.getString(3);
}
}
catch(Exception e)
{
e.printStackTrace();
}

driver.findElement(By.name(uname)).sendKeys(uval);

}

@Test (priority = 1)
public void testpwd() {
try{
String query = "select * from login where id = '" +2+"'";
// Get the contents of userinfo table from DB
ResultSet res = stmt.executeQuery(query);
// Print the result untill all the records are printed
// res.next() returns true if there is any next record else returns false
while (res.next())
{
System.out.print(res.getString(1));
System.out.print(" | " + res.getString(2));
System.out.print(" | " + res.getString(3));
System.out.println();
pwd = res.getString(2);
pval = res.getString(3);
}
}
catch(Exception e)
{
e.printStackTrace();
}

driver.findElement(By.name(pwd)).sendKeys(pval);

}

@Test (priority = 2)
public void testlogin() {
try{
String query = "select * from login where id = '" +3+"'";
// Get the contents of userinfo table from DB
ResultSet res = stmt.executeQuery(query);
// Print the result untill all the records are printed
// res.next() returns true if there is any next record else returns false
while (res.next())
{
System.out.print(res.getString(1));
System.out.print(" | " + res.getString(2));
System.out.print(" | " + res.getString(3));
System.out.println();
loginbtn = res.getString(2);

}
}
catch(Exception e)
{
e.printStackTrace();
}

driver.findElement(By.xpath(loginbtn)).click();

}

@AfterTest
public void tearDown() throws Exception {
// Close DB connection
if (con != null) {
con.close();
}
}
}
Manual Testing

Test Case for Registration in Gmail.

Test Case Title: Registration in Gmail

Test Case ID: RG001

Precondition:

  • The user has a web browser and a stable internet connection.
  • The user has not registered with the email address being used for this test case.

Test Steps:

  1. Open a web browser and navigate to the Gmail registration page.
  2. Enter a valid first name and last name in the respective fields.
  3. Enter a valid email address that has not been used for a Gmail account before.
  4. Create a strong password that meets the password requirements provided on the page.
  5. Confirm the password by re-entering it in the provided field.
  6. Click on the “Next” button to proceed to the next step.
  7. Enter the user’s birthdate in the respective fields.
  8. Select the user’s gender from the options provided.
  9. Optionally, enter a phone number and/or recovery email address.
  10. Complete the captcha challenge.
  11. Read and agree to the terms of service and privacy policy by checking the corresponding checkboxes.
  12. Click on the “Create Account” button to submit the registration form.

Expected Results:

  • The user should be able to complete the registration process without encountering any errors or issues.
  • After submitting the registration form, the user should be redirected to the Gmail welcome page or the Gmail inbox.
  • The user should receive an email confirmation of the new Gmail account creation.
  • The new account should be accessible from any device by logging in with the email address and password provided during registration.
Manual Testing

Test Case for Login into Gmail

Test Case Name: Login to Gmail

Test Objective: To verify that a user can successfully login to their Gmail account

Test Steps:

  1. Open a web browser and navigate to the Gmail login page (https://www.gmail.com)
  2. Enter a valid email address in the “Email or phone” field
  3. Click on the “Next” button
  4. Enter a valid password in the “Password” field
  5. Click on the “Next” button
  6. Verify that the user is successfully logged in to their Gmail account and the inbox is displayed

Test Data:

  • Valid email address
  • Valid password

Expected Result:

  • The user should be able to successfully login to their Gmail account and the inbox should be displayed.

Test Environment:

  • Web browser (Google Chrome, Mozilla Firefox, etc.)
  • Internet connection

Test Execution:

  • Execute the above test steps in the test environment using the provided test data.
  • Observe the behavior of the application during the test execution.
  • If the actual result matches the expected result, mark the test case as “Pass”. If the actual result does not match the expected result, mark the test case as “Fail”.
  • Record any defects or issues encountered during the test execution in a defect tracking system.
Manual Testing

Test Cases for Login Page

Here are some manual test cases for a login page:

  1. Verify that the correct URL opens the login page
  2. Check that the correct page title is displayed for the login page
  3. Validate that the login form is displayed and contains the expected fields (e.g. username, password)
  4. Verify that the input fields only accept valid characters (e.g. no special characters in the username field)
  5. Test the error message displayed when an incorrect username or password is entered
  6. Verify that the password field is masked (e.g. ***)
  7. Check that the user is redirected to the appropriate page after successful login
  8. Validate that the “Remember Me” checkbox works as expected
  9. Verify that the user can reset their password if they have forgotten it
  10. Test the login functionality with both valid and invalid input on both mobile and desktop devices.
  11. Check that the login page is secure (e.g. SSL enabled)
  12. Validate that the login functionality works on different browsers (e.g. Chrome, Firefox, Safari, etc.)
  13. Verify that the user is logged out after a set amount of time (e.g. 30 minutes)
  14. Test the login functionality with different types of accounts (e.g. new accounts, existing accounts, etc.)
  15. Validate that the correct error message is displayed when an invalid username or password is entered multiple times
  16. Verify that the login functionality works even if the network is slow or unstable
  17. Test the login functionality with different types of input (e.g. long username, special characters, etc.)
  18. Validate that the user is redirected to the appropriate page after logging out
  19. Verify that the user can still access the login page after logging out
  20. Check that the login page is accessible for users with disabilities (e.g. screen readers).
Manual Testing

Test Cases for OTP verification

Here are some manual test cases for OTP verification:

  1. Verify that OTP is sent to the correct phone number or email
  2. Check if the OTP format is correct (e.g. 6 digits)
  3. Validate that OTP is sent within the expected time frame
  4. Verify that OTP can be resend if it has expired or not received
  5. Test that the OTP is only valid for a set amount of time
  6. Check that the same OTP cannot be used multiple times
  7. Validate that the OTP input field only accepts numbers
  8. Verify that an error message is displayed if an incorrect OTP is entered
  9. Test that the OTP verification process is successful after entering a valid OTP
  10. Verify that the user is redirected to the appropriate page after successful OTP verification.
  11. Test the OTP functionality with both valid and invalid input on both mobile and desktop devices
  12. Verify that OTP functionality works on different browsers (e.g. Chrome, Firefox, Safari, etc.)
  13. Check that the OTP is sent even if the network is slow or unstable
  14. Test the OTP functionality with different types of accounts (e.g. new accounts, existing accounts, etc.)
  15. Verify that the OTP is sent even if the user is not logged in
  16. Check that the OTP is not sent if the user has opted out of receiving OTP
  17. Validate that the OTP verification process works after multiple attempts
  18. Test the OTP functionality with different types of phone numbers (e.g. landline, mobile, international, etc.)
  19. Verify that the OTP is sent only to the user who requested it
  20. Check that the OTP verification process fails if the user enters the incorrect OTP multiple times.