我正在使用JMeter访问一个API。我正在访问的URI (TestAPI-0)将返回302 Found并将其重定向到Test 1,后者将再次返回302 Found并将其重定向到Test 2。如果一切正常,测试API-2将返回200 OK。

我想获得TestAPI-0、Test 1和Test 2的协议、主机、路径和响应代码。
在JSR223断言Groovy语言中,我尝试了
def url = prev.getURL();
def protocol = url.getProtocol();
def host = url.getHost();
def path = url.getPath();
log.info('Full URL: ' + url.toString())
log.info('Protocol: ' + protocol )
log.info('host: ' + host )
log.info('path: ' + path )
但是这只会给我测试API-2 (仅提供最新的URI )。
我也试过
log.info("Previous Response URL is: " + ctx.getPreviousResult().getURL());
log.info( "The Sample URL is : " + SampleResult.getUrlAsString() );同样的结果。我只获得Test 2(仅提供最新的URI )。
如何获得所有测试API-0、1和2?
更新12月10日
user7294900给出的工作解决方案:
在JSR223断言窗口中
import org.apache.jmeter.samplers.SampleResult;
SampleResult[] subResults = prev.getSubResults();
subResults.each { it ->
def url = it.getURL();
def protocol = url.getProtocol();
def host = url.getHost();
def path = url.getPath();
log.info("URL: " + url )
log.info("Protocol: " + protocol )
log.info("host: " + host )
log.info("path: " + path )
}
发布于 2019-12-09 05:27:55
您还可以使用prev.getSubResults()获得子结果,并从数组中获取数据。
SampleResult[] subResults = prev.getSubResults();数组包含此示例的子结果。
您可以迭代每个子结果:
subResults.each { it->
def url = it.getURL());
def protocol = url.getProtocol();
def host = url.getHost();
def path = url.getPath();
}https://stackoverflow.com/questions/59240792
复制相似问题