How to convert string from JS string format in Jmeter - jmeter

I am newbie in Jmeter. I am able to capture the session id as "result.sessionToken = 'A45833C7\x2D4535\x2D49C8\x2DBB46\x2D15819383F3BB';" using "Regular Expression Extractor". However, this session Token ID in request is going in different format "A45833C7-4535-49C8-BB46-15819383F3BB".
Can anyone tell me, how to convert the captured dynamic data from 1 format to other? We have "Convert" attribute in "web_reg_save_param()" function in Load runner, do we have such function in Jmeter?
OR
How can we write our own code to replace "\x2D" with "-"?

Assuming that you have ID variable with the value of A45833C7\x2D4535\x2D49C8\x2DBB46\x2D15819383F3BB
You can replace \x2 with - Using __javaScript() function as follows:
Just replace
${__javaScript("${ID}".split('\x2').join('-'),)}
Replace and store result into ID variable
${__javaScript("${ID}".split('\x2').join('-'),ID)}
Replace and store result into FOO variable
${__javaScript("${ID}".split('\x2').join('-'),FOO)}
For more information on using JMeter Functions see How to Use JMeter Functions post series

Related

How to pass the dynamic value in Body data in the Post Request using jmeter

I recorded the .JMX script in Jmeter and one of the request is as below
POST http://www.hello.com/auth/nqa/md/login
Body data:
{"domainId":"nqa","code":"12345skdkdk"}
I would like to send the "code" field dynamically and for that I added the regular expressing extractor as below enter image description here
When i re run the script , the code value is not replaced with the dynamic value.
Not sure what part i am missing in the regular expression extractor or in the Body data field
First of all, you cannot extract the value from the request body using the Regular Expression Extractor, normally you should extract the dynamic values from the previous response so inspect the whole flow using View Results Tree listener and look for your "code" value there
Your regular expression extractor in its current configuration will return random value in the parentheses so it could be domainId, nqa, code or 12345skdkdk. Going forward if you need to get some dynamic data from JSON go for JSON Extractor or JSON JMESPath Extractor
List item
you should do three-step of below
go to the random variable according below picture
Define random variable name . in this case we set variable name to code1 and set min & max value to this
Use ${code1} variable to your data section

JMeter how to select randomely from a extracted set of values

I have a requirement to use randome url from a url list I extract from a json response.
Say I extract them in this mannser
imageUrls_1=https://blah01.com
imageUrls_2=https://blah02.com
imageUrls_3=https://blah03.com
imageUrls_4=https://blah04.com
imageURLs_matchNr=4
In a following JSSR223 sampler I was able to generate a variable called "url" with one of the url names selected randomely
("imageUrls_1","imageUrls_2",etc)
I was thinking to use them in my HTTP request to get the correcponding url as follows. ${${url}}. But soon found out its not giving me anything other than "${${url}}" :(.
JMeter Is it possible to place a varibale inside a varible name?
Basically I need to use one of the extracted urls randomely in my HTTP request.
The easiest way is going for __V() and __Random() functions combination like:
${__V(imageUrls_${__Random(1,${imageURLs_matchNr},)},)}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
Use __V function
${__V(url)}
The V (variable) function returns the result of evaluating a variable name expression.

Jmeter - convert a string to base64

I've just started out trying to write some tests in jmeter. It's the first time I've used it in earnest, and I'm struggling a bit with it.
I am running a test that searches for data on a website.
The returned data is in the format baseURL/customerID=
Now, the customer number depends on the customer being searched for and it is in base64.
I'm struggling to see how I can get the url updated.
I can see in the request that the field is parameter, and I know what the value is, as I have it stored in a csv file as CustomerID.
How can I convert that csv data to the url parameter?
I'm trying to use beanshell at the moment with this:
import org.apache.commons.codec.binary.Base64;
String customerID = vars.get("customerID");
String customerStringEncoded = Bas64Encoder.encode(customerID);
vars.put("customerStringEncoded",customerStringEncoded);
But it seems that it can't locate customerID.
I am supplying it wiht ${CustomerID} in the preprossor menu option, but I don't know what is wrong.
the error is "Typed variable declaration : Attempt to resolve method: encode() on undefined variable or class name: Bas64Encoder
"
Any tips?
Thanks
tgb
If the data is being stored in csv, you can use the "CSV Data Set config" to read the CSV File. CSVhttp://jmeter.apache.org/usermanual/component_reference.html#CSV_Data_Set_Config

How to use different properties of a Object type jmeter variable?

I have a jmeter variable suppose ${employee} whose value is {empid:"E101",empname:"XYZ",empcity:"Chennai"}.
I want to use this variable in different Http calls for e.g.
demo.exmaplecode.com?Id=${employee}.empid
demo.exmaplecode.com?Name=${employee}.empmname
demo.exmaplecode.com?City=${employee}.empcity
I am not able to extract values by using "." operator.
Please suggest extracting values from an object type variable in jmeter.
You can achieve this fairly easily using __groovy() function available since JMeter 3.1, the relevant expressions would be something like:
${__groovy((new groovy.json.JsonSlurper().parseText(vars.get('employee'))).empid,)}
${__groovy((new groovy.json.JsonSlurper().parseText(vars.get('employee'))).empname,)}
${__groovy((new groovy.json.JsonSlurper().parseText(vars.get('employee'))).empcity,)}
Demo:
More information: Groovy: Parsing and producing JSON
Use JSON Extractor and choose radio button JMeter Variable and enter variable name
to get for example empid use the following setting:
Variable Names: empid (your new variable name for id)
JSON Path Expressions: $.empid
Match No.: 1

How do I generate a timestamp and put it in a variable in jmeter?

How do I generate a timestamp and put it in a variable in jmeter?
So that the variable can be passed in the URL.
Add the following function wheerever you want to send the Unix based timestamp:
${__time(,curTime)}
you can refer the value using ${curTime} in later requests.
Example:
HTTP Sampler
in View Results Tree
You can use Function Helper Dialog (in Options), to generate the code:
Note: you can also save the value using name of the variable (second row), so later you can refer the same value.
Note: you can also format the time, based on your needs (first row).
Reference:
http://jmeter.apache.org/usermanual/functions.html#__time

Resources