问题描述
我有一个jMeter JSR223PostProcessor脚本,用于解析和验证响应.
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>
我想将此脚本的代码移到一个单独的文件中,并从jMeter步骤中调用它.
现在,它说找不到脚本文件.
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) [?:?]
当我通过jMeter UI打开此脚本时,它将使脚本文件/文件名成为绝对路径,这是我不需要的.
When I open this script via jMeter UI, it will make script file / file name absolute path, which I do not want.
如何从自身内部获取Jmeter .jmx项目文件的绝对文件夹位置?
它说明了如何在脚本中查找脚本位置.我认为会有一个变量或参数指向脚本位置.我尝试使用具有 jMeter properties = true 和 jMeter variables = true 等的调试元素,但是它没有帮助(我没有找到指出的变量或参数到测试文件夹的位置.
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).
事实证明 https://stackoverflow.com/a/31164646/1839360 我可以在开始时有一个脚本来解析jmx文件的位置并将其存储到变量中.然后,我可以将此变量用作脚本位置的起点.但是,它看起来有点复杂:我想从GUI和命令行运行jmeter,因此必须解析GUI mode
或non GUI mode
.
It turns outhttps://stackoverflow.com/a/31164646/1839360that 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
.
推荐答案
-
您只需从脚本路径中删除
./
即可,因此它只是groovy/CitiesAssertion.groovy
,这样脚本位置将相对于JMeter的基本目录
You can just remove
./
from your script path so it would be justgroovy/CitiesAssertion.groovy
, this way the script location will be relative to the JMeter's base directory
如果要继续执行脚本编写方法,请考虑迁移到 __groovy( )函数
If you want to proceed with your scripting approach consider migrating to __groovy() function
JSR223 PostProcessor中没有AssertionResult
速记,您可能要切换到 JSR223断言
There is no AssertionResult
shorthand in JSR223 PostProcessor, you might want to switch to JSR223 Assertion
这篇关于jMeter JSR223PostProcessor-带脚本的运行文件-相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!