Home > Enterprise >  How to print the missing elements using JMeter?
How to print the missing elements using JMeter?

Time:05-17

I have 2 get api's which returns the response code consisting of id number and title.

sample responses of API_1 is:(with 100 id's)

{

   "result": "OK",

   "obj" : {

                "list" : [
                  {
                     "id" : 924946341,
                     "title" : "qweryuy"
                   },
                    {
                     "id" : 8361,
                     "title" : "kgsklp"
                   }
                ]
          }
}

API-2 also has similar response like this.

I want to compare both the api's id number and want to print the missing elements.

So I have used json extractor and extracted the id of 2 api's. API-1 has the extracted variable name as Id.

And API-2 has extracted variable name as c_Id.

In json extractor for 1st API i have extracted something like this:

variable name :id

json path: $..id

match no :-1

checked the suffix ALL box

similarly for api2 also I have used the same with varivable name as c_id

I have used beanshell assertion to compare if they are same, but couldn't get how to show the missing values, so I got suggestion to use JSR223 Assertion, I have used the code given, The code is:

log.info('id1: ' vars.get('id_ALL'))

log.info('id2: ' vars.get('c_id_ALL'))

def id1 = org.apache.commons.lang.StringUtils.substringBetween(vars.get('id_ALL'), '{', '}').split(',').collect()

def id2 = org.apache.commons.lang.StringUtils.substringBetween(vars.get('c_id_ALL'), '{', '}').split(',').collect()

def missing = org.apache.commons.collections.CollectionUtils.disjunction(id1, id2)

log.info('Missing values: '  missing)

When I run the script in view result tree I am getting an assertion failure message:

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: org for class: Script10

When I see in the Log viwer panel I can see

id:924946341,8361

c_id: 924946341,09272,8361

and then instead of missing values I am getting this error:

ERROR o.a.j.a.JSR223Assertion: Problem in JSR223 script: JSR223 Assertion javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: org for class: Script10 at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.7.jar:3.0.7] at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.7.jar:3.0.7] at javax.script.CompiledScript.eval(Unknown Source) ~[?:1.8.0_321] at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.4.3] at org.apache.jmeter.assertions.JSR223Assertion.getResult(JSR223Assertion.java:50) [ApacheJMeter_components.jar:5.4.3] at org.apache.jmeter.threads.JMeterThread.processAssertion(JMeterThread.java:931) [ApacheJMeter_core.jar:5.4.3]

I tried using beanshell assertion to see if the id and c_id values are picking up or not, the extracted variable values are picked up fine.

Is there something I am doing wrong? or can you suggest any other way achieving displaying of such missing elements in JMeter? I can't check 100's of id's manually when they are in jumbled form.

CodePudding user response:

  1. I cannot reproduce your issue, maybe it's something environmental depending on your Java version and the libraries you have in enter image description here

    More information: Scripting JMeter Assertions in Groovy - A Tutorial

  • Related