如何在JMeter中读取XML文件? [英] How to read XML file in JMeter?

查看:708
本文介绍了如何在JMeter中读取XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过了:

// $ {__ FileToString(C:\\QC \\ qa \\ Testlink \\Jmeter \\ Expected\\test.xml,ASCII,$ {xmlFile})};

发现错误消息:
org.apache.jorphan.util.JMeterException:调用bsh方法时出错:eval在文件中:内联评估:``//<?xml version = 1.0encoding =UTF-8?> < feed xmlns =http://www.w3.org/2005/At ...''遇到'<在第2行第1列。

Found error message : 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脚本:

also, I tried with ${__StringFromFile} and got the same error message and even with beanshell script that is:

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. 将以下代码放入采样器中脚本区域:

  1. Add Beanshell Sampler to your Test Plan
  2. Put the following code into the sampler's "Script" area:

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;
}


  • 添加 Debug Sampler 查看结果树听众到您的测试计划

  • Add Debug Sampler and View Results Tree listener to your Test Plan

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

    See How to Use BeanShell: JMeter's Favorite Built-in Component guide for more information on using Beanshell in your JMeter test.

    这篇关于如何在JMeter中读取XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆