Wednesday, March 22, 2023

Essential Points to Include in Your Checklist for Testing a Web Application

PDF - Testing of Web Application

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();

}

}