这是我在其中一个测试用例中所做的替代方法。
- HTTP Sampler
- BSF Post processor with javascript language
- script in BSF goes like this
- log.info("processing image index response");
if ("" != prev.getResponseDataAsString()) { //if response is not empty process it
eval( 'var indexJSON = ' + prev.getResponseDataAsString() ); //get the respnose JSON string as javascript var and operate on it as you like
vars.putObject("indexJSON", indexJSON);
var next_slide_timestamp=indexJSON[0].timestamp;
vars.put("next_slide_timestamp", "0");
var maxSlides=indexJSON.length;
vars.put("maxSlides", maxSlides);
} else { //if response is empty simply initialize all var to 0
vars.put("currentThumb", "0");
vars.put("currentSlide", "0");
vars.put("next_slide_timestamp", "0");
vars.put("maxSlides", "0");
log.info("index time : empty response , setting defaults to zero");
}