Naseem
Naseem

Reputation: 961

Why Response Assertion is not working in JMeter

Here is my text response

<p class="equipment-left">
        <span id="p_lt_zoneContent_pageplaceholder_p_lt_ctl02_TireSearchResults_lblOriginalFrontEquipmentHeader">Original Equipment-Front: </span>
        <span class="equipment-num">
            <a id="p_lt_zoneContent_pageplaceholder_p_lt_ctl02_TireSearchResults_hypOriginalFrontEquipment" href="javascript:__doPostBack(&#39;p$lt$zoneContent$pageplaceholder$p$lt$ctl02$TireSearchResults$hypOriginalFrontEquipment&#39;,&#39;&#39;)"></a></span></p>
    <p class="equipment-right">
        <span id="p_lt_zoneContent_pageplaceholder_p_lt_ctl02_TireSearchResults_lblOriginalFrontEquipmentCount">**We found <strong>@Count</strong> result(s) that fit your vehicle.</span>**
    </p>
</div>
<div id="p_lt_zoneContent_pageplaceholder_p_lt_ctl02_TireSearchResults_divOriginalRearEquipment" class="equipment" style="display:none;">
    <p class="equipment-left">
        <span id="p_lt_zoneContent_pageplaceholder_p_lt_ctl02_TireSearchResults_lblOriginalRearEquipmentHeader">Original Equipment-Rear: </span>
        <span class="equipment-num">
            <a id="p_lt_zoneContent_pageplaceholder_p_lt_ctl02_TireSearchResults_hypOriginalRearEquipment" href="javascript:__doPostBack(&#39;p$lt$zoneContent$pageplaceholder$p$lt$ctl02$TireSearchResults$hypOriginalRearEquipment&#39;,&#39;&#39;)"></a></span></p>

And here is my Assertion screenshot

enter image description here

Basically I am trying to assert that if the response contains the text "We found @Count result(s) that fit your vehicle." then fail that request but somehow it is always getting passed.

I tried with Text Response, Response Message and Document(text) option but it is not working with any of the option.

Am I missing something? Please suggest. Thanks.

Upvotes: 3

Views: 2465

Answers (2)

Dmitri T
Dmitri T

Reputation: 168072

According to How to Use JMeter Assertions in Three Easy Steps article:

The Pattern can be either be:

  • a “string” for “Equals” or “Substring” clauses

  • a “Perl5-style” Regular Expression for “Contains” or “Matches” clauses

So given you set Contains mode JMeter treats your pattern as a Perl-compatible regular expression. So you need to escape parentheses with a backslashes in your pattern in order to make it work as you expect like:

We found <strong>@Count</strong> result\(s\) that fit your vehicle.</span>

References:

Upvotes: 3

Naseem
Naseem

Reputation: 961

I was able to fix the issue by Changing the Pattern Matching Rules from Contains to Substring.

enter image description here

Upvotes: 0

Related Questions