Thursday, October 7, 2021

RestAssured Examples

 package RestAssuredNews.RestAssuredNewApp;

import org.testng.Assert;


import org.testng.annotations.Test;


import io.restassured.config.LogConfig;

import io.restassured.http.Header;

import io.restassured.http.Headers;

import io.restassured.path.json.JsonPath;

import io.restassured.response.Response;


import static io.restassured.RestAssured.*;

import static io.restassured.matcher.RestAssuredMatchers.*;

import static org.hamcrest.Matchers.*;


import java.util.Collections;

import java.util.HashMap;

import java.util.HashSet;

import java.util.List;

import java.util.Set;


import static org.hamcrest.MatcherAssert.assertThat;


public class GetAutomationTest {

public void testjava(){

}

@Test(enabled=false)

public void valiateStatusCode(){

given().

      baseUri("https://api.postman.com")

      .header("x-api-key","PMAK-606a8c2da5c08a004dfd060f-c7cdd622c690177cce465538021e349288").

when().

     get("/workspaces").

then()

.log().all()

.assertThat()

.statusCode(200);

}

@Test(enabled=false)

public void validate_response_body(){

given().baseUri("https://api.postman.com")

.header("x-api-key", "PMAK-606a8c2da5c08a004dfd060f-c7cdd622c690177cce465538021e349288")

.when().get("/workspaces")

.then().log().all()

.assertThat().statusCode(200)

.body("workspaces.name",hasItems("APITesting","MyMockServer","My Workspace2","Team Workspace",

"myworkspace")

,"workspaces.type",hasItems("team","team","team","team"),

"workspaces[0].name",equalTo("APITesting")

,"workspaces[0].name",is(equalTo("APITesting"))

,"workspaces.size()",equalTo(5)

,"workspaces.name",hasItem("APITesting"));

}

   @Test(enabled=false)

   public void extract_response(){

  Response res= given().baseUri("https://api.postman.com")

   .header("x-api-key", "PMAK-606a8c2da5c08a004dfd060f-c7cdd622c690177cce465538021e349288")

   .when()

    .get("/workspaces")

    .then()

    .assertThat()

    .statusCode(200)

    .extract().response();

  System.out.println("Response = " + res.asString());

   }

   

   @Test(enabled=false)

   public void extract_single_value_from_response(){

String name=  given().baseUri("https://api.postman.com")

   .header("x-api-key", "PMAK-606a8c2da5c08a004dfd060f-c7cdd622c690177cce465538021e349288")

   .when()

    .get("/workspaces")

    .then().assertThat()

    .statusCode(200)

    .extract()

    .response().path("workspaces[0].name");

System.out.println("workspace name = " + name);

// JsonPath.from(res).getString("workspaces[0].name");

//System.out.println("workspace name = " + JsonPath.from(res).getString("workspaces[0].name"));

 

 

   //System.out.println("workspace name = " + res.path("workspaces[0].name"));

//JsonPath js=new JsonPath(res.asString());

// System.out.println("workspace name = " + js.getString("workspaces[0].name"));

 

   }

   

   @Test(enabled=false)

   public void hamcrest_assert_on_extracted_response(){

   String name =given().baseUri("https://api.postman.com")

   .header("x-api-key", "PMAK-606a8c2da5c08a004dfd060f-c7cdd622c690177cce465538021e349288")

   .when()

    .get("/workspaces")

    .then()

    .assertThat()

    .statusCode(200)

    .extract()

    .response().path("workspaces[0].name");

 

   System.out.println("workspace name=" + name);

  // assertThat(name,equalTo("APITesting"));

   Assert.assertEquals(name, "APITesting");

   

   }

   

   @Test(enabled=false)

   public void validate_response_body_hamcrest_learning(){

   given()

   .baseUri("https://api.postman.com")

   .header("x-api-key", "PMAK-606a8c2da5c08a004dfd060f-c7cdd622c690177cce465538021e349288")

   .when()

    .get("/workspaces")

    .then()

    .assertThat()

    .statusCode(200)

    .body("workspaces.name",contains("APITesting","MyMockServer","My Workspace2",

    "Team Workspace","myworkspace"),"workspaces.name",is(not(emptyArray()))

    ,"workspaces.name",hasSize(5)

    //,"workspaces.name",everyItem(startsWith("My"))

   

    ,"workspaces[0]",hasKey("id")

    ,"workspaces[0]",hasValue("APITesting")

    ,"workspaces[0]",hasEntry("id","1f44f446-31d0-429e-8e92-ed6fdb17934b")

    ,"workspaces[0]",not(equalTo(Collections.EMPTY_MAP))

    ,"workspaces[0].name",allOf(startsWith("API"),containsString("Testing")));

   

   }

   

   @Test(enabled=false)

   public void request_response_logging(){

   given()

    .baseUri("https://api.postman.com")

    .header("x-api-key", "PMAK-606a8c2da5c08a004dfd060f-c7cdd622c690177cce465538021e349288")

    .config(config.logConfig(LogConfig.logConfig().enableLoggingOfRequestAndResponseIfValidationFails()))

    //.log().ifValidationFails()

        .when()

        .get("/workspaces")

        .then()

        //log().ifValidationFails().

        .assertThat()

        .statusCode(201);

   

   }

   

   @Test(enabled=false)

   public void log_blacklist_header(){

   Set<String> headers=new HashSet<String>();

   headers.add("x-api-key");

   headers.add("Accept");

   given()

    .baseUri("https://api.postman.com")

    .header("x-api-key", "PMAK-606a8c2da5c08a004dfd060f-c7cdd622c690177cce465538021e349288")

    .config(config.logConfig(LogConfig.logConfig().blacklistHeaders(headers)))

    .log().all()

    .when()

    .get("/workspaces")

    .then()

    .assertThat()

    .statusCode(200);

   }

   

   @Test(enabled=false)

   public void multiple_headers(){

   HashMap<String,String> headers=new HashMap<String,String>();

   headers.put("header", "value1");

   headers.put("x-mock-match-request-headers", "header");

   given()

    .baseUri("https://5e6acb5c-eb77-40a9-ac40-7dfc335f8288.mock.pstmn.io").

   // headers(headers).

    header("multiValueHeader","value1","value2").

    log().headers().

   when() 

    .get("/get")

    .then()

        .log().all()

        .assertThat()

        .statusCode(200);

  }

   

   

   @Test(enabled=false)

   public void multi_value_in_the_request(){

   Header header1=new Header("multiValueHeader","value1");

   Header header2=new Header("multiValueHeader","value2");

   

   Headers headers=new Headers(header1,header2);

   

   given().

    baseUri("https://5e6acb5c-eb77-40a9-ac40-7dfc335f8288.mock.pstmn.io")

    .headers(headers)

    .log().headers().

   when().

    get("/get")

    .then()

    .log()

    .all()

    .assertThat()

    .statusCode(200);

      } 

   

   @Test(enabled=false)

   public void asser_response_headers(){

   HashMap<String,String> headers=new HashMap<String,String>();

   headers.put("header","value1");

   headers.put("x-mock-match-request-headers","header");

   given()

    .baseUri("https://5e6acb5c-eb77-40a9-ac40-7dfc335f8288.mock.pstmn.io").

    headers(headers).

   

    when()

    .get("/get").

    then().

    log().all().

    assertThat()

    .statusCode(200).

    //header("responseHeader","resValue1").

            //header("X-RateLimit-Limit","120");

    headers("responseHeader","resValue1","X-RateLimit-Limit","120");

   }  




  @Test(enabled=false)

  public void extract_response_headers(){

  HashMap<String,String> headers=new HashMap<String,String>();

  headers.put("header","value1");

   headers.put("x-mock-match-request-headers","header");

   Headers extractedheaders=given()

    .baseUri("https://5e6acb5c-eb77-40a9-ac40-7dfc335f8288.mock.pstmn.io").

    headers(headers).

    when().get("/get").

    then().

    log().all()

    .assertThat()

    .statusCode(200)

    .extract()

    .headers();

   for(Header header:extractedheaders){

   System.out.println("header name = " + header.getName() + " ,");

   System.out.println("header value = " + header.getValue());

   }

/*

System.out.println("header name = " + extractedheaders.get("responseHeader").getName());

System.out.println("header value = " + extractedheaders.get("responseHeader").getValue());

System.out.println("header value = " + extractedheaders.getValue("responseHeader"));

*/

  }

  

  @Test

  public void extract_multivalue_response_header(){

  HashMap<String,String> headers=new HashMap<String,String>();

  headers.put("header","value1");

   headers.put("x-mock-match-request-headers","header");

   Headers extractedheaders=given()

    .baseUri("https://5e6acb5c-eb77-40a9-ac40-7dfc335f8288.mock.pstmn.io").

    headers(headers).

    when().get("/get").

    then().

    //log().all()

    assertThat()

    .statusCode(200)

    .extract()

    .headers();

   List<String> values=extractedheaders.getValues("multiValueHeader");

   for(String value:values){

   System.out.println(value);

   }    }}

 


 

   

   


Saturday, May 1, 2021

How to Handle bootstrap drop down and make reusable method add in framework

 package com.seleniumpractice1;


import java.util.List;

import java.util.concurrent.TimeUnit;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


import com.businesslib.Helper;


public class BoostrapTest extends Helper{


public static void main(String[] args) {

/*

System.setProperty("webdriver.chrome.driver","D:\\driver1016\\driver\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

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

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

driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

driver.findElement(By.xpath("//input[@id='ctl00_mainContent_ddl_originStation1_CTXT']")).click();

List<WebElement> list=driver.findElements(By.xpath("//div[@id='glsctl00_mainContent_ddl_originStation1_CTNR']//li"));

for(int i=0;i<list.size();i++){

String str=list.get(i).getText();

System.out.println(str);

if(str.equalsIgnoreCase("Aurangabad (IXU)")){

list.get(i).click();

break;

}

}

*/

Helper.lauchApp();

Helper.selectCity("//input[@id='ctl00_mainContent_ddl_originStation1_CTXT']","//div[@id='glsctl00_mainContent_ddl_originStation1_CTNR']//li","Aurangabad (IXU)");

//Helper.selectCity(xpath1, xpath2, city);


}


}

==============================================
package com.businesslib;

import java.util.List;
import java.util.concurrent.TimeUnit;

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.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Helper {
public static WebDriver driver;
/**
* This Method is used to launch app
*/
public static void lauchApp(){
System.setProperty("webdriver.chrome.driver","D:\\driver1016\\driver\\chromedriver.exe");
driver=new ChromeDriver();
//driver.get("http://demo.guru99.com/test/newtours/register.php");
driver.get("https://www.spicejet.com/");
driver.manage().window().maximize();
}


public static void selectCity(String xpath1,String xpath2,String city){
driver.findElement(By.xpath(xpath1)).click();
List<WebElement> listofStr=driver.findElements(By.xpath(xpath2));
for(int i=0;i<listofStr.size();i++){
String str=listofStr.get(i).getText();
if(str.equalsIgnoreCase(city)){
listofStr.get(i).click();
break;
}
}
}

Saturday, March 27, 2021

How to create Re-usable Method for Verify getText(),Click()and SendKeys() and Add your framework

Step1:- Create Helper class  

package com.businesslib;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


public class Helper {

public static WebDriver driver;

/**

* This Method is used to launch app

*/

public static void lauchApp(){

System.setProperty("webdriver.chrome.driver","D:\\driver1016\\driver\\chromedriver.exe");

driver=new ChromeDriver();

driver.get("https://in.yahoo.com/");

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

}

/**

* This Method is used to verify the title of page

* @param ExpectedTite is String Type

*/

public static String verifyTiteOfPage(String expectedtitle){

String titleOfPage=driver.getTitle();

System.out.println("TitleOf Page::" + titleOfPage);

if(titleOfPage.equals(expectedtitle)){

System.out.println("Title is matched");

}

else{

System.out.println("Title is not matched");

}

return titleOfPage;


}

/**

* This Method is used to maxmize browser

*/

public static void maxmizeBroser(){

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

}

/**

* This Method is used to getCurrentUrl

*/

public static String getcurrentUrl(){

String getcurrenturl=driver.getCurrentUrl();

System.out.println("getcurrenturl:::" + getcurrenturl);

return getcurrenturl;

}

/**

* This Method is used to getpageSourse

*/


public static String getpageSourse(){

String getpageSourse=driver.getPageSource();

System.out.println("getpageSourse:::" + getpageSourse);

return getpageSourse;

}

/**

* This Method is used to getTitleofpage

*/


public static String gettitleOfpage(){

String titleofpage=driver.getTitle();

System.out.println("titleofpage::" + titleofpage);

return titleofpage;

}

/**

* This Method is used to close the browser

*/

public static void closeBrowser(){

driver.close();

}

/**

* This Method is used to capture text on webpage

*/

public static String getTextMessage(String xpath) throws InterruptedException{

Thread.sleep(2000);

String gettext=driver.findElement(By.xpath(xpath)).getText();

System.out.println(gettext);

return gettext;

}

/**

* This Method is used to click on webpage

*/

public static void clickOnPage(String xpath){

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

}

/**

* This Method is used to Enter vale in text Field

*/

public static void enterValueInTextField(String xpath,String str){

driver.findElement(By.xpath(xpath)).sendKeys(str);

}

public static String verifyStringText(String xpath,String expcted){

String actualValue=driver.findElement(By.xpath(xpath)).getText();

if(expcted.equals(actualValue)){

System.out.println("Text is Matched & Test case passed");

}

else{

System.out.println("Text is Matched & Test case passed");

}

return actualValue;

}


}

=======================================================================

Step 2:- Test Runner class 

package com.seleniumpractice;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


import com.businesslib.Helper;


public class VerifyErrorMessage extends Helper {


public static void main(String[] args) throws InterruptedException {

/*

System.setProperty("webdriver.chrome.driver","D:\\driver1016\\driver\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://in.yahoo.com/");

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

*/

Helper.lauchApp();

Helper.clickOnPage("//span[contains(text(),'Sign in')]");

//driver.findElement(By.id("login-username")).sendKeys("mohit123");

Helper.enterValueInTextField("//input[@id='login-username']","mohit123");

//driver.findElement(By.id("login-signin")).click();

Helper.clickOnPage("//input[@id='login-signin']");

//String errorMessage=driver.findElement(By.id("username-error")).getText();

//System.out.println("errorMessage::" + errorMessage);

//WebElement element=driver.findElement(By.id("username-error"));

Helper.getTextMessage("//*[@id='username-error']");

Helper.verifyStringText("//*[@id='username-error']","Sorry, we don't recognise this email address.");

}


}








Friday, March 19, 2021

Interview questions for Automation Test Engineer

 Interview question for Automation Test Engineer 4 to 5 year

1)Oracle India Pvt Ltd Interview question

1)WAP 

Str="This is Mohit";

O/P:- ThIS IS MohIT;


2)WAP 

int[] arr={1,2,3,0,0,12};

O/P:- {1,2,3,12,0,0}


3)What is encapsulation in java?

4)What is Interface and abstract class ?

5)What is abstraction?

6)What is Singleton & Serialization in java ?




 Pega System

1)WAP 

int[] arr={1,2,3,0,0,12};

O/P:- {1,2,3,12,0,0}


2)Write X-path for below 

<div>

<span>pega------test</span>

<span>pega------</span>

<span>-----test</span>

</div>


3)How to handle multiple window (Do validation for 5)

4)How to Execute failure test cases in Jenkins

5)We have 100 test cases out 3 we have to do db connection

6)What is plugins and dependency 

7)What is default defect 

8)What is tractability matrix 


Saturday, February 27, 2021

API Testing Syllabus for Manual & Automation

 API Testing Syllabus for Manual & Automation

======================================

1)Introduction of The Postman Tool 

2)Installation of Postman Tool 

3)What is GET Method with realTime example

4)What is POST Method with realTime example

5)What is PUT Method with realTime example

6)What is DIfference Between Put and Patch HTTP Methods

7)What is Sending DELETE Request in Postman.

8)Understand Environment & Variables in Postman

9) Adding Automation Test Scripts In Postman

10)Working with Data driven Testing in Postman

11)How to use variable in Postman 

12)Another way to use collection variables 

13)Authorization & Type of Authorization 

14)What is API Key Authorization?

15)What is Bearer Token?

16)What is Oauth 2.0?

RestAssured 

==============

1)Introduction to REST Assured

2) Project Set up in Eclipse IDE

3)Write First  Program for GET REST Assured Test

4)Write First Program POST Request in REST Assured

5)Write First Program PUT Request in REST Assured

6)Write First Program  PATCH Request in REST Assured

7)Write First Program  DELETE Request in REST Assured

8)How to write API Response in a JSON File

9)What is RequestSpecification 

10) How to Send a JSON/XML File as Payload to Request

11)Creating JSON Object Request Body Using Java Map

 12)How To Create a JSON Object Using Jackson API – ObjectMapper – 


createObjectNode()

13)How To Use Java Object As Payload For API Request

14)How To Create JSON Array Using Jackson API – ObjectMapper – CreateArrayNode()

15)What is Plain Old Java Object (POJO) ?

16)How to create POJO classes of a JSON Object Payload

17)How To Create POJO Classes Of A JSON Array Payload

18)How To Create POJO Classes Of A Nested JSON Payload

19)Serialization – Java Object To JSON Object Using Jackson API

20)De-Serialization – JSON Object To Java Object Using Jackson API

21)Serialization – Java Object To JSON Object Using Gson API

22)De-Serialization – JSON Object To Java Object Using Gson API

23)What is JSON Schema?

24)JSON Schema Validation in Rest Assured

25)How To Create JsonPath For Simple And Nested JSON Array?

26)write JsonPath expressions or JsonPath syntax

27)How To Parse A JSON Array Response To A Java List In Rest Assured?

28)Framework Development 

29)Mock Interview + Resume Preparation 


Core java 

A) Java Fundamentals:-
---------------------
1)Identifiers
2)Reserve words
3)Datatypes
4)Literals
5)Type Conversion
6)Type Casting 
7)Arrays
8)Types of Variables
9)Types of Methods
10)Coding Standard
b)Java Language concepts:-
-------------------------
1)Packages
2)Accessibility
3)Variables and types of variables with respect to Execution
Modifiers
4)Methods and types of variables with respect to Execution
Modifiers
5)Block and types of Block
6)Class and types of Class
7)New keyword and constructor and types
8)static Members and their control flow
10)static and non-static members control flow including super
class
11)final variables and their rules
12)this and super keywords rule and use
13)Compiler responsibility and Compiler code conversion
14)JVM Architecture and responsibility
15)OOPs fundamentals,concepts and Principle
16)Types of Object and Garbage Collection
17)Inner Classes
18)Arrays and Var-args types
19)Control Statement
20)Collections
23)Wrapper Classes
24)Exception Handling
25)string Handling

Course fee is 3000/

Duration 2 months 



Sunday, November 15, 2020

Manual Testing Syllabus

 Manual Testing Syllabus

=======================

What is Project?

What is Product?

What is Quality?

What is Defects?

What is Testing?

What is kick of meeting?

PIN(Project initial node)?

Software Development Lifecycle(SDLC):-(V.V.I)

Test Methodology :-

1)Black box Testing

2)Grey box Testing

3)White box & glass

Levels Of testing

1)Unit level testing

2)Module level testing

3)Integration level testing

4)System level Testing

5)User acceptance level testing

Types of Environment

1)Single type architechire(stand alone)

2)Two Tier architechire

3)Three Tier architechture:-

4)N Tier architechture

Q)What is a Software Build?

Types of Testing

Smoke Testing

Sanity Testing

static testing

Stability Testing

dyanamic Testing

Compatibility Testing(suitable)

Alpha Testing

Beta Testing

Adhoc Testing

Reliability Testing

Retesting

Regression Testing

Security Testing

Authentication Testing

URL testing

Firewall Testing

Exploratory Testing

End to End Testing

Load Testing

Installation Testing

Non-functional Testing

Survivability

Scalability

Usability

Speed

Performance Testing

Types of Performance Testing.

1)Load testing

2)Stress testing

3)Endurance testing

4)Volume testing

5)Scalability testing.

6)Endurance Testing

What is funcational Testing?

Types of Functional testing are

================================

Unit Testing

Smoke Testing

Sanity Testing

Integration Testing

White box testing

Black Box testing

User Acceptance testing

Regression Testing.

Globalization Testing?

Localization Testing

Positive Testing

Negative Testing

Pilot Testing

Types of Model

===============

1)Waterfall Model

2)Prototype Model

3)Evoluting Model

4)Spiral Model

5)fish Model

6)V Model

7)Agile Model

8)Incremental Model.

eXtreme Programming (XP)?

Software Testing Lifecyscle(STLC)

=================================

It contains 6 phases:-

-------------------------

1)Test Planning

2)Test Design | Test development

3)Test Execution

4)Result Analysis

5)Bug Tracking and Reporting

6)Closer activity|Exit activity.

Guidines to understanding the FRS document:-

=============================================

Test Scenario:-

================

How to create a Test Scenario.

Test Case

==========

What is Test Case?

Types of Test cases :-

=======================

1)GUI Test cases

2)Funcational Test cases

3)Non-Funcational Test cases

Non Funcationality Test cases:-

a)Compatability Testing.

b)Performance Testing

c)Usability Testing

d)Installation Testing.

Guidlines for writing the positive test case:-

==============================================

Guidlines for writing the negative test cases:-

=================================================

Q)What is Test Design Technique

=================================

1)Boundry value Analysis

--------------------------

2)Equivalence Partition (EP)

3)Q)What is Traceability Matrix?(TM)

Q)What is RTM (Requirement Traceability Matrix)?

Requirement Traceability Matrix – Parameters include

=====================================================

1)Requirement ID

2)Requirement Type and Description

3)Trace to design specification

4)Unit test cases

5)Integration test cases

6)System test cases

7)User acceptance test cases

8)Trace to test script

How to create Requirement Traceability Matrix

=================================================

Test Execution

================

Result Analysis

================

Bug tracking & Reporting

=========================

1)What is Bug?

Q)What is Defect?

While reporting the bug to developer, your Bug Report should

contain the following information

==========================================================

Q)What is Defect life cycle?

Defect life cycle stages

=========================

Q)What is Priority?

Defect severity can be categorized into four class

=====================================================

Defect priority can be categorized into three class

======================================================

Bug Tracking tool

==================

BUGZILLA

============

Software Test Engineer Responsibilites:-

=========================================

Test lead Responsiblility

==========================

Quality Center

Course fee is 10000/ only 

Saturday, November 7, 2020

How to handle Dynamic table

 Q)How to handle Dynamic table and Create Re-usable method and add in framework.

package com.seleniumpractice;


import java.util.List;

import java.util.concurrent.TimeUnit;


import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;


import com.businesshelper.Helper;


public class Dyamictable extends Helper{


public static void main(String[] args) {

/*

System.setProperty("webdriver.chrome.driver","D:\\driver1016\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

driver.get("https://www.redbus.in/");

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

driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

*/

Helper.launchApp();

driver.findElement(By.xpath("//button[contains(text(),'Search Buses')]/preceding::span[1]")).click();

Helper.selectDate(driver,"10");

/*

List<WebElement> list=driver.findElements(By.xpath("//table[@class='rb-monthTable first last']/tbody//td"));

for(int i=0;i<list.size();i++){

String strlist=list.get(i).getText();

System.out.println("strlist-->" + strlist);

if(strlist.equals("10")){

list.get(i).click();

break;

}

*/


}


}

=========================================================================

package com.businesshelper;


import java.util.List;


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.interactions.Actions;


public class Helper {

public static WebDriver driver;

public static String driverPath="D:\\driver1016\\chromedriver.exe";

public static String url="https://www.redbus.in/";

public static List<WebElement> listofCheckbox;

public static void launchApp(){

System.setProperty("webdriver.chrome.driver",driverPath);

driver=new ChromeDriver();

driver.get(url);

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

}

public static boolean verifyisSeleted(WebElement ele){

boolean status= ele.isSelected();

if(status){

System.out.println("CheckBox is selected");

}

else{

System.out.println("CheckBox is not selected");

}

return status;

}

/*

public static void multipleCheckbox(){

listofCheckbox=driver.findElements(By.xpath("//input[@type='checkbox']"));

for(WebElement listele:listofCheckbox){

listele.click();

}

}

*/

public static boolean isDisplayedRadiobtn(WebElement ele){

boolean eleisisplaye=ele.isDisplayed();

if(eleisisplaye){

System.out.println("Radio Button is Displayed ");

}

else{

System.out.println("Radio Button is not Displayed ");

}

return eleisisplaye;

}

public static boolean isEnabledRadioButton(WebElement ele){

boolean eleisEnabled=ele.isEnabled(); 

if(eleisEnabled){

System.out.println("Radio Button is Enabled ");

}

else{

System.out.println("Radio Button is not Enabled");

}

return eleisEnabled;

}

public static void ClickWithActions(WebElement ele){

Actions act=new Actions(driver);

act.moveToElement(ele).click().perform();

}

public static void selectDate(WebDriver driver,String str){

List<WebElement> list=driver.findElements(By.xpath("//table[@class='rb-monthTable first last']/tbody//td"));

for(int i=0;i<list.size();i++){

String strlist=list.get(i).getText();

if(strlist.equals("10")){

list.get(i).click();

break;


}

}

}


}

====================================================================

Q) How to handle Dynamic table in Selenium


package Selenium.SeleniumTest;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class WebTable {

public static void main(String[] args) {
    System.setProperty("webdriver.chrome.driver","D:\\driver1016\\chromedriver.exe\\");
    WebDriver driver=new ChromeDriver();
    driver.get("https://www.w3schools.com/html/html_tables.asp");
  //*[@id="customers"]/tbody/tr[2]/td[1]
  //*[@id="customers"]/tbody/tr[3]/td[1]
  //*[@id="customers"]/tbody/tr[4]/td[1]
  //*[@id="customers"]/tbody/tr[6]/td[1]
    
  //*[@id="customers"]/tbody/tr[2]/td[2]
  //*[@id="customers"]/tbody/tr[3]/td[2]
  //*[@id="customers"]/tbody/tr[4]/td[2]
  //*[@id="customers"]/tbody/tr[5]/td[2]
  //*[@id="customers"]/tbody/tr[2]/td[3]
    
    String beforeXpath_compnay="//*[@id='customers']/tbody/tr[";
    String afterXpath_company="]/td[1]";
    
    String beforeXpath_contact="//*[@id='customers']/tbody/tr[";
    String afterXpath_contact="]/td[2]";
    
    String beforeXpath_country="//*[@id='customers']/tbody/tr[";
    String afterXpath_country="]//td[3]";
    
    List<WebElement> rows=driver.findElements(By.xpath("//table[@id='customers']//tr"));
    System.out.println("Total number of rows = " + (rows.size()-1));
     int rowCount=rows.size();
     
     //Xls_Reader reader=new XlsReader();
     
     
    for(int i=2;i<=rowCount;i++){
    String actualXpath_comapnayName=beforeXpath_compnay+i+afterXpath_company;
    String companyName=driver.findElement(By.xpath(actualXpath_comapnayName)).getText();
    System.out.println(companyName);
   
    String actualXpathcoustomer=beforeXpath_contact+i+afterXpath_contact;
    String contactName=driver.findElement(By.xpath(actualXpathcoustomer)).getText();
    System.out.println(contactName);
   
    String actualXpath_country=beforeXpath_country+i+afterXpath_country;
    String countryName=driver.findElement(By.xpath(actualXpath_country)).getText();
    System.out.println(countryName);
   
    }
}

}






Q) How To Find Duplicate Characters In A String In Java?

Step1:- Creating a HashMap containing char as key and it's occurrences as value. Step2:- Converting given string to char array. Step3:- ...