Jmeter error due to captured token containing '\x' - jmeter

In my testing scenario most of the responses fail due to the captured token having a \x in it.
The token without this \x does pass. How should I handle this token or what is required to be converted here.
I did try urlencode , urldecode
token for example - 00ceR2t8n\x2DfSp6lfvPvm_xxB23683omTcxbE\x2DulsTf

If you really need to remove these \x signs the best option is going for __strReplace() function like:
${__strReplace(${token},\\\x,,)}
Demo:
__strReplace() function can be installed as a part of Custom JMeter Functions bundle using JMeter Plugins Manager

Create a JSR 223 post processor and write the code below:
def responseToken = vars.get("token")
def newToken = responseToken.replace("\\x", "")
vars.put("newToken", newToken)
Then use this newToken variable

Probably my question was not constructed the right way.
The below solution worked for me -
added a beanshell postprocessor with the below code
${__javaScript("${stateToken}".split('\x2D').join('-'),FOO)}
the converted variabled was stored in Foo.
and substituted ${Foo} in the the required place.

Related

Unable to send object value in next request json body

I am trying to send object value based on condition to the previous request.
From above,pricecheck i will get formtype value based on form type validation i have to send guests info in request..
here i am able to validate but not able to pass the object value if i try any string i can able to do,please help me.
You need to put a string value in vars, surrounded with quotes " and escape inner quotes\",as
vars.put("guests", "{ \"title\":\"Mr\", .... }");
You're violating 2 major best practices:
You're referring JMeter Variables like ${form} in the JSR223 Test Elements while you should be using vars.get('form') construction instead
You're using JavaScript language which is a performance anti-pattern, since JMeter 3.1 you should be using Groovy language for scripting
Check out Parsing and producing JSON article to learn more about reading and generating JSON in Groovy.
Also posting code in form of screenshots is not something you should be doing otherwise the chance of getting a comprehensive answer will be much less

Is there a function in BeanShell JMeter for get a value of a element in a decode token?

I have a decoded token in JMeter BeanShell, which contains
Username,
ContactGUID,
among other
I need to get the value from ContactGUID
vars.put("deToken", new String(Base64.decodeBase64(vars.get("token"))));
If there is a GUID-like structure in the token you can get it using Regular Expressions
First of all forget about Beanshell, since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting.
Groovy in its turn provides find operator so you will be able to extract GUID from text like:
def contactGUID = ((deToken =~ "([a-f0-9]{8}(-[a-f0-9]{4}){4}[a-f0-9]{8})")[0][1])
Demo:

How can I pass an assertion in Jmeter to validate the parten of my generated random UUID for every iteration?

[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12} this is how my UUID looks like
I don't know where your generated random UUID comes from but supposing you have put it (through CSV Reader or some extractor) in variable randomUUID and that it's accessible through:
${__P(randomUUID)}
use a Response Assertion in the following configuration:
Check Matches
Check JMeter Variable and enter randomUUID
Fill in the correct regexp for your UUID (you will have to create it)
If your regular expression does not work, I would try to add capital letters, and make it more generic:
[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}
I am getting a UUID in Response when I call a 'GET' Rest Service. And I need to validate it for every iteration.
Here is what I have tried with Reg Exp and
Response Assertion
For [0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}
It kind of works but the problem here is the if i change this [0-9a-f]{8} to [0-9a-f]{7} or any other number <8 its still works fine
Even If i change this [0-9a-f]{12} to [0-9a-f]{10} or any other number <12 its still works fine

While controller don't stop Jmeter

I am encountering a problem with "While Controller":
This is what I do:
Thread Group
-user defined variables (I have assigned 'nikitaShalom' to {})
-while controller (the following condition: ${__javascript(eval("'${nikitaShalom}' != '${str}'")})
-Http request (my request)
- JSON path extractor (to extract the value I will use in my while controller)
I have pre-defined nikitaShalom to be {} as I said after the extraction it should get 'userArrivedNode' then I am comparing it to str variable which predefined to 'userArrivedNode' I can see that the while controller keeps going it does not stop even if I get the condition right. why is this?
Can you give me any reference about it?
Thanks!
OK, I found the answer for this problem, all has to be done is to change javascript to javaScript with captial 'S'.
Thnaks!

Change variable from HTTP Response in JMeter

I have a GET request from where I extract the variable ${SAMLRequest} (Regular Expression Extractor).
Value of ${SAMLRequest} is as follows: VhJUVNXeHBPRjNMdnNvNHpTUT09PC9YNTA5Q2VydGlmaWNhdGU+PC9YNTA5RGF0YT48L0tleUluZm8+PC9TaWduYXR1cmU+PHNhbWxwOk5hbWVJRFBvbGljeSBBbGxvd0NyZWF0ZT0idHJ1ZSIgLz48L3NhbWxwOkF1dGhuUmVxdWVzdD4=
Next I have a POST request, and I want to post the variable ${SAMLRequest} with some changes.
Instead of the sign + I want to have %2B and instead of =, I want to have %3D.
Do you know how I can change a variable in JMeter?
Use beanshell preprocessor1 in your post sampler
The easiest way is to check "Encode?" box for SAMLRequest parameter in your POST request body
The harder way is using __urlencode() JMeter Function.
The hardest way is BeanShell Pre Processor as okwap suggests. However it'll give you the full control.
Relevant Beahshell code will look like:
import java.net.URLEncoder;
String source = vars.get("SAMLRequest");
String encoded = URLEncoder.encode(source);
vars.put("SAMLRequest", encoded);

Resources