The prev variable displays a warning message in groovy, is it normal? - groovy

1.add JSR223Sample
2.add follow values:
${__Sms_String_Encrypt(${__groovy(import groovy.json.JsonSlurper ;def respone = prev.getResponseDataAsString();new JsonSlurper().parseText(respone).result,)},${secretKey},2,re)}
3.Please allow me to attach a screenshot.
Why is this warning message prompted?
Why is it normal to add prev variable references in the script area?For example: prev.getTime().toString())

It sounds like a bug in JMeter to it worth reporting it to JMeter Bugzilla
Until it's fixed the options are in:
Ignore the warning as the function will still do its job
Decrease JMeter logging verbosity for __groovy() function by adding the next line log4j2.xml file
<Logger name="org.apache.jmeter.functions.Groovy" level="error"/>
this way you will stop seeing the message in the jmeter.log file
Extract data from the response using JSR223 PostProcessor or JSON Extractor or JSON JMESPath Extractor and use variables, not the groovy function in the "Parameters" section

Related

How to change log.info/error message's font color in Jmeter's JSR223?

I'm trying to find a way to change log.info/error message's font color so that it would be easier for me to read messages in Jmeter's JSR223 Log section
any advice ?
thanks,
As per current version (JMeter 4.0) I don't think it is possible. You can use Groovy Coloriser library if you want, however it will only work for println statements, not for JMeter's log.error
The only way you can filter out the log output to errors only is configuring JMeter logging subsystem to display only messages of ERROR level (or above). You can do this in at least 2 ways:
Locate <Root level="info"> line in log4j2.xml file (lives in "bin" folder of your JMeter installation) and change info to error. JMeter restart will be required to pick the property up
Or you can simply run JMeter like jmeter -LERROR
In both cases you will not be seeing all these INFO and/or WARN messages anymore, you will see only ERROR and above.
More information:
Overriding Properties Via The Command Line
How to Configure JMeter Logging

Call function from different sampler in JMeter - Groovy

I have a sampler that get data from DB (budget), and I have some assertions that I made using JSR223 assertion.
In each assertion I write the same function (check_budget) and to each assertion I pass different values (start_budget, end_budget etc)
The problem is that I duplicate the code for each assertion and it is not friendly for maintenance.(if logic change need to change at 7 duplicate functions)
It there a way to create a sampler and write generic function in it (calc_budget) and to call it from each assertion,
like creating a class in java and perform import?
In Groovy you have evaluate() function, so given you stored it into a JMeter Variable or JMeter Property or into a file you can call it like:
evaluate(vars.get('your_var'))
or
evaluate(new File('your_test.groovy'))
See Scripting JMeter Assertions in Groovy - A Tutorial article for more information.
In that case, and in general also, you can keep groovy script in a script file and call the same script file from all JSR223 elements
Script File
Name of a file to be used as a JSR223 script, if a relative file path is used, then it will be relative to directory referenced by "user.dir" System property

How to use log4j write logs into a mysql database on Jmeter?

Jmeter default write logs into a file named "jmeter.log".But there is a file named "log4j.conf" under the folder "bin". I confused about how to use it. Anyone can help me ?
please check in the conf
# JMeter does not use log4j as logging system
# This configuration will only be used by libraries that do use log4j
# or your custom code if it uses it
# For logging configuration of JMeter, it needs to be done in user.properties
how it works.
If you have special sampler that uses java code .. in that java code if you use log.info , log.error, log.warn statements it prints that to jmeter.log Hope this helps
If you have jsr223 groovy sampler try putting below line and check jmeter.log you see the logging info.
log.info "check this in jmeter.log"
Hope this helps ..

How to read a txt file, get a data and store it as variable in Custom Properties of SOAPUI using Groovy?

i started to use Soapui this week and i did some tests like sending a request POST and save the response as txt file ina folder.
What i'm trying to do is to read this txt file, copy a sepcific data and store it in Custom Properties.
Because i want to use this object in the nest Request POST which is depending of the first request.
I want to do it in Groovy.
i have only the Open source SOAPUI version 5.0.0
Thank you
You've to add a groovy test step in your test case and do it similar as you would in java, check groovy documentation.
Only as a reference SOAPUI 5.2.0 has the groovy 2.1.7 version (check the dependency in pom.xml) so in groovy scripts which runs on SOAPUI you can use the java standard api included in the jre, the SOAPUI classes, the groovy 2.1.7 API among some others, additionally you can include other jars in SOAPUI\bin\ext in order to use them in groovy script.
Finally you're asking about to read some data from a file and write it to a custom property, so for example you can do it as follows:
// read the file from path
def file = new File('/path/yourFile')
// for example read line by line
def yourData = file.eachLine { line ->
// check if the line contains your data
if(line.contains('mySpecifiyData=')){
return line
}
}
// put the line in a custom property in the testCase
testRunner.testCase.setPropertyValue('yourProp',yourData)
Since your problem it's not clear I show you a possible sample showing how to read a file looking for specific content and saving this content in a custom property in the testCase.
Note that in groovy scripts the are a global objects which you can use: testRunner, context and log, in this sample I use testRunner to access testCase and its properties, in the same way you can go thought testRunner to access testSuites, project, testSteps etc... check the documentation:
http://www.soapui.org/Scripting-Properties/tips-a-tricks.html
http://www.soapui.org/Functional-Testing/working-with-scripts.html
Hope this helps,

BSF Assertion from script file does not load UDVs

I am trying to use groovy scripts as BSF assertion in JMeter. The script written inside the JMETER assertion script box works well, but when I try to use it through a groovy file it is not loading the User Defined Variables it needs for assertions
It says
org.apache.bsf.BSFException: exception from Groovy: groovy.lang.MissingPropertyException: No such property: mobileNumber class: D__RESTAPITesting_JmeterBSFAssertionScripts_Script1
Not sure why it is looking for property when ${..} refers to a variable (if I am not wrong). Any help on the error message and how to use a script file for assertions ?
The scripts I have written are saved as *.groovy. Do I need to save scripts in some other extensions for BSF to read it correctly ?
Pass your User Defined Variables via Parameters input like ${foo} ${bar}
In your .groovy script body refer variables as args[0] args[1]
See image below for details (the solution works fine for file inputs as well) and How to Use JMeter Assertions in 3 Easy Steps guide for advanced information on using JMeter's assertions.

Resources