JMeter 3.3:无法从文件中读取变量 - 类型化变量声明:Class:在命名空间中找不到 Wini
JMeter 3.3: Cannot read variables from file - Typed variable declaration : Class: Wini not found in namespace
让我介绍一下背景。
如您所见,定义了两个变量,它们使用以下值指向两个不同的 *.ini 文件:
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}Settings.ini
对于变量:SettingsFile
使用分步调试器,我可以确认文件路径是正确的。现在,有趣的部分。
我几乎没有从文件中读取值的“用户定义变量”。
JMeter 无法读取此变量的值并为每个变量抛出以下错误:
使用(例如):用于变量 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 请求。
这是由于缺少 ini4j library, you need to download the .jar, put it somewhere to JMeter Classpath 并重新启动 JMeter 以获取 .jar。
还要注意 starting from JMeter 3.1 it is recommended to use JSR223 Test Elements and __groovy() function for any form of scripting in JMeter. So consider to moving to Groovy on next available opportunity. More information: Apache Groovy - Why and How You Should Use It
让我介绍一下背景。
如您所见,定义了两个变量,它们使用以下值指向两个不同的 *.ini 文件:
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}Settings.ini
对于变量:SettingsFile
使用分步调试器,我可以确认文件路径是正确的。现在,有趣的部分。 我几乎没有从文件中读取值的“用户定义变量”。
JMeter 无法读取此变量的值并为每个变量抛出以下错误:
使用(例如):用于变量 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 请求。
这是由于缺少 ini4j library, you need to download the .jar, put it somewhere to JMeter Classpath 并重新启动 JMeter 以获取 .jar。
还要注意 starting from JMeter 3.1 it is recommended to use JSR223 Test Elements and __groovy() function for any form of scripting in JMeter. So consider to moving to Groovy on next available opportunity. More information: Apache Groovy - Why and How You Should Use It