Ask a Question

Unable to print Id out side the method

ArchanaRavi15
New Member

Unable to print Id out side the method

Cucumber API Testing

Base class

 

package com.dxc.eproc.apiTest;

public class BaseUtil {

private String id;
private String supplierInfoId;


public String getSupplierInfoId() {
return supplierInfoId;
}

public void setSupplierInfoId(String supplierInfoId) {
this.supplierInfoId = supplierInfoId;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

}

StepDefination

@When("I send post directsupplierinfos request with payload")
public void i_send_post_directsupplierinfos_request_with_payload() throws ClientProtocolException, IOException {

String directSupplierInfoUrl = directSupplierInfoUrl();
System.out.println(directSupplierInfoUrl);
logger.info("Service URL >> " + directSupplierInfoUrl());
HttpPost directSupplierInfo = new HttpPost(directSupplierInfoUrl);
StringEntity entity = directSupplierInfo();
directSupplierInfo.addHeader("content-type", APPLICATION_JSON);
directSupplierInfo.setEntity(entity);
HttpResponse response = httpClient.execute(directSupplierInfo);

checkResponseStatusCode(response,201);
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
System.out.println(responseBody);
String id="id";
String value = extractValueFromApiResponse(responseBody,id);

logger.info("The Generated Id is >> " + value);
base.setId(value);
System.out.println(base.getId());
}

Another Method

 

@When("I send directsupplierinfo GET request with id")
public void i_send_directsupplierinfo_get_request_with_id() throws ClientProtocolException, IOException {

base =new BaseUtil();
String getDirectSupplierInfoUrl=getDirectSupplierInfoUrl();
//String id1=extractValueFromApiResponse(response, id);
System.out.println(getDirectSupplierInfoUrl);
System.out.println(base.getId());
System.out.println(value);
//System.out.println(base.getId());
HttpGet getDetails = new HttpGet(getDirectSupplierInfoUrl+base.getId());
HttpResponse response = httpClient.execute(getDetails);
check200(response);
}

Response

Unable to print Id out side the method

http://130.175.175.137:9191/v1/api/direct-supplier-infos/
null
null

 

 

cancel
Showing results for 
Search instead for 
Did you mean: