how to pass created token in 2nd thread group - jmeter

How To pass token in 2nd thread group.
I have tried adding json extractor in 1st thread group and then added beanshell preprocessor in 2nd thread group
I am getting invalid token

Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy for scripting.
You need to convert the JMeter Variable holding your token into a JMeter Property, for this add a JSR223 PostProcessor after the JSON Extractor and put the following code to "Script" area:
props.put('token', vars.get('variable-holding-your-token'))
In 2nd Thread Group you can use __P() function for accessing the token like:
${__P(token,)}
More information: Using JMeter Variables With Multiple Thread Groups

Related

How to pass parameter (token) to another thread group , i need to use the parameter pass from another threadgroup as dynamic url

How to pass parameter (token) to another thread group , i need to use the parameter pass from another threadgroup as dynamic url ( as the image above , i need to use Survey Token as parameter on the next threadgroup)
i already try some tips , but still get stucked
the token passed from the result GETSurveyToken is not successful place after /svap/survey/[token]
hope anyone can help ??
thanks
i try using : regular expression extractor, json extractor, dan using Preprocessor to get the parameter/variable
As per documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
What Regular Expression Extractor gives to you is a JMeter Variable so in order to be able to use it in other thread in this or other thread group you need to convert it into a JMeter Property using __setProperty() function. Once done you can access the value using __P() function
If your logic is more complex, i.e. you need to "wait" in 2nd thread group until the token is available consider using Inter-Thread Communication Plugin

Use regular expression extractor variable in Tear Down Thread Group

we have to save regular expression extractor variable in one file --> "GJC_NUMZCAISSE" Type="Integer" Value="(.+?)"/>
Data Used for StoreClosing Transaction : Closing - cbrauth,store,baid,GJC_NUMZCAISSE
GJC_NUMZCAISSE variable will fetch from Login and save into one file and use corresponded data for closing as written above.
As per JMeter Documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
Regular expression extractor produces a JMeter Variable which is visible only to the Thread Group where it's declared.
If you want to access the variable value in the tearDown Thread Group you need to convert it into a JMeter Property using __setProperty() function.
The property value can be read using __P() function where required
More information: Knit One Pearl Two: How to Use Variables in Different Thread Groups

How to pass response from one beanshell sampler to another beanshell sampler in same thread in Jmeter

I am making dme2 call to api from beanshell and i am getting response from it like {"stagedcustomerId":"165ce369-a9fb-4d42-b8f0-f119a6ae20eb"}
so now i want to pass only customer id value to another beanshell sampler for next api call as one of parameter in request body in same thread in jmeter.
Please suggest what can we do in this case. is there any way to do beanshell postprocessor?
You can use SampleResult shorthand in order to define the Beanshell Sampler response data like:
SampleResult.setResponseData("{\"stagedcustomerId\":\"165ce369-a9fb-4d42-b8f0-f119a6ae20eb\"}","UTF-8")
Once done you can add a JSON Extractor as a child of the Beanshell Sampler and configure it like:
That's it, now you will be able to access the extracted value as String id = vars.get("id"); in other Beanshell Sampler or as ${id} in any other test element.
Also be aware that starting from JMeter 3.1 it's highly recommended to use JSR223 Test Elements and Groovy language for scripting so consider refactoring your test on next available opportunity.

How to pass variable extracted using json path extractor to another thread group

I am able to extract access_token and pass it to header manager on http request in same thread group .
But I want to use this variable in other tread group also .
I am extracting json value using JSON path extractor:
Json Path Extractor
And Putting it on Header of other Same Thread Group then it work fine :
Header Manager
in 1st Thread Group use __setProperty() function to convert JMeter Variable into a JMeter Property
in 2nd Thread Group use __P() function to access the value
Demo:
More information: Knit One Pearl Two: How to Use Variables in Different Thread Groups
There is a more "intelligent" way of sharing variables between threads/thread groups - Inter-Thread Communication plugin, check out documentation for comprehensive explanation and test plans examples.

How to find and replace a substring in sampler's response for web services?

I am using two soap/xml request samplers wherein response of one is to be used in request of the other. The issue is that the response of Sampler1 contains multiple occurrences of "a:" which has to be replaced by "eas1:" which can be used in Sampler2. Kindly suggest a solution.
I tried using beanshell postprocessor but could not come to any positive result.
Add JSR223 PostProcessor as a child of the Sampler1
Put the following code into "Script" area
def response = prev.getResponseDataAsString()
def request = response.replaceAll('a:', 'eas1:')
vars.put('request', request)
Use ${request} in the "Body Data" section of the Sampler2
References:
prev is a shorthand to SampleResult class instance which provides access to the parent Sampler result
vars is a shorthand to JMeterVariables class instance, it provides read/write access to JMeter Variables
String.replaceAll() method reference
Groovy is the New Black - guide to Groovy scripting in JMeter

Resources