Bibek Prasad

REST API AUTOMATION(ACCESS token to response body FLOW) Access token generate String accessToken = Authentication.generateAccessToken(baseURI, requestUser, requestScope); public static String generateAccessToken(String baseURI, String requestUser, String requestScope) { RestAssured.config = RestAssured.config().encoderConfig(encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)); String accessToken = ""; try { ExtentTest logs = Logger.getLoggerReporter().createTest("Setting the accessToken using api"); logs.info("The baseURI is "+baseURI+" user "+requestUser+" scope "+requestScope+" and baseURI is "+baseURI); RestAssured.baseURI = baseURI; Response response = RestAssured.given() .config(RestAssured.config() .encoderConfig(EncoderConfig.encoderConfig() .encodeContentTypeAs("x-www-form-urlencoded", ContentType.URLENC))) .contentType("application/x-www-form-urlencoded; charset=UTF-8") .formParam("grant_type", "client_credentials") .formParam("client_id", "ct-resource-client") .formParam("client_secret", "ct-resource-client-password") .formParam("scope", requestScope) .formParam("user_principal", requestUser) .post(Constants.GENERATE_ACCESS_TOKEN_URI); logs.info("The response is "+response.asString()); System.out.println("Status Code is :"+response.getStatusCode()); System.out.println(response.asString()); JsonPath jsonPathEvaluator = response.jsonPath(); accessToken = (String) jsonPathEvaluator.get("access_token"); logs.info("The accessToken is "+accessToken); } catch (Exception e) { e.printStackTrace(); } return accessToken; }