Jmeter - convert a string to base64 - jmeter

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

Related

how to pass the dynamic filename in csv data set config in jmeter while the dynamic names are generated to save data of previous request?

I have one http request whose response comes in nested json and using groovy i am saving that data in different csv file on the basis of conditions.
the name of csv file is generated dynamically and saved in a variable
using vars.put() function
vars.put("_cFileName",cFileName.toString());
when try to use this variable in csv data set config
enter image description here
getting error message
2022-01-19 16:58:39,370 ERROR o.a.j.t.JMeterThread: Test failed!
java.lang.IllegalArgumentException: File ${_cFileName} must exist and be readable
it is not converting the name to actual file name
But in case if file name is not dynaamic and the variable is defined under user defined variable in test plan it will able to convert to actual file name?
is there any way we can use the dynamic name created in an previos request post processor?
You cannot, as per JMeter Test Elements Execution Order Configuration Elements are executed before everything else, CSV Data Set Config is a Configuration Element hence it's being initialized before any JMeter Variables are being set.
The solution would be moving to __CSVRead() function, JMeter Functions are evaluated at the time they're being called so it's possible to provide dynamic file name there, see How to Pick Different CSV Files at JMeter Runtime guide for more details if needed.

Graphql in jmeter

I am using graphql in jmeter for API testing. Where in graphal we have the query and variable section.
My query would require a client ID which is int. Where as in Variable if I try to pass "{clientid : ${clientid}}"(here I am passing the CSV config variable, for testing the app for multiple users). But it is throwing an error like $ is unauthorised and expecting a (json,null,true or false).
Please help me out how I can pass the clientid which is a csv config variable.
Thanks in advance.
It looks like your CSV Data Set Config setup is not very correct so the JMeter Variable placeholder isn't getting substituted with its respective value from the CSV file.
We cannot help without seeing first couple of lines of the CSV file and your CSV Data Set Config setup so far I can only suggest re-visit the configuration and cross-check it with JMeter Documentation
You can observe JMeter Properties and Variables with their values using Debug Sampler and View Results Tree listener combination, if you don't see clientid line there - the variable is not set and JMeter sends it as it is, to wit "{clientid : ${clientid}}" and doesn't substitute ${clientid} with the value from CSV

How to convert string from JS string format in 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

JMeter using a variable as input for a response assertion pattern

I have a test plan in JMeter that has a Response Assertion where I'd like to use a variable that comes from a CSV Data Set Config. So my Pattern looks like:
${assert1}
Which corresponds (at least in my thoughts) to what comes from the file used in CSV Data Set Config, but it doesn't work. I have seen multiple suggestions to use a Regular Expression Extractor, but the examples I saw refer to something they're trying to capture from a page. In my case I am using an external csv file.
My question: how can I use a variable as input for a Response Assertion pattern ?
I have successfully used a CSV Data Set Config as a source of string that I use in a url parameter, and then use a Response Assertion to seek out that parameter in the response.
Variable name: P.
URL: /product/${P}.
The response assertion Parterns to Test: ${P}.
I wonder if it is not necessary to use the CSV data variable in the request in order for it to be available in the response assertion?
If my understanding is right,
here your problem:
You want to use the value from your CSV as part of URL and that too via variable.
Solution:
Configure your CSV Data Set Config like this:
Filename: url csv path
variable name : assert1
Delimiter : , (if your CSV comma separated)
leave remaining unchanged
That's it you can use the variable assert1 anywhere: ${assert1}.

Jmeter Parametrization

I'm very new to Jmeter. I need help with the input data file for jmeter.
Here is my situation.
My test data file structure is like this:
Test Case Name = XXXXXX11
RequestData = AAAAAAAAAA11
Expected Result = BBBBBBBBB11
Test Case Name = XXXXXX22
RequestData = AAAAAAAAAA22
Expected Result = BBBBBBBBB22
and so on ....
Now, I have to send the http request and verify the expected using Jmeter (Maven & Continuous Integration).
How can I parse the given file and verify the expected result?
I have tried the following:
__StringFromFile - but i don't know how to look for the line which has Request data or Expected result;
userParameter - but not sure how to pass values on runtime.
Could any of you please help me?
Do you have single test-case per file (i.e. single appearance of "Test Case Name",...,etc. in file)?
If so then you can possibly try to use custom Variables From CSV File plugin from Jmeter Plugins project.
My suggestion would be to convert your file to csv (with any delimiter you like). The first row becomes your heading, and each additional row becomes your data you want to pass in or validate. For example:
Test Case Name|Request Data|Expected Result
XXXXXX11|AAAAAAAAAA11|BBBBBBBBB11
XXXXXX22|AAAAAAAAAA22|BBBBBBBBB22
You can load this data in to your test plan using the CSV Data Set Config. Once you do, you'll be able to loop through each row of data if you set your Thread Group to Loop Forever. Then all you need to do in the test case is refer to your variables from the csv file like so:
${Test Case Name}.
Thank you so much guys!
I just wrote a bean shell script to parse the CSV file and stored all the request & response in the array and then created a for each loop around my http sampler. That met my requirement.
Thread Group
Beanshell preprocessr (To parse my CSV and to store it in an array)
For each loop (loops thru the array)
http sample
response assertion
Results

Resources