Getting Null pointer exception whenever running, unable to resolve.
Below is my code
public static RequestSpecification setFormParam(String formParam, RequestSpecification reqSpec)
{
String[] splittedFormParam=formParam.split(",");
System.out.println("NoOfFormParam:"+splittedFormParam.length);
for(String s:splittedFormParam)
{
System.out.println("FormParam:-"+s);
String[] keyValue=s.split(":");
System.out.println("key-->"+keyValue[0]);
System.out.println("Value-->"+keyValue[1]);
System.out.println(reqSpec);// reqSpec Always getting null value
reqSpec.formParam(keyValue[0], keyValue[1]);
testCaseLogger.get().log(Status.INFO, "Added "+keyValue[0]+" as FormParam with value "+keyValue[1]);
}
return reqSpec;
}
Uses of setFormParam method
public static Response postCandidateResponse(Hashtable<String, String> data) {
requestSpec= TestUtils.setFormParam(data.get("formParam"), requestSpec);
extentLogger().log(Status.INFO, " Method type is: "+data.get("methodType"));
extentLogger().info("EndPoint is: "+data.get("endPoint"));
return requestSpec.request(data.get("methodType"),data.get("endPoint"))
.then()
.extract()
.response();
}
NullPointerException
stands for? Have you looked at your stacktrace? See this answer to see how to read stacktraces and understand exceptions: sqa.stackexchange.com/a/51649/1933