Posts

Framework- RestAssured API - Layers/Components

Image
 FrameWork - High Level Design Pattern +Hybrid DD -  RestAssured API RestClients.java - > Custom utility ,We have generic Methods  Rest Specifications and CRUD methods GET().PUT().POST().DELETE(),PATCH() - returnds Response Wrapper method we create top of RestAssured  Reusability we have methods  Cofig.properties baseUrl,clientId,ClientSecret,APIKEY,Bearer TOKEN,USerName,Password,Token TestLayer - TestNG TestCases: Classes with TestNg layer ->assertions,@BeforeTest,@Test BaseTest.Java with @Before,@After Utility:UTIL JsonPathUtil.java -->methods with getJsonnValue(path)--give the value xmlPathutil.java ObjectMapperUtil.java -->Deserialzation ExelUtil.java CSVUtil.java StringUtils.java--String Manupulation POJO UserPojo.java using lombok productsPojo.java using lombok TestRunners test_sanity.xml test_regression.xml <test> blocks Avoid parrel execution ->api is so fast we dont need parallel run Pom.xml- Maven dependency plugins:compiler suref...

RequestSpicification - Response Specification -Pojo

Image
 Example: public class RequestResponseSpecificationWithBuilder { static RequestSpecification reqSpec; static ResponseSpecification resSpec; public RequestSpecification requestSpecTestBuilder() { reqSpec = new RequestSpecBuilder().setBaseUri("https://gorest.co.in/public/v2/users/7466205") .setContentType(ContentType.JSON).build(); return reqSpec; } public ResponseSpecification responseSpecTestBuilder() { resSpec = new ResponseSpecBuilder().expectBody("name", equalTo("Indra Pillai")).expectStatusCode(200).build(); return resSpec; } @Test public void reqResSpecBuilder() { Response  res = given().spec(requestSpecTestBuilder()) .log().all().when().get(); System.out.println(res.asPrettyString()); ObjectMapper mapper = new ObjectMapper(); try { // De-serialzation - converting Json to Pojo ResponseGoRestUserPojo  tp = mapper.readValue(res.getBody().asString(), ResponseGoRestUserPojo.class); String name=tp.get...

Ignore SSL Certificate -.relaxedHTTPSValidation()

Image
  - Ignore the SSL certificate:   .relaxedHTTPSValidation() @Test public void SSLCERTIFICATE() { RestAssured.baseURI = "https://expired.badssl.com/"; given().log().all( ).relaxedHTTPSValidation() // off certification validation  .when().get().then().assertThat().statusCode(200); } 1- Certificate Error

oAuth 2.0

Image
        public class Autho2 { private String Access_Token; @BeforeMethod public void getAccessToken() { RestAssured.baseURI="https://test.api.amadeus.com/v1/security/oauth2/token"; JsonPath  js = given().contentType(ContentType.URLENC) .formParam("grant_type", "client_credentials") .formParam("client_id", "3WEebG9lWQQqwnRbngz5zkhwKtmEXVKs") .formParam("client_secret", "88uhUgeGJX31a0aa") .when().post() .then().extract().jsonPath(); System.out.println("access_token==>" + js.getString("access_token")); this.Access_Token=js.getString("access_token"); } @Test public void oAuthTest() { RestAssured.baseURI="https://test.api.amadeus.com/v1/shopping/flight-destinations"; /*System.out.println(Access_Token);*/ String resString = given().header("Authorization","Bearer "+Access_Token).param("o...

OAuthFlow_OAuth1.0_OAuth2.0_FlickrAPIOAuth1.0_AmadeusOAuth2.0_WithPostman_And_RestAssured

 Auth API with Rest Assured: Basic - supply Username and password given().log().all() .auth().basic("admin", "admin"). when().get().then().assertThat().statusCode(200);      2. Preemptive given().log().all() .auth().preemptive().basic("admin","admin"). when().get().then().assertThat().statusCode(200);      3.digestive' RestAssured.baseURI = "https://postman-echo.com"; given().log().all() .auth().digest("postman", "password"). when().get("/digest-auth").then().log().all().assertThat() .statusCode(200).and().body("authenticated",equalTo(true)); form Oauth1 Oauth2 JWT

XML API

 Example: GEt- http://ergast.com/api/f1/2017/circuits.xml In Basic Authentication, the client waits for a 401 Unauthorized response before sending the encoded credentials. In Preemptive Authentication, the client sends the encoded credentials with the first request, without waiting for a challenge. <MRData xmlns= "http://ergast.com/mrd/1.5" series= "f1" url= "http://ergast.com/api/f1/2017/circuits.xml" limit= "30" offset= "0" total= "20" >     <CircuitTable season= "2017" >         <Circuit circuitId= "albert_park" url= "http://en.wikipedia.org/wiki/Melbourne_Grand_Prix_Circuit" >             <CircuitName>Albert Park Grand Prix Circuit</CircuitName>             <Location lat= "-37.8497" long= "144.968" >                 <Locality>Melbourne</Locality>               ...

JayWay JsonPath Example:

Image
https://github.com/json-path/JsonPath Examples JayWayPath function syntax: Min min($[*].price) max($[*].price) avg($[*].price) length($) sum($[*].price) concat($[*].price,'0.0001') first($[*].price)--first index last($[*].price)--last index [     {         "id" : 1 ,         "title" : "Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops" ,         "price" : 109.95 ,         "description" : "Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in the padded sleeve, your everyday" ,         "category" : "men's clothing" ,         "image" : "https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg" ,         "rating" : {             "rate" : 3.9 ,             "count" : 120         }     },     { ...