Hi there ,This is Mohit Kumar . I am an entrepreneur ,Software trainer,IT Job adviser and I am working in MNC as Sr Software engineer. We provide industry Level training (Automation Testing,Core Python Advanced python ,Manual Testing ,Development ....
Friday, October 15, 2021
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);
}
}
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
Course fee is 3000/
Duration 2 months
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:- ...
-
Our Syllabus =========================== Core java syllabus =================== A) Java Fundamentals:- ---------------------...
-
API Testing Syllabus for Manual & Automation ====================================== 1)Introduction of The Postman Tool 2)Installation...
-
Step1:- Creating a HashMap containing char as key and it's occurrences as value. Step2:- Converting given string to char array. Step3:- ...