jmeter icon indicating copy to clipboard operation
jmeter copied to clipboard

Unable to create sample labels dynamically

Open PavanMudigondaTR opened this issue 10 months ago • 0 comments

Expected behavior

I would expect to create sample labels dynamically using JSR223 listener in groovy. Sample Label kept appearing same "JSR223 Sampler" but i expected dynamic label as per my custom groovy

Actual behavior

unable to see custom label names. please see groovy below

image

Steps to reproduce the problem

import org.apache.jmeter.samplers.SampleResult

def createSampleResult(String label, String message, String data, long startTime, long endTime) {
    def result = new SampleResult()

    result.setSampleLabel(label)
    result.setStartTime(startTime)
    result.setEndTime(endTime)
    log.info("Start Time for ${label} should be: " + (new Date(startTime)).toString())
    Thread.sleep(3000)
    result.setResponseCode("200")
    result.setSuccessful(true)
    result.setResponseMessage(message)
    result.setResponseData(data, "UTF-8")
    log.info("${label} label after ending: " + result.getSampleLabel())

    return result
}

def results = []
def teardownThreadGroup = {
    // This is your loop
    for (int i = 0; i < 10; i++) {
        log.info("******************Sample Number ${i + 1}********************")
        long startTime = System.currentTimeMillis()
        Thread.sleep(5000) // simulate some delay
        long endTime = System.currentTimeMillis()

        SampleResult result = createSampleResult("Sample ${i + 1}", "This is message returned from JSR223 script for Sample ${i + 1}", "You will see this sentence in Response Data tab for Sample ${i + 1}", startTime, endTime)
        results.add(result)
    }
}

teardownThreadGroup()
// Return the last SampleResult
return results[-1]

JMeter Version

latest

Java Version

corretto 17

OS Version

mac

PavanMudigondaTR avatar Apr 19 '24 16:04 PavanMudigondaTR