How to get the thread and the sampler name in JMeter

Gene Truuts

I want to get the thread and the sampler names in JMeter Test Plan and keep it in the variables.

I already keep the Test Plan name using the BeanShell Post Processor:

import org.apache.jmeter.services.FileServer;

String testPlanName = FileServer.getFileServer().getScriptName(); vars.put("testPlanName", testPlanName)

I use it in the Email notification to send the messages like "Test plan ${testPlanName} have received the response code ${responseCode}

But I want to include the thread name and the sampler name the same way.

I already tried to add the BeanShell Post Processor .getThreadname() and .getSampleName() and import import org.apache.jmeter.samplers.SampleResult; but it doesn't work.

How can I get that names and use it like variables?

Vadim Yangunaev

There are three functions, you may use them in BeanShell:

  1. __samplerName()

    The samplerName function returns the name (i.e. label) of the current sampler. The function does not work in Test elements that don't have an associated sampler. For example the Test Plan. Configuration elements also don't have an associated sampler. However some Configuration elements are referenced directly by samplers, such as the HTTP Header Manager and Http Cookie Manager, and in this case the functions are resolved in the context of the Http Sampler. Pre-Processors, Post-Processors and Assertions always have an associated Sampler.

    Example: ${__samplerName()}

  2. __TestPlanName()

    The TestPlanName function returns the name of the current test plan (can be used in Including Plans to know the name of the calling test plan).

    Example: ${__TestPlanName}

    Note, that __TestPlanName will return the File name of Test Plan, which can be different with Test Plan Name.

  3. __threadGroupName()

    The thread group name function simply returns the name of the thread group being executed.

    Example: ${__threadGroupName}

For full details on using BeanShell, please see:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to use 'OS Sampler' of jmeter to run any command of terminal on ubuntu

How to correctly get thread name in Java?

gdb how to get thread name displayed

gdb how to get thread name displayed

Get and set JMeter's properties in Java Request Sampler

How to run Jmeter webdriver sampler file uploading script in blazemeter?

How to make Jmeter run command from CMD - OS sampler - JMETER

How to display thread group name in JMeter log and in step

How to define and call java methods in jmeter using Wedriver Sampler

how to parse a value in JMeter sampler result

How to transfer a variable in java sampler to jmeter?

How to add a JDBC request sampler in JMeter-5

JMeter jp@gc-WebDriver Sampler Element Name is dynamic

JMETER - WebDriver Sampler - Groovy - Dynamic Name

How to get the name of a Thread in a Fixed Thread Pool

How do I override the response content in a JMeter WebDriver sampler test?

Get the downloaded file name from sampler response in JMeter

How to get throughput( in influx db) of each sampler i have in jmeter test

How to get Sampler Body data from beanshell Pre-Processor - JMeter

How to close newly opened window in Jmeter webdriver Sampler.?

Jmeter Debug Sampler | How to save all variable values to CSV

How to set ChromeProfile using Jmeter WebDriver Sampler?

How to specify firefox/chrome binary path in Jmeter webdriver sampler?

Jmeter extracting the response value and use on the same HTTP Sampler name

how to use jmeter OS process sampler

How to filter the inbox in JMeter Mail reader sampler?

JMeter - How to pass output from HTTP Sampler as input to OS Process Sampler

How to run the same sampler in Jmeter until I get specific result in response data Json

Get error when run WebDriver Sampler in jmeter