1

I am new to Jmeter. I need to write an assertion to my http request. The HTTP request returns all the tags available as an array in JSON response and I need to assert that my tag, which I have stored as a variable, is part of the response

I have tried using ${tagName}

as well as vars.get("tagName")

for response assertion, but both are doing the string match rather than matching the variable value.I am sure there is an easy fix to this. Please help.

2 Answers 2

1

In case of "normal" Response Assertion as per How to Use JMeter Assertions in Three Easy Steps article:

The most commonly used assertion is the Response Assertion, which checks whether a response text/body/code/message/header contains, matches, or equals a specified pattern.

The Pattern can be either be:

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

So the configuration you're looking for is "Substring" pattern matching rule and should be something like:

enter image description here

2
  • Thanks for responding. I was using 'Contains' matching rule and getting error. However using substring matching rule also gives the same error:Assertion failure message:Test failed: text expected to contain /${tagName}/ Oct 6, 2020 at 1:42
  • It means that your tagName variable doesn't have a value so double check the way you're creating/assigning it. You can see all JMeter Variables with their respective values using Debug Sampler and View Results Tree listener combination
    – Dmitri T
    Oct 6, 2020 at 4:55
0

Have you tried using the JSON Assertion item, rather than the Response Assertion?

You can then assert that the JSON path in the response exists and is set to a value, which can be a JMeter variable.

Your JSON path in it might be something like $.tagName (or whatever the field is called in the response) and the expected value might be ${tagName} (your variable).

1
  • Sadly, the response doesn't have a key value pair structure, just an array of values.. {"results":["AAbb7","AFC_s2s_CRUD_NB_T4","Aztest1","Aztest2","Aztest3","CLOUD_RSSERVER2012.SIMULATION00001","Cloud_BA:ACTIVE.1","Cloud_BA:CONC.1","Cloud_BA:LEVEL.1","Cloud_BA:PHASE.1","Cloud_BA:TEMP.1","Cloud_Cloud_QA-SECD-HIST-FN.Simulation00001","Cloud_Cloud_QA-SECD-HIST-FN.Simulation00002","Cloud_Cloud_QA-SECD-HIST-FN.Simulation00003"]} Oct 5, 2020 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.