让我给出一些背景知识。
如您所见,定义了两个使用以下值指向两个不同* .ini文件的变量:
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}Settings.ini
表示变量: SettingsFile
使用Step-by-step调试器,我可以确认文件的路径是否正确。现在,有趣的部分。 我很少有"用户定义的变量"从文件中读取值。
JMeter无法读取此变量的值,并为每个变量抛出以下错误:
使用(例如):for variable accountNumber
2018-02-20 15:15:46,750 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``{import org.ini4j.*; Wini ini = new Wini(new File(vars.get("SettingsFile"))); St . . . '' : Typed variable declaration : Class: Wini not found in namespace
2018-02-20 15:15:46,751 WARN o.a.j.f.BeanShell: Error running BSH script
org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``{import org.ini4j.*; Wini ini = new Wini(new File(vars.get("SettingsFile"))); St . . . '' : Typed variable declaration : Class: Wini not found in namespace
at org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:183) ~[ApacheJMeter_core.jar:3.3 r1808647]
at org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:189) ~[ApacheJMeter_core.jar:3.3 r1808647]
at org.apache.jmeter.functions.BeanShell.execute(BeanShell.java:100) [ApacheJMeter_functions.jar:3.3 r1808647]
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:137) [ApacheJMeter_core.jar:3.3 r1808647]
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:112) [ApacheJMeter_core.jar:3.3 r1808647]
at org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:92) [ApacheJMeter_core.jar:3.3 r1808647]
at org.apache.jmeter.testelement.AbstractTestElement.getPropertyAsString(AbstractTestElement.java:281) [ApacheJMeter_core.jar:3.3 r1808647]
at org.apache.jmeter.config.Argument.getValue(Argument.java:146) [ApacheJMeter_core.jar:3.3 r1808647]
at org.apache.jmeter.config.Arguments.getArgumentsAsMap(Arguments.java:94) [ApacheJMeter_core.jar:3.3 r1808647]
at org.apache.jmeter.engine.PreCompiler.createArgumentsMap(PreCompiler.java:114) [ApacheJMeter_core.jar:3.3 r1808647]
at org.apache.jmeter.engine.PreCompiler.addNode(PreCompiler.java:101) [ApacheJMeter_core.jar:3.3 r1808647]
at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:996) [jorphan.jar:3.3 r1808647]
at org.apache.jorphan.collections.HashTree.traverse(HashTree.java:978) [jorphan.jar:3.3 r1808647]
at org.apache.jmeter.engine.StandardJMeterEngine.run(StandardJMeterEngine.java:369) [ApacheJMeter_core.jar:3.3 r1808647]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_151]
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_151]
at org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:166) ~[ApacheJMeter_core.jar:3.3 r1808647]
... 14 more
Caused by: bsh.EvalError: Sourced file: inline evaluation of: ``{import org.ini4j.*; Wini ini = new Wini(new File(vars.get("SettingsFile"))); St . . . '' : Typed variable declaration : Class: Wini not found in namespace
at bsh.BSHAmbiguousName.toClass(BSHAmbiguousName.java:74) ~[bsh-2.0b5.jar:2.0b5 2005-06-12 04:50:41]
at bsh.BSHType.getType(BSHType.java:154) ~[bsh-2.0b5.jar:2.0b5 2005-06-12 04:50:41]
at bsh.BSHTypedVariableDeclaration.eval(BSHTypedVariableDeclaration.java:75) ~[bsh-2.0b5.jar:2.0b5 2005-06-12 04:50:41]
at bsh.BSHBlock.evalBlock(BSHBlock.java:130) ~[bsh-2.0b5.jar:2.0b5 2005-06-12 04:50:41]
at bsh.BSHBlock.eval(BSHBlock.java:80) ~[bsh-2.0b5.jar:2.0b5 2005-06-12 04:50:41]
at bsh.BSHBlock.eval(BSHBlock.java:46) ~[bsh-2.0b5.jar:2.0b5 2005-06-12 04:50:41]
at bsh.Interpreter.eval(Interpreter.java:645) ~[bsh-2.0b5.jar:2.0b5 2005-06-12 04:50:41]
at bsh.Interpreter.eval(Interpreter.java:739) ~[bsh-2.0b5.jar:2.0b5 2005-06-12 04:50:41]
at bsh.Interpreter.eval(Interpreter.java:728) ~[bsh-2.0b5.jar:2.0b5 2005-06-12 04:50:41]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_151]
at org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:166) ~[ApacheJMeter_core.jar:3.3 r1808647]
... 14 more
Settings.ini看起来像(以accountNumber为例):
[General]
;account number used for testing
accountNumber = 989899773
;BadAccountNumber = 12314500
BadAccountNumber = 989899773
有关如何摆脱此错误的任何想法?我不明白为什么如果文件的路径正确,我无法读取每个变量的值。
PS:我没有在"查看结果树"中获得任何结果。所有测试都是使用文件中的变量的简单HTTP请求。
答案 0 :(得分:2)
这是由于缺少ini4j library,你需要下载.jar,把它放到JMeter Classpath的某处并重启JMeter以选择.jar。
还要注意{JMter中任何形式的脚本starting from JMeter 3.1 it is recommended to use JSR223 Test Elements and __groovy() function。所以考虑在下一个可用的机会上转移到Groovy。更多信息:Apache Groovy - Why and How You Should Use It