繁体   English   中英

如何在JMeter中读取XML文件?

[英]How to read XML file in JMeter?

我试过了:

//${__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));

试试以下内容:

  1. Beanshell Sampler添加到您的测试计划中
  2. 将以下代码放入采样器的“脚本”区域:

     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; } 
  3. Debug SamplerView Results Tree监听添加到您的测试计划中

  4. 运行测试
  5. 确保Beanshell Sampler为绿色且设置了${content}变量。 如果不是 - 查看jmeter.log文件并搜索Failed to read "test.xml" file 如果此行下面的异常堆栈跟踪告诉您什么 - 在此处发布。

有关在JMeter测试中使用Beanshell的更多信息,请参见如何使用BeanShell:JMeter最喜欢的内置组件指南。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM