How to get the name given to transaction controller using beanshell preprocesssor in jmeter

shey

I want to get the name given to transaction controller using BeanShell preprocessor in JMeter. Which I want to use to connect and display in dynaTrace later using header manager.

I tried something like this using BeanShell listener

String test = sampleResult.getSampleLabel();
log.info(test);

but I want to use the preprocessor.

log.info(sampler.getName());

This is used to get the name of sampler, in the similar way I want to get the name of transaction controller.

Specifically, I want to use BeanShell preprocessor .

Can somebody help me in this?

Dmitri T

You cannot walk further than Previous Result or Previous Sampler so I would state that it is not something you can implement easily. Looks like your test is not very well designed as normally people do not require knowing the name of the parent sampler controller.

Nevertheless you can get access to JMeter Test Plan Tree and figure out information from there. The example code will look something like:

import org.apache.jmeter.control.TransactionController;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.SearchByClass;

import java.lang.reflect.Field;
import java.util.Collection;

StandardJMeterEngine engine = ctx.getEngine();
Field test = engine.getClass().getDeclaredField("test");
test.setAccessible(true);
HashTree testPlanTree = (HashTree) test.get(engine);

SearchByClass txnCtrlSearch = new SearchByClass(TransactionController.class);
testPlanTree.traverse(txnCtrlSearch);
Collection txnControllers = txnCtrlSearch.getSearchResults();

for (Object txnController : txnControllers) {
    log.info(((TransactionController) txnController).getName());
}

Demo:

Beanshell Transaction Controller Name

Some information on using JMeter API from Beanshell scripts: How to Use BeanShell: JMeter's Favorite Built-in Component

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get Machine IP Address using beanshell in JMeter?

How to get value from property in BeanShell (jmeter)

JMeter ForEach Controller transaction name with multiple iteration

How to get response message HTTP Request on Beanshell Jmeter

JMeter: Transaction Controller label name is not displaying in aggregate report

How do i remove empty parameter using beanshell preprocessor in jmeter

How to generate hash(SHA1) using beanshell in JMeter?

How can we Verify Json response using Beanshell in Jmeter?

Verify the file is exist on a location in jmeter using beanshell

Jmeter extract a value using BeanShell PostProcessor

BeanShell Post Processor parse Json using Jmeter

Jmeter : Error when I try to get data from Database using beanshell assertion

How to Sort Numeric Array in JMeter Beanshell

How to use Hashset/set in Jmeter beanshell scripting

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

How to write data at particular cell in excel/csv file in jmeter using beanshell?

In Jmeter how do I set a variable number of threads using a beanshell sampler variable?

How can I print only 4 digits after decimal in Jmeter using Beanshell post processor?

How to get the thread and the sampler name in JMeter

Given username and fork name, how to get the name of the source GitHub repo using Github API (v3)

JMeter Beanshell Get Text File Size Save to Variable

Get first json object from response rest service by Beanshell in jmeter

Get controller by controller name

How to get the tag name given the value in python?

How to get the tree hash for a given directory name?

how to get Contact Name for a given Phone number

How to get an Agent when given its name?

How to visually group children samples under the Transaction controller's parent sample in the JMeter Dashboard report Statistics table?

JMeter - Exception when using Beanshell as JSR223 Sampler with file