Reputation: 11
There may be mistranslations because i'm using a translator.
i want to create response assertion in beanshell
script content is postrequest site and get responsedata
but this request usually fail so i want to check everytime with response assertion
i want to check make response assertion in jmeter beanshell
Whether the request is successful or not, I want to create a response assertion in beanshell.
can i help?
for(int i=0; i<10; i++){
HttpClient client = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost(requestURL);
postRequest.setEntity(new StringEntity(jsonMessage));
HttpResponse response = client.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String inputLine;
StringBuffer sbRes = new StringBuffer();
while((inputLine = reader.readLine()) != null) {
sbRes.append(inputLine);
}
reader.close();
String trans = sbRes.toString();
Boolean checkResult = trans.contains("result\":0");
if(checkResult==true){
//** i want create response assertion here **
}
else{
// **i want create response assertion here **
}
}
Upvotes: 1
Views: 575
Reputation: 167992
Looking into your code you're just sending 10 consecutive HTTP requests so it can be easily substituted with normal HTTP Request sampler and Response Assertion, there is no need to go for scripting there
Whatever:
Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting.
You have SampleResult
pre-defined variable which can be used for controlling:
Check out Top 8 JMeter Java Classes You Should Be Using with Groovy to learn more about above and other JMeter API shorthands available for JSR223 Test Elements
Upvotes: 0