I am hitting one API using JMeter. The URI that I am hitting (Test API-0) will return 302 Found and redirect it to Test API-1 which will again return 302 Found and redirect it to Test API-2. Test API-2 will return 200 OK if everything is fine.
I want to get the protocol, host, path, and response code of Test API-0 , Test API-1, and Test API-2.
In JSR223 Assertion Groovy language, I tried
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 )
But this will only give me the Test API-2 only (The latest URI only).
I also tried with
log.info("Previous Response URL is: " + ctx.getPreviousResult().getURL());
log.info( "The Sample URL is : " + SampleResult.getUrlAsString() );
Again same result. I only get the Test API-2 only (The latest URI only).
How can I get all Test API-0 , 1 , and 2 ?
[UPDATE 10 Dec]:
The working solution given by user7294900 :
In JSR223 Assertion window
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 )
}
