Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create sample labels dynamically #6273

Open
PavanMudigondaTR opened this issue Apr 19, 2024 · 0 comments
Open

Unable to create sample labels dynamically #6273

PavanMudigondaTR opened this issue Apr 19, 2024 · 0 comments

Comments

@PavanMudigondaTR
Copy link

PavanMudigondaTR commented Apr 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant