Jmeter regex failing - jmeter

How do I get the text "Need to grab this" using Jmeter - Regex
"suggestionsIdentifiers":[{"#v":"some other variable","#t":"string"}],"saveInto":["need to grab this"],"labelPosition":"ADJACENT","#t":"PickerField"}]}]}

It isn't very recommended to use Regular Expressions to work with JSON entities as they're quite complex, multiline, you need to escape a lot of characters, etc. so regular expressions are hard to develop and quite fragile.
I would recommend switching to JSON Path Extractor available via JMeter Plugins, it works with JSON like a charm.
JSON Path expression would be something like:
$..saveInto[0]
N.B. your response is not full, it doesn't look like a valid JSON so if you have any problems - please update your question with the full response so we could suggest an appropriate JSON Path
See Using the XPath Extractor in JMeter (Scroll down to "Parsing JSON") for plugin installation instructions and some form of JSONPath language reference.

Related

How to write a regex to get only values of destination btwn destination and departure cities of flight

Blazedemo is the website can anyone help me on this
HTML is not a regular language therefore using regular expressions for parsing HTML is not the best idea
JMeter provides CSS Selector Extractor which provides way more robust, reliable and readable approach to deal with HTML data.
Example:
More information:
CSS Selector Reference
How to Use the CSS/JQuery Extractor in JMeter

How to replace file content which has special character, with dynamic value in JMeter

Can I replace a file content with dynamic content even if the file has special characters.
This is what I get when I try to do that.
and this is how my file looks like
[{"someName": "M`o\c\k","someNumber": "${randomNumber}"}]
and I have a variable configured for ${randomNumber}.
Please check if the below can met your requirement.
Random Variable Config:-
Dummy sampler for the json
JSR223 Post processor to put the dummy response in a variable
Used the variable in HTTP. This is just for demo. Probably, in your case it will be websocket.
Output
Also, groovy provide json support. Below you can check a similar solution based on groovy. Where it is mentioned to escape special character for json.
Jmeter Groovy how can I replace this string with {
Hope this helps.
I was able to solve my scenario by adding a json library to my JMeter, JSON.Simple. I added the jar to my jmeter classpath. Then I was able to a BeanShell PreProcessor.
The Json simple object will not escape the special characters and its much easier to manipulate. So that was great for my use case.

I need to extract a request number from "response data"

I am trying to use Regular expression extractor to extract, but i don't know how to use it here. Since the "request number" is visible only in "Response Data" of "View result tree". where should i place the post processor. what would be my regular expression.
edit: I have added my regular expression and result screen
Your response value is a number, without double quotes, so change your Regular expression to
"response":(\d+)
Parsing JSON data using regular expressions is not the best idea, I believe you should be using JSON Extractor instead.
It's available since JMeter version 3.0 and you should be able to use it instead of the Regular Expression Extractor.
The relevant JsonPath query will be as simple as:
$.response
Full configuration just in case:
Also be aware that according to JMeter Best Practices you should always be using the latest version of JMeter so consider migrating to JMeter 5.0 (or whatever is the latest version available at JMeter Downloads page) on next available opportunity.

how to use jmeter to update xml to post later

I have a JMeter job that I'm taking the XML response from, updating the XML, then PUT the XML back to update the record. I have ALL the parts, except the XML update part.
I need to update XML root/Settings/HasRetry from not only "false" to "true", but also add other nodes directly under it. Order matters in this XML.
xml to update
Ideas on the best way to do this? I tried a via a simple java script:
java replace
...but the JS pukes on that b/c of the special characters in the XML string.
Ideas?
You have an error in your script, last line should look like vars.put("ResponceData", res); as your current implementation simply ignores the replacement logic.
Also be aware that it is not recommended to use Beanshell for scripting, since JMeter 3.1 users are encouraged to switch to JSR223 Test Elements and Groovy language.
Groovy is Java compliant hence in majority of cases valid Beanshell code will be a valid Groovy code, however it is not recommended to use JMeter Variables references like ${ResponceData} as it will ruin scripts compilation feature and performance will be a big question mark so switch to vars.get('ResponceData') instead.
Example Groovy code for values replacement will look something like:
def str = vars.get('ResponceData')
def res = str.replace(vars.get('findSearch'), vars.get('findReplaceWith'))
vars.put('ResponceData', res)
Demo:
See Apache Groovy - Why and How You Should Use It to learn more about Groovy scripting in JMeter.

how to check that tag does not contain spaces or null as value using regular expression

I am trying to validate a string (containg numbers, alphabets and spaces in between words and also contains trailing and leading white spaces) .I need a regular expression which i can put in response assertion of jmeter
Standard recommendation not to use regular expressions for working with HTML and/or XML.
Go for XPath Assertion instead, using it you can implement your requirement using XPath query like:
//yourElement[#yourTag!='null' and not(contains(#yourTag,' '))]
XPath language is quite easy, at least it is much easier to create and read XPath expressions rather than "regular" ones. Check out XPath Tutorial to get started and How to Use JMeter Assertions in Three Easy Steps guide to learn more about assertions available in JMeter.

Resources