Wednesday, March 22, 2023

Step-by-Step Guide: Connecting MySQL with Eclipse for Seamless Database Management

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class Mysql {

private static final String DB_URL = "jdbc:mysql://localhost:3306/local";

private static final String DB_USERNAME = "root";

private static final String DB_PASSWORD = "your_password";

@SuppressWarnings("unused")

public static void main(String[] args) {

try {

Connection con = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);

System.out.println("Connected to the database.");

Statement statement = con.createStatement();

ResultSet resultSet = statement.executeQuery("SELECT * FROM trial_user");

while (resultSet.next()) {

int id = resultSet.getInt("demoid");

String email = resultSet.getString("email");

String exam = resultSet.getString("exam");

String password = resultSet.getString("password");

String phoneno = resultSet.getString("primarycontactphoneno");

System.out.println(id + " " + email + " " + phoneno);

}

} catch (SQLException ex) {

System.err.println("Error occurred while connecting to the database: " + ex.getMessage());

}

}

}

Tuesday, March 21, 2023

Building Java Projects Made Easy with Maven

 Maven:

  •  Maven is a project management tool or software build tool or dependency management tool.
  •  It is used for project build or dependencies.

Maven addresses two aspects:

 1. It describes how software is built.

 2. It describes the software dependencies.

  • In Maven execution starts from the pom.xml file, it reads the POM.xml file and starts execution.

Uses of Maven:

  •  It is used to build the software application, manage your dependencies, run your tests, and create reports.

Maven Structure:

 src/main/java

 src/main/resources

 src/test/java

 src/test/resources

 JRE System library

 Maven Dependencies

 src

 target

 pom.xml


pom.xml: (Project Object Model)

  •  A Project Object Model or POM is the fundamental unit of work in Maven.
  •  It is an XML file that contains information about the project and configuration details used by Maven to build the project.
  •  It contains default values for most projects.


How to Write Effective Test Scripts for Postman API Testing

pm.test("success status", () => pm.response.to.be.success );


pm.test("Status code is 200 or 201"function () {
  pm.expect(pm.response.code).to.be.oneOf([200201]);
});


pm.test("Response time is less than 300ms", () => {
  pm.expect(pm.response.responseTime).to.be.below(300);
});


pm.test("Response status code contains 'Created' or 'OK'"function () {
  console.log(pm.response.status);
  pm.expect(pm.response.status).to.be.oneOf(['Created''OK']);
});


pm.test("Response body is not empty"function () {
    pm.expect(pm.response.text()).to.not.be.empty;
});

Monday, March 20, 2023

Dropdown Handling with Selenium WebDriver: Tips and Techniques

 import java.time.Duration;

import java.util.ArrayList;

import java.util.List;

import java.util.stream.Collectors;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

import org.testng.annotations.AfterTest;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.Test;

import io.github.bonigarcia.wdm.WebDriverManager;

public class Example {

WebDriver driver;

@BeforeTest

public void setUp() {

WebDriverManager.chromedriver().setup();

driver = new ChromeDriver();

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

driver.manage().window().maximize();

driver.get("https://www.amazon.com/");

}

@Test

public void dropdownTest() {

WebElement dropdown = driver.findElement(By.id("searchDropdownBox"));

Select select = new Select(dropdown);

// Print the first selected option and assert if it equals “All Departments”.

String firstSelectedOption = select.getFirstSelectedOption().getText();

System.out.println("firstSelectedOption = " + firstSelectedOption);

if (firstSelectedOption.equals("All Departments")) {

System.out.println("PASS");

} else {

System.out.println("FAIL");

}

// Print all of the drop down options-getOptions(); method returns the List<WebElement>. 

Using a loop, print all options.

List<WebElement> allOptions = select.getOptions();

for (WebElement eachOption : allOptions) {

System.out.println(eachOption.getText());

}

// Print the total number of options in the dropdown

int totalNumOfOptions = select.getOptions().size();

System.out.println("numOfOptions = " + totalNumOfOptions);

// if ‘Appliances’ is a drop-down option. Print true if “Appliances” is

// an option. Print false otherwise.

List<String> listOfOptions = new ArrayList<>();

for (WebElement eachOption : allOptions) {

listOfOptions.add(eachOption.getText());

}

System.out.println("listOfOptions = " + listOfOptions);

if (listOfOptions.contains("Appliances")) {

System.out.println("TRUE");

} else {

System.out.println("FALSE");

}

// Assert if the dropdown is in Alphabetical Order

List<String> sortedList = listOfOptions.stream().sorted().collect(Collectors.toList());

System.out.println("sortedList = " + sortedList);

}

@AfterTest

public void tearDown() {

driver.quit();

}

}

Thursday, March 16, 2023

OTP Code Verification: How to Test for Every Scenario

  1. Verify for verification whether valid and correct OTP is generated or not.
  2. Verify OTP code should be valid only for one time or not.
  3. Verify the count for the OTP code generated should not be more than required.
  4. Test the count for the OTP code generated should not be less than required.
  5. Verify OTP code is sent to the user successfully or not within time or not.
  6. Verify and confirm the time duration in which the user received the OTP-generated code sent by email.
  7. Check the time duration for the OTP-generated code received by the user on mobile.
  8. Verify the OTP code fetched by the application from the message by default or user add manually. It depends on the requirements.
  9. Verify by adding the valid OTP application that must accept the code successfully.
  10. Confirm whether the correct info message is shown or not in case if the User adds a valid OTP code.
  11. Verify a proper error message should be shown in case if the user adds an invalid OTP code.
  12. Verify OTP code should expire after the time allowed by the application or software.
  13. Verify application should not accept the OTP code once expired.
  14. Verify the user can request a new OTP code by clicking on the link or button to resend the code.
  15. Verify on again request on clicking on the Resend link OTP code should be sent to the user successfully or not.
  16. Verify whether the user should be temporarily blocked or not in case it requests for new OTP code again and again.
  17. Verify whether the limit is set for the OTP code to resend multiple times or not. (For example, a maximum of five attempts is allowed per user)
  18. Verify OTP code is case-sensitive or Not.
  19. Verify OTP code is only numeric or alphanumeric.