Thursday, 24 November 2022

Charactor_At_Position

public class Char_At_Position {



public static void main(String[] args) {
String str = "Wankhede";
String rev="";
//String rev1="";

System.out.println("String length="+str.length());
System.out.println("character at third position = "+str.charAt(2));
for(int i =str.length()-1;i>=0;i--)
{
char strrev = str.charAt(i);
rev = rev + strrev;
}
System.out.println("Reverse String = "+rev);
StringBuffer sb=new StringBuffer(rev);
sb.reverse();
rev=sb.toString();

System.out.println("Original String = "+rev);
}

}

--
With Warm REGARDS,

En. S. WANKHEDE

Find Duplicate Word in Two Strings

public static void main(String[] args) {
String str1 = "awankhede";
String str2 = "aaadeea";
char c = 0;
int i,w = 0;
int len1 = str1.length();
int len2 = str2.length();
for(i=0;i<=len1-1;i++)
{
for(int j=0;j<=len2-1;j++)
{
if(str1.charAt(i)==str2.charAt(j))
w++;
if(str1.charAt(i)==str2.charAt(j))
c=str1.charAt(i);

}

}

System.out.println("Duplicate character   " +c+"   number of times  "+(w+1));
}

--
With Warm REGARDS,

En. S. WANKHEDE

Number Reverse

public static void main(String[] args) {
int n=121;
int rev=0;
while(n!=0)
{
rev = rev*10+n%10;
n=n/10;
}
System.out.println(rev);
if(n==rev)
System.out.println("number is palindrome");
else
System.out.println("number is not palindrome");
}

--
With Warm REGARDS,

En. S. WANKHEDE

Number of Even and odd in given numbers


public static void main(String[] args) {
int n=12345;
int odd=0;
int even=0;
while(n!=0)
{
int r=n%10;
if(r%2==0)
{
even++;
}
else
{
odd++;
}
n=n/10;
}
System.out.println(even);
System.out.println(odd);
int n1=1000;
int c=0;
while(n1!=0)
{
n1=n1/10;
c++;
}
System.out.println(c);
}
--
With Warm REGARDS,

En. S. WANKHEDE

Removing White Spaces between string


public static void main(String[] args)
{
String str = "wan   khede";
StringBuffer sb = new StringBuffer();
char [] ch = str.toCharArray();
for(int i=0;i<=str.length()-1;i++)
{

if(ch[i]!=' ')
{
sb=sb.append(str.charAt(i));
}

}
String str1 = sb.toString();
System.out.println(str1);

}


 
--
With Warm REGARDS,

En. S. WANKHEDE

String Compare

 public static void main(String[] args) {
String str1="Wankhede";
String str2 = "Wankhede";
if(str1==str2)
{
System.out.println("String Equals");
}
else
{
System.out.println("String not Equals");
}


}




--
With Warm REGARDS,

En. S. WANKHEDE

String Swap Count_White Space Reverse String

public static void main(String[] args) {
String str1="Shivaji";
String str2 = "Wankhede";
String str3="wa    kh  ede";
int c=0;
System.out.println("string1="+str1);
System.out.println("string2="+str2);
str1=str1+str2;
str2= str1.substring(0,str1.length() - str2.length());
System.out.println("string2 "+str2);
str1=str1.substring(str2.length());
System.out.println("String1 "+str1);

// counting length of white spaces
for(int i=0;i<=str3.length()-1;i++)
{
if(str3.charAt(i)==' ')
{
c++;
}
}
System.out.println("Blank Spaces: " + c);

//Reverse string
String rev=" ";
for(int i=str2.length()-1;i>=0; i--)
{
rev = rev+str2.charAt(i);
}
System.out.println("reverse string : " + rev);

}

--
With Warm REGARDS,

En. S. WANKHEDE

Fwd: String Reverse and Palindrom



---------- Forwarded message ---------
From: En. S. Wankhede <shivaji.wankhede@gmail.com>
Date: Thu, Oct 20, 2022 at 8:38 PM
Subject: String Reverse and Palindrom
To: <shivaji.wankhede.java@blogger.com>



public static void main(String[] args) {
String str="Shivaji";
//String str1="Wankhede";
String str3 ="Wa  ";
String rev="";
int c = 0;
// char rev = 0;
int l=str.length();
for(int i=l-1;i>=0;i--)
{
rev = rev + str.charAt(i);
}
System.out.println("reverse string = "+rev);

if(str.equals(rev))
{
System.out.println("String is palandrom");
}
else
{
System.out.println("String is not palandrom");
}

for(int i=0;i<str3.length()-1;i++)
{
char ch = str3.charAt(i);
if(ch==' ')
{
c++;
}

}

System.out.println("number of white spaces="+c);


for(int i=0;i<str3.length()-1;i++)
{
char ch = str3.charAt(i);
if(ch==' ' && ch!=' '&&ch!='\t')
{
c++;
}

}
System.out.println("number of words="+c);
}




--
With Warm REGARDS,

En. S. WANKHEDE


--
With Warm REGARDS,

En. S. WANKHEDE

TestNG Code Samples POM.xml file Maven Project

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>TestNGFramework</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>TestNGFramework</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
</properties>

<dependencies>

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.5.3</version>
</dependency>


<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.3.1</version>

</dependency>


<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.6.0</version>

</dependency>



<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.8</version>
</dependency>

</dependencies>
</project>

--
With Warm REGARDS,

En. S. WANKHEDE

TestNG Project testng.xml file selenium Testing


<?xml version="1.0" encoding="UTF-8"?>
<suite name="suite 1" verbose="1" >
<test name="Regression suite 1" >

<listners>
<listner name="Listners.Listners"></listner>
</listners>


<classes>
<class name="ExtentReports.Load_Test"/>
<class name="ExtentReports.Window_Maximize"/>
<class name="ExtentReports.Check_Title"/>
<class name="ExtentReports.Check_User_Name"/>
<class name="ExtentReports.Check_Password_Box"/>
<class name="ExtentReports.Check_Logging_In"/>
<class name="ExtentReports.Check_Page_Info"/>
<class name="ExtentReports.Check_Drop_Down"/>
<class name="ExtentReports.Count_Cards"/>
<class name="ExtentReports.Add_To_Cart"/>
<class name="ExtentReports.Check_Menu_Button"/>
<class name="ExtentReports.Take_Screenschot"/>
</classes>

</test>
</suite>
--
With Warm REGARDS,

En. S. WANKHEDE

TestNG Project add_to_cart.java file test case code

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.openqa.selenium.By;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Add_To_Cart extends Load_Test{

@BeforeTest
public void before_add_to_cart(){

}

@Test
public void test_Add_to_cart(){
ExtentTest test = extent.createTest("Add To Cart Button Test ");
try{
driver.findElement(By.id("add-to-cart-sauce-labs-backpack")).click();
String text = driver.findElement(By.id("add-to-cart-sauce-labs-backpack")).getText();
if(text == "REMOVE"){
test.log(Status.INFO,"Add to cart button test: Pass");
extent.flush();
}
else{
test.log(Status.INFO,"Add to cart button test: Fail");
extent.flush();
}
}
catch (Throwable t){
System.out.println("Add to cart Exception: "+t);
}
}

@AfterTest
public void after_add_to_cart(){

}

}

--
With Warm REGARDS,

En. S. WANKHEDE

TestNG project Check_Drop_Down.java test case

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Check_Drop_Down extends Load_Test{

@BeforeTest
public void before_drop_down(){

}

@Test
public void Test(){
ExtentTest drop_test = extent.createTest("Drop Down Test");
try{
WebElement element = driver.findElement(By.xpath("/html/body/div/div/div/div[1]/div[2]/div[2]/span/select"));
Select select = new Select(element);
select.selectByIndex(3);
String option = element.getText();

drop_test.log(Status.INFO,"Selected drop down Option: "+option);
extent.flush();
}
catch (Throwable t){
//drop_test.log(Status.INFO,"Exception: "+t);
//extent.flush();
System.out.println("Drop Down Exception: "+t);
}
}

@AfterTest
public void after_drop_down(){

}
}

--
With Warm REGARDS,

En. S. WANKHEDE

TestNG Project Check_Logging_in.java test case

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.openqa.selenium.By;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Check_Logging_In extends Load_Test{

@BeforeTest
public void before_login(){

}


@Test
public void Login(){
ExtentTest login_test = extent.createTest("Login with USERNAME & PASSWORD Test");
try{
driver.findElement(By.id("user-name")).sendKeys("standard_user");
driver.findElement(By.id("password")).sendKeys("secret_sauce");
driver.findElement(By.id("login-button")).click();
String username = driver.findElement(By.id("user-name")).getText();
login_test.log(Status.INFO, "Username: "+username);
login_test.log(Status.INFO,"Logging in: Pass");
extent.flush();
}
catch (Throwable t){
//login_test.log(Status.INFO, "Exception: "+t);
//System.out.println("Exception: "+t);
System.out.println("Logging in: "+t);
}
}

@AfterTest
public void after_login(){

}
}

--
With Warm REGARDS,

En. S. WANKHEDE

TestNG Project check_menu_button.java file

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.util.List;

public class Check_Menu_Button extends Load_Test{

@BeforeTest
public void before_menu(){

}

@Test
public void test_Menu_Button(){
ExtentTest menu_test = extent.createTest("Menu_Button Test");

try{
driver.findElement(By.id("react-burger-menu-btn")).click();
List<WebElement> listelement = driver.findElements(By.className("bm-item-list"));
for (int i=0; i<listelement.size();i++){
menu_test.log(Status.INFO,"Menu: "+listelement.get(i).getText());
extent.flush();
}
menu_test.log(Status.INFO,"Menu List Check");
extent.flush();
}
catch (Throwable t){
System.out.println("Menu bar Exceptions: "+t);

}
}

@AfterTest
public void after_menu(){

}


}

--
With Warm REGARDS,

En. S. WANKHEDE

TestNG Project check_page_info..java file selenium test case

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.openqa.selenium.By;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Check_Page_Info extends Load_Test{

@BeforeTest
public void before_Page_Info(){

}

@Test
public void Test_Page_Info(){
ExtentTest page_test = extent.createTest("Page Test");

try{
String page_title = driver.findElement(By.className("title")).getText();
if(page_title == "PRODUCTS"){
page_test.log(Status.INFO,page_title+" - Page loaded: Pass");
page_test.log(Status.INFO, new Throwable());
extent.flush();
}
else{
page_test.log(Status.INFO,page_title+" - Page Not Loaded: Fail");
page_test.log(Status.INFO, new Throwable());
extent.flush();
}

}
catch (Throwable t){
page_test.log(Status.INFO,"Exception Generated: "+t);
System.out.println("Exception: "+t);
extent.flush();
}
}
}

--
With Warm REGARDS,

En. S. WANKHEDE

TestNG Project check_page_info.java file

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.openqa.selenium.By;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Check_Password_Box extends Load_Test{

@BeforeTest
public void before_pass(){

}
@Test
public void Test_pass(){
ExtentTest test5 = extent.createTest("Check Password TextBox");
if(driver.findElement(By.id("password")).isDisplayed()){
if (driver.findElement(By.id("password")).isEnabled()){
test5.log(Status.INFO,"Check password TextBox is Displayed: Pass");
test5.log(Status.INFO,"Check Password textBox is Enabled: Pass");
extent.flush();
}
else {
test5.log(Status.INFO, " Check password TextBox is Displayed: Pass");
test5.log(Status.INFO, " Check password TextBox is Enabled: Failed");
extent.flush();
}
}
else{
test5.log(Status.INFO, " Check password TextBox is Displayed: Failed");
test5.log(Status.INFO, "Check password TextBox is Enabled: Failed");
extent.flush();
}
}

@AfterTest
public void after_pass(){

}
}

--
With Warm REGARDS,

En. S. WANKHEDE

TestNG project check_user_name.java file

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.openqa.selenium.By;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Check_User_Name extends Load_Test {

@BeforeTest
public void Before_User_name(){

}

@Test
public void Test_User_name(){
ExtentTest test4 = extent.createTest("Check User Name Text Box");
if(driver.findElement(By.id("user-name")).isDisplayed()){
if(driver.findElement(By.id("user-name")).isEnabled()){
test4.log(Status.INFO,"User Name TextBox is Displayed: Pass");
test4.log(Status.INFO, "User Name TextBox is Enabled: Pass");


extent.flush();

}
else{
test4.log(Status.INFO,"User Name TextBox is Displayed: Pass");
test4.log(Status.INFO,"User Name TextBox is Enabled: Failed");
extent.flush();
}
}
else{
test4.log(Status.INFO, "User Name TextBox is Displayed: Failed");
test4.log(Status.INFO, "User Name TextBox is Enabled: Failed");
extent.flush();
}
}

@AfterTest
public void After_user_name(){

}

}

--
With Warm REGARDS,

En. S. WANKHEDE

TestNG Project Count_card.java file selenium project

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;

import com.aventstack.extentreports.Status;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.awt.*;
import java.util.List;

public class Count_Cards extends Load_Test{

@BeforeTest
public void before_count_cards(){

}

@Test
public void count_cards(){
ExtentTest card_test = extent.createTest("Card Count Test");
try{
List<WebElement> elementList = driver.findElements(By.className("inventory_item"));
for (int i = 0; i<elementList.size();i++) {
System.out.println(elementList.get(i));
card_test.log(Status.INFO,"Option: "+elementList.get(i).getText());
extent.flush();
}
card_test.log(Status.PASS,"Cards Count: "+elementList.size());
extent.flush();
}
catch (Throwable t){
//card_test.log(Status.INFO,"Exception: "+t);
//extent.flush();
System.out.println("Card Count Exception: "+t);
}
}

@AfterTest
public void after_count_card(){

}
}

--
With Warm REGARDS,

En. S. WANKHEDE

TestNG project reference file which is inherited by each test case file


TestNG project 

package ExtentReports;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.reporter.configuration.Theme;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Load_Test {

public static WebDriver driver;
public static ExtentReports extent;
public static ExtentSparkReporter spark;



@BeforeTest
public void initialize(){
extent = new ExtentReports();
spark = new ExtentSparkReporter("target/Spark/Spark.html");
spark.config().setReportName("Sample_Report_1");
spark.config().setDocumentTitle("Insurance Project Us Client ");
spark.config().setTheme(Theme.DARK);
spark.config().setEncoding("utf-8");
extent.attachReporter(spark);
}
@Test
public void load(){


}

@AfterTest
public void end(){
extent.flush();
}

}



--
With Warm REGARDS,

En. S. WANKHEDE

TestNG Project take screenschot test_case selenium project

package ExtentReports;

import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.testng.annotations.Test;

import java.io.File;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


public class Take_Screenschot extends Load_Test {


LocalDateTime dt = LocalDateTime.now();
DateTimeFormatter dt_format = DateTimeFormatter.ofPattern("dd-MM-yy HH:mm:ss");
String time_now = dt.format(dt_format);



@Test
public void test_screenschot(){
System.out.println("Time Now: "+time_now);
ExtentTest test = extent.createTest("Takeing Schreenschot.");

try{
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String path = "target/Spark/homePageScreenshot.png"+time_now;
FileUtils.copyFile(screenshot, new File("target/Spark/homePageScreenshot.png"));
test.log(Status.INFO, "target/Spark/homePageScreenshot.png");
extent.flush();
}
catch (Throwable t){
System.out.println("Exceptions: "+t);
}
}

}

--
With Warm REGARDS,

En. S. WANKHEDE

Charactor_At_Position

public class Char_At_Position { public static void main(String[] args) { String str = "Wankhede"; String rev=""...