我努力了:
//${__FileToString(C:\\QC\\qa\\Testlink\\Jmeter\\Expected\\test.xml,ASCII,${xmlFile})};
发现错误信息:org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``//<?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/At . . . '' Encountered "<" at line 2, column 1.
另外,我尝试过${__StringFromFile}
并得到相同的错误消息,甚至使用 beanshell 脚本:
import org.apache.jmeter.services.FileServer;
//Open the file
FileInputStream fstream = new FileInputStream("C://QC//qa//Testlink//Jmeter//Expected//test.xml");
//Get the object of DataInputStream
DataInputStream instream = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(instream));
尝试以下操作:
- Add 豆壳取样器 http://jmeter.apache.org/usermanual/component_reference.html#BeanShell_Sampler到您的测试计划
-
将以下代码放入采样器的“脚本”区域:
import org.apache.commons.io.FileUtils;
try {
String content = FileUtils.readFileToString(new File("C:/QC/qa/Testlink/Jmeter/Expected/test.xml"));
vars.put("content", content);
} catch (Throwable ex) {
log.info("Failed to read \"test.xml\" file", ex);
throw ex;
}
Add 调试采样器 http://jmeter.apache.org/usermanual/component_reference.html#Debug_Sampler and 查看结果树 http://jmeter.apache.org/usermanual/component_reference.html#View_Results_Tree聆听您的测试计划
- 运行测试
- 确保 Beanshell Sampler 是绿色的并且
${content}
变量已设置。如果没有 - 调查一下jmeter.log文件并搜索该行Failed to read "test.xml" file
。如果该行下面的异常堆栈跟踪没有告诉您任何内容 - 将其发布到此处。
See 如何使用 BeanShell:JMeter 最喜欢的内置组件 https://blazemeter.com/blog/queen-jmeters-built-componentshow-use-beanshell有关在 JMeter 测试中使用 Beanshell 的更多信息,请参阅指南。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)