JMeter: Assertion Failure Message is displayed for Response Assertion - jmeter

I am trying Response assertion for the first time, and below error is displayed:
Assertion error: false
Assertion failure: true
Assertion failure message: Test failed: text expected to contain /(?is)<title>Management Information System</title>/
What could be the reason for such error?

The Assertion error: false line means that no internal jmeter error occurred.
The Assertion failure: true line means that the assertion condition you set to be checked was false.
The Test failed: text expected to contain /(?is)Management Information System/ line means that you set up the assertion to check if the target of the assertion (most likely the response body) matches to the regexp /(?is)Management Information System/ but it did not.

First assumption: why do you need this (?is) bit? In "Contains" mode Response Assertion should work fine if you remove it.
As per How to Use JMeter Assertions in 3 Easy Steps guide
The Pattern can be either be:
a “string” for “Equals” or “Substring” clauses
a “Perl5-style” Regular Expression for “Contains” or “Matches” clauses
Second assumption: the assertion as per your picture is being applied to all requests, if you want it to be applicable only to one of them move it to be a child of that particular request.

In JMETER: There if you see 2 Response Assertion tab then remove one of those Response Assertion which is (Pattern to test) is OK
Then try again it will work

Related

MultipleCompilationErrorsException is showing when I add two code in pre-processor

I wrote below given code in Jmeter pre-processor
${__fifoPop(sync_tokensa, gotTokena_1)}
${__fifoPop(sync_tokensaq, gotTokena_2)}
error showing as
Response code:500
Response message:javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script394.groovy: 1: unexpected token: # line 1, column 38.
U0pDVVdtaUJRa0xQSEVodzE1MDEyNTM2MzQ=
As per JSR223 Sampler documentation:
When using this feature, ensure your script code does not use JMeter variables directly in script code as caching would only cache first replacement. Instead use script parameters.
Don't inline JMeter Functions and/or Variables into the Groovy scripts, it may cause either compilation failure or incorrect interpretation or only first value will be used or any combination of all above.
Go for code-based equivalent like:
1.upto(2, { number ->
vars.put('gotTokena_' + number, kg.apc.jmeter.modifiers.FifoMap.getInstance().pop('sync_tokensaq'))
})
More information: Apache Groovy - Why and How You Should Use It

JMeter: JSON Path Assertions fail without any error

Below is the error shown on failure of my test.
JMeter version: 3.2
Assertion error: false
Assertion failure: true
Assertion failure message: Value expected to be 'ptgrna9jgc1f3a77881+iamtestpass', but found 'ptgrna9jgc1f3a77881+iamtestpass'
There is a failure even if the 2 strings are exactly same. Any idea why this is happening?
PS: The tests are running as expected on a different machine.
Everything started working fine after switching to JMeter 3.1!
If assertion fails - something is wrong, my expectation is that the reason is in:
Your JSON Path Expression returns a JSON Array and you are expecting its 1st element
There is a leading or trailing space (or both) either in the JSON Path return value or in your expected data. Double check both using i.e. Debug Sampler and View Results Tree listener combination.

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

Having trouble telling ruby/watir webdriver to check for two fail conditions

I am trying to write a simple cucumber step where it checks to see if one of two phrases are on the page, but my attempts at if statements have failed. Here is the step i currently have
Then(/^I should see a pdf preview of the magazine$/) do
#browser.windows.last.use
#browser.text.should_not include "Page not found"
But, ideally, I want the step to check and see if the text "Page not found" is present, if so fail the test. If "page not found" is NOT present, then check to see if the text "Forbidden" is present, if so, fail the test. If neither phrase is present, then pass the test.
Where i think I am stumbling, is I dont know how to tell it, to stop and fail the test.
Ideally, I would think it would look like this...
if text "Page not found" visible?
fail test
elseif text "Forbidden" visible?
fail test
else
pass test
But I dont know how to put that into ruby/watir-webdriver code
Do I just have to make it throw exceptions if the test fails? If its that easy, will that fail the test, or pass it but give me a message and how do I make it pass if neither phrase is visible?
A Cucumber step will stop and fail the test as soon as any of the assertions fail (or an exception is raised). Conversely, a Cucumber step will pass if all assertions pass (or there are no exceptions raised).
As a result, you can simply do:
Then(/^I should see a pdf preview of the magazine$/) do
#browser.windows.last.use
#browser.text.should_not include "Page not found" # first assertion
#browser.text.should_not include "Forbidden" # second assertion
end
With this step:
In the situation where "Page not found" is displayed, the first assertion will fail. As a result the step will be marked as Fail (with the message that the text includes "Page not found"). The rest of the Cucumber step will not be executed - ie the second assertion will not be tested.
In the situation where "Forbidden" is displayed, the first assertion will pass so Cucumber will continue to execute the line. When the second assertion is run, it will fail and therefore cause the step to fail (with the message that the text includes "Forbidden").
In the situation where neither text is present, both assertions will pass. Since Cucumber was able to complete the step without any failed assertions (or exceptions), the step will be marked as Pass.
In the situation where both texts are displayed, the step will Fail, but the error message will only indicate the first failure - ie "Page not found" was displayed.

JMeter issues with span tag in Response Assertion

I added a Response Assertion to my test to hit the home page of our local site. I added this to the "Patterns to Test" in a Response Assertion:
Email
This worked. ( To get that label, I did View Source in Firefox and copied the code including all white space. I then clicked "Add" for the Response Assertion and pasted the copied code directly into JMeter this way. ) When I run my test, my test will pass with just this label as a Pattern to Test. It shows no red errors after running it in JMeter.
However, when I add the following span tag by clicking on "Add" to get a new entry in the same Response Assertion, the test will fail.
1.7.0.147
So, to be clear, I had 2 entries for the same Response Assertion...one for the "Email" label and one for the "footerVer" span. Each of these had their own separate line under the same Response Assertion.
Also, for most tests that passed and did not pass, I had "Main Sample only", "Text Response", and "Contains" selected. I did try to change to "Matches" and "Equals" but I just ended up with different errors. So, I wanted to stay on "Contains" for now since my other entry for the "Email" label worked when I had "Contains" selected.
Under the "View Results Tree", JMeter tells me about this failure when I add the span tag:
Assertion error: false
Assertion failure: true
Assertion failure message: Test failed: text expected to contain /
1.7.0.147
/
I also have had success with other tags like , , , , etc. along the way.
Only the tag seems to be giving me a problem right now. Any ideas?
===============================
Added config:
I am not able to add the full response since it is not my code, but the company's code. But, I can try to get something on here that me be useful in a different way.
This is the response dealing with the version copied verbatim from the response tab within JMeter:
<span class="footerVer">
1.7.0.147
</span>
Hope that helps
I would suggest using XPath assertions for multiline HTML entities parsing as page source may vary and it can be a headache to deal with flaky HTML code.
Following XPath expression validates whether inner text of span with footerVer class equals 1.7.0.147
//span[#class='footerVer']/text()='1.7.0.147'
Use Substring instead of Contains for Pattern Matching rules:
http://jmeter.apache.org/usermanual/component_reference.html#Response_Assertion
So, I found one way around this. Although, I do not think this is the most efficient way to verify the test. I split the span into 3 individual lines in the Response Assertion.
<span class="copyright marginLeft_100">
© Copyright 2002-2013 Turning Technologies, LLC. All Rights Reserved.
</span>
==========================
I do not really mind the first 2 lines. But, the third line is so generic it really does no good if not combined with the beginning tag
Well, for now, I can at least confirm something. Also, I left it on "Contains", even though I took a look at the other link posted above, because all of my other tags presented no problem when it was on "Contains". Hope this helps someone else also.

Resources