I have a jMeter JSR223PostProcessor script which parses and validates response.
<JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="CitiesAssertion" enabled="true">
<stringProp name="TestPlan.comments">Asserts that actual cities are equal to expected cities</stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="script">
expectedCities = ["Prague", "Brno", "Ostrava", "Berlin", "Minsk", "Warsaw"] as Set
responseData = prev.getResponseData();
responseDataParsedJson = new groovy.json.JsonSlurper().parse(responseData);
actualCities = responseDataParsedJson as Set
log.info("actualCities: {}", actualCities);
// Assert may not work.
assert actualCities == expectedCities;
if (actualCities != expectedCities) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage("actualCities are not equal to expectedCities. actualCities: $actualCities, expectedCountries: $expectedCities")
}
</stringProp>
<stringProp name="scriptLanguage">groovy</stringProp>
</JSR223PostProcessor>
I want to move the code of this script into a separate file and call it from jMeter step.
Now, it says it cannot find the script file.
020-08-10 14:31:50,969 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, CitiesAssertion
javax.script.ScriptException: Script file 'C:\Users\johndoe\Desktop\apache-jmeter-5.3\bin\.\groovy\CitiesAssertion.groovy' does not exist or is unreadable for element:CitiesAssertion
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:205) ~[ApacheJMeter_core.jar:5.3]
at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:45) [ApacheJMeter_components.jar:5.3]
at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:940) [ApacheJMeter_core.jar:5.3]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:572) [ApacheJMeter_core.jar:5.3]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) [ApacheJMeter_core.jar:5.3]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) [ApacheJMeter_core.jar:5.3]
at java.lang.Thread.run(Thread.java:834) [?:?]
When I open this script via jMeter UI, it will make script file / file name absolute path, which I do not want.
How to get the absolute folder location of a Jmeter .jmx project file from within itself?
It says how to find script location in script. I thought that there would be a variable or parameter that points to the script location. I tried to have a debug element with jMeter properties=true and jMeter variables=true, etc, but it did not help (I did not find a variable or param pointing out to the location of test folder).
Some idea
It turns out
https://stackoverflow.com/a/31164646/1839360
that I can have a script at the beginning which resolves the location of jmx file and stores into into a variable. Then I can use this variable as a starting point of script location. It looks a bit complex though: I want to run jmeter from GUI and from command line, therefore I have to resolve GUI mode
or non GUI mode
.