How to compare the responses from two different servers using Jmeter? - jmeter

I need to compare the responses from two different servers using Jmeter. I think that Comparison assertion in Jmeter supports the response comparison. But how to use this? What is the purpose of 'Comparison filters'?

You'll need the Assertion as a parent or sibling to your compare requests. Make sure you add the Listener "Comparison Assertion Visualizer" to help see the differences/debug
The Filters are to remove strings you know are dynamic, for example a timestamp or unique userID embedded in the response. It uses PERL regular expressions, the same as the post-processor Regex Extractor
Here's a sample structure:
Test Plan
+ Thread Group
+ Server 1
+ Server 2
+ Compare Assertion
+ Compare Assertion Visualizer

Related

How to remove special characters, string , number from regax

I have. done paramerization in recorded requests in jmeter , when i rerun it some requests. are failing but i have done capture variables and pass to
next requests but there is issue
format ofresponse is changing dynamically
my regax - stateToken":"(.+?)"
\x2D is. additionalpart is coming some time so i need re write regax to remove this when we getting that
Fail Case
002KljInsq318mkPTkDTuJ06eLSxIQmVga\x2DSuvHmDe
{"stateToken":"00UaBoY\x2D81AIL32Nz9qmUJrIarSv3OgfUdd8FHGSkb"}
{"stateToken":"003LYZGSYKn3io1ocOwCBNcp2I\x2Dt8UbkdBfruaC6C0"}
{"stateToken":"00C8O4pt\x2DcSPEzHrt69zqmEGta9KbjdwywEVdkICku"}
{"stateToken":"00JgMsy7\x2DzXDP0gxaeWv4dj8EguFTWtnLxV\x2DBKTkIq"}
Working
{"stateToken":"00fswJVHKpW7dNhNVK0bRclBBrsuMLHBBevJ8IS1Wz"}
{"stateToken":"00ZVZXpSJn7v3lxNTrEqy1mAGydgroO5apvoTlWH2u"}
any ideas ?
It looks like your application has a functional issue, if it returns the token which cannot be used for authentication is sounds like a bug so instead of trying to implement a workaround in JMeter you should report it as it needs to be fixed.
JSON is not a regular language hence using regular expressions for extracting data from it is not the best idea, I would recommend considering using JSON Extractor or JSON JMESPath Extractor instead
If you still want to bypass the intermittent issue with tokens and remove the problematic element from the token (I repeat I doubt real user of your application will do this) you can do it using a suitable JSR223 Test Element and the code like:
def before = vars.get('token')
log.info('Before: ' + before)
def after = before.replace('\\x2D','')
log.info('After : ' + after)
vars.put('token', after)
Demo:

How to correlate different values in a RegEx with multiple matches with JMeter- Correlation Recorder?

I have a problem in JMeter that I can't figure out how to solve.
Situation:
I want to load test an ASP.NET-website.
bzm - Correlation Recorder used for recording and correlation
ScriptResource and WebResource have multiple occurrences
Now I used following RegEx to extract the ScriptResource values: <script src="(.+/ScriptResource.+?)". Then I stored the 3 matched values into 3 different variables. But I can't replace the values in the found order.
Example:
First Match: stored in : AspNet_ScriptResource
Second match stored in: AspNet_ScriptResource_1
Third match stored in: AspNet_ScriptResource_2
The three matches have all different values, can't paste one value into all 3 matches.
So I have to write the value from AspNet_ScriptResource into the first match (matchNr=1).
AspNet_ScriptResource_1 into second match (matchNr = 2) and
AspNet_ScriptResource_2 into third match (matchNr = 3).
But in the Correlation Rules (in the Correlation Recorder) in the "Correlation Replacement" section, there is no option to choose in which matchNr to write.
Correlation Recorder: Correlation Rules
I tried to use a BeanShell Preprocessor with a for-loop but I only found a way to write in the logs, not in the response body.
Is there a way to solve this with the Correlation Recorder plugin? If not, what options do I have to handle such a scenario?
Thanks for your help! :)
You can raise an enhancement request for the bzm - Correlation Recorder via JMeter Plugins support forum or if you're a BlazeMeter customer and need this piece of functionality asap - you can open a support ticket for implementation of the feature.
Currently it seems that the Correlation Recorder expects you to provide a regular expression either with the unique match or you will have multiple substitutions with the same value.
With regards to Beanshell approach:
You can substitute response data, but not with the PreProcessor, you need to do this via the PostProcessor using prev.setResponseData() function
Since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting
If you need to change request data, not the response data, you can do this via sampler.getArguments() function

JMeter - compare assersion between two variables

I have two variables (create_date) took from SQL queries, and I want to validate the results.
Using Regular Expression I fetch both created date and I want to make sure that the dates is not equal.
I have created the following BeanShell assersion to compare both variables:
enter image description here
however, I'm getting the following error:
enter image description here
You're mixing 2 approaches:
Referencing variables like ${CreateDateBefore} in scripts (which you should not be using at all)
And using vars shorthand for JMeterVariables class instance
Apart from this you're using double to store some form of a timestamp
So you need to update your code like:
String var1 = vars.get("CreateDateBefore");
String var2 = vars.get("CreateDateAfter");
Also be aware that since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting so consider migrating to JSR223 Assertion
And last but not the least, you can compare 2 JMeter Variables using "normal" Response Assertion configured like:

Jmeter- Condition using response assertion

How to put a condition using response assertion in jmeter.
In loadrunner we have web_reg_find with savecount attribute. This helps us to for keeping condition in IF loop.
if textcount >0
transaction --> pass
else
transaction--> fail and exit iteration and continue
Similarly, how to get the count of text check and place the same in condition (IF loop) in jmeter.
Use any of the post processor extractor to fetch all the values in a variable. Like in regular expression we can use "-1" in "match no." to fetch all the values matching with the regular expression. So, you will get the count.
Now, put that as a condition in if controller like ${__groovy("${countVar}"=="10")}
In short,
1.Add a Regular Expression Extractor as a child of the request to fetch all values.
2.Add If Controller at the same level to check the condition.
More information: 6 Tips for JMeter If Controller Usage
If you provide "Match No" as -1 in the Regular Expression Extractor
you will have ${foo_matchNr} variable containing the number of matches.
Since JMeter 4.0 you have __isVarDefined() function which can be used to check whether a JMeter Variable is defined or not
Both approaches can be used in the If Controller

Compare Assertion in Jmeter

I am new to J meter. Please look into the following body data in Http request
{
"groupBy":"${groupBy}",
"offset":0,
"limit":10
}
I need to check whether limit value is above 10 in the above content. Is it can be done by using Compare Assertion.
Thanks in advance.
You have to extract the value "10" in to variable using "Regular Expression Extractor" after that use "Response Assertion" by choosing "Jmeter Variable" option under "Apply to" choosing "Equals" option under "Pattern Matching Rules"
and add 10 under "Pattern to test"
There is a special Test Element - JSON Path Assertion available via JMeter Plugins which is designed for working with JSON data.
The relevant JSON Path expression to match your "limit" will be as simple as:
$.limit
Try to avoid Compare Assertion where possible as it consumes very much resources.
References:
JSONPath - XPath for JSON
How to Use JMeter Assertions in Three Easy Steps

Resources