I have a scenario where I have arrays like Names(Mike, Harry, Jones, Jack, Jimmy) Rank(4,2,1,3,5) and Rollno(S12,S76,S89,S87,S99). I need to capture lowest rank and associated name and roll no in beanshell.
I'm expecting to capture lowest rank and to get their names and roll no.
Since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting so I will provide solution in Groovy :
import java.util.stream.IntStream
def Names = ['Mike', 'Harry', 'Jones', 'Jack', 'Jimmy']
def Rank = [4, 2, 1, 3, 5]
def Rollno = ['S12', 'S76', 'S89', 'S87', 'S99']
def lowestRankIndex = IntStream
.range(0, Rank.size())
.reduce((i, j) -> Rank.get(i) > Rank.get(j) ? j : i)
.getAsInt()
def lowestRankName = Names.get(lowestRankIndex)
def lowestRankRollno = Rollno.get(lowestRankIndex)
log.info('Lowest rank name: ' + lowestRankName + ' rollno: ' + lowestRankRollno)
Demo:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.