jmeter text resp. assertion failing when appears it should pass - jmeter

I'm getting a very basic text resp failing in jmeter when it appears it should pass. Feels like some whitespace or character encoding issue, but got me stuck - any pointers would be great.
Applied to: HTTP sampler
Type of assert: Main sample only, text resp
Matching: equals
So I ran the sample with the asset disabled, and copied the content of the resp. body into the patterns to test field within the asset. The context should be static, so assumed it would pass.
However, the assert is tripping with:
Assertion failure message: Test failed: text expected to equal.
URL testing:- http://c1-orig-qa.adis.ws/c/AutomatedQA2/texttype_plain.xml

It's a bad practice to compare full xml as even 2 xmls that differ in whitespace should be equal.
Most probably here the issue is whitespace.
I suggest you just compare some texts line:
- ok
- [CDATA[/c/AutomatedQA2/texttype_plain]]>

Related

Matching against the value of a Regex group containing an HTML entity

I have the following element on an HTML page:
<option value="52">Engine Specialist</option>
I have a regular expression extractor giving me a variable named SpecialistInfo:
<option value="(\d+)">(.+?)<\/option>
JMeter gives me a match and I can access the matched values using the "group notation" syntax: SpecialistInfo_g1 and SpecialistInfo_g2
In a subsequent test I have a response assertion with a pattern of ${SpecialistInfo_g2} and I'm tyring to match against the following: "This person is an Engine Specialist"
This understandably fails with an assertion error: Assertion failure message:Test failed: text expected to contain /Engine Specialist/
I have tried using a matching pattern of: ${__unescapeHtml(${SpecialistInfo_g2})} which seems to replace the entity with a space but the match still fails.
The assertion error JMeter gives me is Assertion failure message:Test failed: text expected to contain /Engine Specialist/
Does anyone have suggestions on what to try?
My expectation is that __unescapeHtml() function produces something weird and not the space and hence your assertion fails.
Try using the following __groovy() function instead:
${__groovy(vars.get('SpecialistInfo_g2').replace(' '\, '\u0020'),)}
This will guaranteed return "normal" space separator hence your assertion should start working normally

Response assertion failing even though the document does contain the expected text

I have a response assertion validating the 'Document (text)' of a response.
This is the assertion
This is the failure
This is the response that the assertion is checking. As you can see I have directly copied 'Statutory Currency USD Total Tax (SC) 58.80' from the failing assertion and it is found in the response?!
Other assertions are passing for this request.
Notice you can (maybe should) switch to using Substring instead of Contains which will fix your issue, because it doesn't use regex which have reserved characters as (
Contains - true if the text contains the regular expression pattern
Substring - true if the text contains the pattern string (case-sensitive)
Turns out the '(' and ')' needed to be escaped using a '\'.
You’re using document instead of Text response in Fields to test.
Document is usually reserved to asserting on pdf, excel, word document. it has an important cost in terms of performance and is not needed when asserting on text (html, json...)
Also you should favor substring instead of contains.

How to pass jmeter response data (ex: getting response 295 without any lable) to next http request url path/body

How to pass jmeter response data (ex: getting response 295 without any lable) to next http request url path/body. This 3 digits/4 digits number is dynamically generated for every run and this value i have to use it for next API calls. Since this value is not having any lable/attribute name not sure how to extract this value. Please suggest.
Regular Expression Configuration:
Reference Name: anything
Regular Expression: (.+)
Template: $1$
Match No.(O for Random): 1
The Reference name should be passed as the variable in the next HTTP request URL path/body.
Screenshot from Regex Test in View Results Tree.
If you need to extract a single numeric value, the relevant regular expression will be as simple as (\d+). See Perl 5 Regex Cheat sheet for quick reference.
If in future you will need a regular expression which return the whole response (including line breaks, special characters, whatever), as per How to Extract Data From Files With JMeter article it will be something like (?s)(^.*)

Adding / at the start and end of the asserted string in Response Assertion in JMeter

Assert given value:
"action":"GET /api/invoice_status","description":"[NO_AUTH] get
invoice statuses"
Assertion failure message:
Test failed: text expected to contain /"action":"GET
/api/invoice_status","description":"[NO_AUTH] get invoice statuses"/
It is adding / slashes just to represent properly but it's not an issue. Cross verify your response after running the script, there might be some difference in the response and the text which you are passing in assertion. Also, there is no need to pass complete response in assertion, just pass some important text like success, passed (if present in response) or any other text available in your response and click on contains radio button inside Response assertion
Got the solution by using the \ forward slash escape character.
As per How to Use JMeter Assertions in Three Easy Steps
The Pattern can be either be:
a “string” for “Equals” or “Substring” clauses
a “Perl5-style” Regular Expression for “Contains” or “Matches” clauses
So if you choose "Contains" mode - JMeter treats pattern as Regular Expression. Either escape meta characters with a backslash - \ or consider switching the Response Assertion into "Substring" mode instear.

JMeter's RegEx Post Processor returns null

The following is a contrived demo that reproduces the issue I was having with a larger, real Test Plan. I have 3 screen captures to demonstrate how the RegEx PostProcessor never matches during execution.
[EDIT] Note that in my screenshots that the Response Field to Check is shown as "Response Message". I had already tested Body and got "null" as explained. Screencaps would have been better had they shown Body selected with null result, but this should still make sense)
1) Here's the HTML of the Sampler's Response in the View Tree:
FIGURE 1.
Notice I'm using the Regex [Pp]age\s\d{1} to successfully find the desired text "Page 1" in the HTML in the first sampler response.
2) Here's the RegEx PostProcessor on the first Sampler:
FIGURE 2.
Notice it uses the same Regex as in previous screen capture, and default text is "notfound", and the resulting variable is "TempVar".
a) Screen capture shows "Main Sample" & "Response Message" selected. This returns default text.
b) Not shown - I tried "Main Sample" & "Body", but that returns null.
3) Here's the second sampler's Path where the result of the first sampler regex is fed into a URL parameter as ?MyVar=${TempVar}
FIGURE 3.
Now go back to look again at FIGURE 1 where you will see that during execution the dynamic URL on the second sampler becomes "MyVar=notfound" when using "Response Message" (it becomes "MyVar=null" if using "Body" instead).
Please let me know what I'm doing wrong. I've tried every combination in the RegEx Extractor screen, but I have never been able to get it return the matching text from the expression.
Thank you.
Change the regex you're using to:
<h3>This\sis\s([^<]*)<\\/h3>
Whilst the regex you're using does work (it will match on Page 1) because it is not using the () notation to return a value to the variable, you're ending up with null. The braces are required to denote what is sent back.
Check out this page, it gives more detail on how JMeter works with regexs.

Resources