Reputation: 2576
I just have the "JSR223 postprocessor" in Jmeter with below script
var context_data = {"referralId":${referral_id}};
console.log(context_data);
const secret = CryptoJS.enc.Utf8.parse(JSON.stringify(context_data))
console.log(secret);
const encoded_referral_id = CryptoJS.enc.Base64.stringify(secret);
console.log(encoded_referral_id);
The above script I need to get "encoded_referral_id" value and need to pass another input request header section.
Can someone help me how can I get the "encoded_referral_id" and pass it to another subsequence API header.
Upvotes: 0
Views: 738
Reputation: 168157
Example implementation using __groovy() function:
${__groovy(('{"referralId":' + vars.get('referral_id') + '}').bytes.encodeBase64().toString(),)}
Example implementation using __base64Encode() function:
${__base64Encode({"referralId":${referral_id}},)}
Demo:
More information: Apache Groovy - Why and How You Should Use It
Upvotes: 2
Reputation: 1841
You could create a variable within the JSR223 PostProcessor and read the value of the variable in subsequent components including header.
Steps 1 : Creating the variable encoded_referral_id
vars.put("ENCODED_REFERRAL_ID", encoded_referral_id )
Step 2 : Reading value of the variable
${ENCODED_REFERRAL_ID}
JMeter Variables API documentation could be useful to get an idea of available methods for manipulating the variables.
Upvotes: -1