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

TestNG Project Follder Structure for TestNG Project in selenium java.



--
With Warm REGARDS,

En. S. WANKHEDE

TestNG and WebDriver Methods tobe used in selenium java software test engine





Types Of Commands in WebDriver:

1) get() Methods


>> driver.get("https://google.com");
>> driver.getClass();
>> driver.getCurrentUrl();
>> boolean result = driver.getPageSource().contains("String to find");
>> String title = driver.getTitle();
>> String Text = driver.findElement(By.id("Text")).getText();
>> driver.findElement(By.id("findID"));
getAttribute("value");

>> private String winHandleBefore;
winHandleBefore = driver.getWindowHandle();
driver.switchTo().window(winHandleBefore);
>> getWindowHandles();

2) Locating links by linkText() and partialLinkText():

>> driver.findElement(By.linkText("Google")).click();
>> driver.findElement(By.linkText("abodeQA")).click();

>> driver.findElement(By.partialLinkText("Goo")).click();
>> driver.findElement(By.partialLinkText("abode")).click();


3) Selecting multiple items in a drop dropdown:

i. Single select dropdown: A drop-down that allows only single value to be selected at a time.
ii. Multi-select dropdown: A drop-down that allows multiple values to be selected at a time.

>> // select the multiple values from a dropdown
Select selectByValue = new Select(driver.findElement(By.id("SelectID_One")));
selectByValue.selectByValue("greenvalue");
selectByValue.selectByVisibleText("Red");
selectByValue.selectByIndex(2);

4) Submitting a form:


>> // enter a valid username
driver.findElement(By.<em>id</em>("username")).sendKeys("name");

// enter a valid email address
driver.findElement(By.<em>id</em>("email")).sendKeys("name@abc.com");

// enter a valid password
driver.findElement(By.<em>id</em>("password")).sendKeys("namepass");

// re-enter the password
driver.findElement(By.<em>id</em>("passwordConf")).sendKeys("namepass");

// submit the form
driver.findElement(By.<em>id</em>("submit")).submit();

5) Handling iframes:


Select iframe by id:
>> driver.switchTo().frame("ID of the frame");

Select iframe by id:
>> driver.switchTo().frame(driver.findElements(By.tagName("iframe").get(0));

Locating iframe using the index:

a) frame(index)
>> driver.switchTo().frame(0);

b) frame(Name of Frame)
>> driver.switchTo().frame("name of the frame");

c) frame(WebElement element)
Select Parent Window
>> driver.switchTo().defaultContent();

6) close() and quit() methods:

>> driver.close(); // closes only a single window that is being accessed by the WebDriver instance currently
>> driver.quit(); // closes all the windows that were opened by the WebDriver instance

7) Exception Handling:

>> try{

}
catch (Exception e)
{

}

>> try{

}
catch (Exception1 e)
{

}
catch (Exception2 e)
{

}
catch (Exception3 e)
{

}

>> WebElement saveButton = driver.findElement(By.id("Save"));
try{
if(saveButton.isDisplayed()){
saveButton.click();
}
}
catch(NoSuchElementException e){
e.printStackTrace();
}

Samples:

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

>> driver.getCurrentUrl();
Assert.assertEquals(expectedUrl, driver.getCurrentUrl());

>> driver.findElement(By.id("submit1")).click();

>> WebElement roleDropdown = driver.findElement(By.id("name1");
roleDropdown.click();

>> boolean textBox = driver.findElement(By.xpath("//input[@name='textbox1']")).isEnabled();
>> driver.findElement(By.name("name")).sendkeys("Aaron");
>> String dropDown = driver.findElement(By.tagName("dropdown1")).getText();

>> driver.findElement(By.xpath("//input[@name='comments']")).submit();

>> List<WebElement> allChoices = dropDown.findElements(By.xpath(".//fruitoption"));

>> Boolean checkIfElementPresent= driver.findElements(By.xpath("//input[@id='checkbox2']")).size()!= 0;

>> driver.manage().timeouts().pageLoadTimeout(500, SECONDS);

>> driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);

>> WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated (By.xpath("//input[@id='name']")));

>> WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.alertIsPresent()

>> String title = driver.getTitle();
System.out.println(title);

>> WebElement mySelectedElement = driver.findElement(By.id("select"));
Select dropdown= new Select(mySelectedElement);
dropdown.selectByVisibleText("Apple");

>> WebElement mySelectedElement = driver.findElement(By.id("select"));
Select dropdown= new Select(mySelectedElement);
Dropdown.selectByValue("Apple")


>> WebElement mySelectedElement = driver.findElement(By.id("select"));
Select dropdown= new Select(mySelectedElement);
listbox.selectByIndex(1);

>> WebElement mySelectedElement = driver.findElement(By.id("select"));
Select dropdown= new Select(mySelectedElement);
dropdown.deselectByVisibleText("Apple");

>> WebElement mySelectedElement = driver.findElement(By.id("select"));
Select dropdown= new Select(mySelectedElement);
Dropdown.deselectByValue("Apple");

>> WebElement mySelectedElement = driver.findElement(By.id("select"));
Select dropdown= new Select(mySelectedElement);
listbox.deselectByIndex(1);

>> driver.navigate().to("https://www.softwaretestinghelp.com");
driver.navigate().back();
driver.navigate().forward();

>> File shot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(shot, new File("D:\\ shot1.jpg"));

>> Actions actions = new Actions(driver);
WebElement mouseHover = driver.findElement(By.xpath("//div[@id='mainmenu1']/div"));
actions.moveToElement(mouseHover);
actions.perform();

>> WebElement sourceLocator = driver.findElement(By.xpath("//*[@id='image1']/a"));
WebElement destinationLocator = driver.findElement(By.xpath("//*[@id='stage']/li"));
Actions actions=new Actions(driver);
actions.dragAndDrop(sourceLocator, destinationLocator).build().perform();

>> Alert alert = driver.switchTo().alert();
alert.sendKeys("This Is Softwaretestinghelp");
alert.accept();

>> String handle= driver.getWindowHandle();
Set<String> handle= driver.getWindowHandles();

>> for (String handle : driver.getWindowHandles()){
driver.switchTo().window(handle);
}

>> DriverManager.getConnection(URL, "username", "password" )

>> Workbook workbook = WorkbookFactory.create(new FileInputStream(file));
Sheet sheet = workbook.getSheetAt(0);

>> Assert.assertEquals(message, "This text");
Assert.assertNotEquals(message, "This text");
Assert.assertTrue(result<0);
Assert.assertFalse(result<0);

>> driver.close()
driver.quit()

>> JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("scrollBy(0, 4500)");

>> driver.navigate().refresh();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().to("https://javatpoint.com/selenium-tutorial");

>> driver.switchTo().window("windowName");
driver.switchTo().frame("frameName");

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

>> Actions act = new Actions(driver);
act.dragAndDrop(from,to).build().perform();

>> driver.switchTo().alert().accept();
driver.switchTo().alert().getText();
driver.switchTo().alert().sendKeys("Text");

>> driver.findElement(By.linkText("Generate Alert Box")).click();
Alert alert = (Alert) driver.switchTo().alert();
alert.accept();
driver.findElement(By.linkText("Generate Confirm Box")).click();
Alert confirmBox = (Alert) driver.switchTo().alert();
((Alert) confirmBox).dismiss();

>> driver.findElement(By.xpath("//input[@value='Banana']")).click();

>> int a = driver.findElements(By.xpath("//input [@name='group1']")).size();
System.out.println(a);
for(int i=1;i<=a;i++)
{
driver.findElements(By.xpath("//input[@name='group1']")).get(2).click();
}


https://www.javatpoint.com/software-testing-tutorial
















--
With Warm REGARDS,

En. S. WANKHEDE

Fwd: TestNG Listners.xml file


TestNG Listners.xml file

package Listners;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
public class Listners extends TestListenerAdapter{

@Override
public void onTestStart(ITestResult result) {
super.onTestStart(result);
System.out.println("Test Started.");
}

@Override
public void onTestSuccess(ITestResult tr) {
super.onTestSuccess(tr);
System.out.println("Test Success.");
}

@Override
public void onTestSkipped(ITestResult tr) {
super.onTestSkipped(tr);
System.out.println("Test Skiped.");
}

@Override
public void onTestFailure(ITestResult tr) {
super.onTestFailure(tr);
System.out.println("Test Failed.");
}


}

--
With Warm REGARDS,

En. S. WANKHEDE


--
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=""...