Search code examples
jmeterperformance-testingbeanshelljsr223

Want to fetch first three character from the String


I have use case in JMeter JSR223 where I want to fetch First three characters from a String Example given Below def randomPrefix = org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(6)

vars.put("Trailer_ID", TrailerId)

Output: Trailer_ID : QlWBvp

I want to fetch only QlW


Solution

  • How about String.take() function

    def foo = vars.get('Trailer_ID').take(3)
    

    Demo:

    enter image description here

    More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?