Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用批处理文件解析JMeterXML响应文件,并在控制台上打印输出_Xml_Batch File_Cmd_Jmeter_Batch Processing - Fatal编程技术网

使用批处理文件解析JMeterXML响应文件,并在控制台上打印输出

使用批处理文件解析JMeterXML响应文件,并在控制台上打印输出,xml,batch-file,cmd,jmeter,batch-processing,Xml,Batch File,Cmd,Jmeter,Batch Processing,我有一个Jmeter响应文件: <?xml version="1.0" encoding="UTF-8"?> <testResults version="1.2"> <httpSample t="22" lt="11" ts="1500633511099" s="true" lb="Url check" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="543" ng="1" na="1"> <

我有一个Jmeter响应文件:

<?xml version="1.0" encoding="UTF-8"?>
<testResults version="1.2">
<httpSample t="22" lt="11" ts="1500633511099" s="true" lb="Url check" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="543" ng="1" na="1">
  <assertionResult>
    <name>Response Assertion</name>
    <failure>false</failure>
    <error>false</error>
  </assertionResult>
  <httpSample t="11" lt="11" ts="1500633511099" s="true" lb="http://ipaddress/application" rc="302" rm="Found" tn="Thread Group 1-1" dt="" by="149" ng="1" na="1"/>
  <httpSample t="10" lt="10" ts="1500633511111" s="true" lb="http://ipaddress/application/" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="394" ng="1" na="1"/>
</httpSample>
<httpSample t="196" lt="196" ts="1500633511133" s="true" lb="Login" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="1204" ng="1" na="1">
  <assertionResult>
    <name>Response Assertion</name>
    <failure>false</failure>
    <error>false</error>
  </assertionResult>
  <assertionResult>
    <name>Response Assertion - HttpOnly</name>
    <failure>false</failure>
    <error>false</error>
  </assertionResult>
</httpSample>
<httpSample t="98" lt="98" ts="1500633511350" s="true" lb="Logout" rc="200" rm="OK" tn="Thread Group 1-1" dt="text" by="986" ng="1" na="1">
  <assertionResult>
    <name>Response Assertion</name>
    <failure>false</failure>
    <error>false</error>
  </assertionResult>
</httpSample>

</testResults>

响应断言
假的
假的
响应断言
假的
假的
响应断言-仅HttpOnly
假的
假的
响应断言
假的
假的
我想使用批处理文件分析此文件,并获得以下属性的输出,即仅值:

  • httpSample->lb
  • httpSample->rc
  • httpSample->rm
  • 我创建了一个批处理文件,如下所示,但不起作用:

    @echo off
    set tag=httpSample
    set f_xml=response.xml
    (for /F "tokens=5,6,7 delims=<=>" %%a in ('findstr "\</%tag%\>" %f_xml%') do echo  (
        IF /i "%%a"=="lb" SET "printme=Y"   %%~a %%b
        IF /i "%%a"=="rc" SET "printme=Y"   %%~a %%b
        IF /i "%%a"=="rm" SET "printme=Y"   %%~a %%b
     )
     )
    
    @echo关闭
    set tag=httpSample
    设置f_xml=response.xml
    (对于/F“tokens=5,6,7 delims=“%%a in('findstr“\%F\u xml%”)do echo(
    如果/i“%%a”==“lb”设置“printme=Y”%%~a%%b
    如果/i“%%a”==“rc”设置“printme=Y”%%~a%%b
    如果/i“%%a”==“rm”设置“printme=Y”%%~a%%b
    )
    )
    
    我还想打印自己的文本作为输出的键。 实际上,这个response.xml没有完整的实际响应,我们在Jmeter GUI中每次调用都会得到这些响应。它只是说明成功或失败。如何在Jmeter非gui模式(即命令行模式)下获取所有响应数据


    例如,如果%%a的输出为
    http://ipaddress/application
    然后我想打印
    ipadders=http://ipaddress/application

    下面的示例仅从提供的特定内容中选择您请求的特定数据

    @Echo关闭
    设置“tag=httpSample”
    设置“f_xml=response.xml”
    对于('FindStr“\”“%F\u xml%”中的/F“Delims=>”%%A
    )Do For/F令牌^=10^、12^、14Delims^=^“%%B In(“%%A”
    )是否回显“%%B”“%%C”“%%D”
    暂停
    

    它可以扩展,但不建议使用批处理文件读取xml数据而不使用其他语言,或者通常不值得这样做。

    如果您希望保存响应数据,您需要明确地“告诉”JMeter这样做,您有以下选项:

  • 特殊(仅一次)设置通过以下方式传递相关属性:

  • 永久设置。如果希望JMeter始终存储响应数据,则需要将上述行添加到user.properties文件(位于JMeter安装的“bin”文件夹中)

    需要重新启动JMeter才能获取属性

  • 参考资料:



    请记住,使用XML格式存储JMeter测试结果,特别是保存响应数据并不是因为它们会产生大量磁盘IO开销,并且可能会对负载测试结果产生负面影响。

    您可以检查->例如,获取
    rc
    调用xpath.bat http.XML//httpSample/@rc“
    powershell”([XML](gc response.xml)).SelectNodes('//httpSample[包含(@lb,\“://\”))|%{\“lb={0}`nrc={1}`nrm={2}\'-f$\\.lb,$\.rc,$\.rm}“
    从cmd控制台,或者如果从.bat脚本调用,则加倍百分号。批处理文件用于在非gui模式下运行Jmeter…因此,首先使用命令行运行Jmeter套件,创建响应xml,然后我希望在控制台上显示响应本身。这样做的更好方法是什么?
    jmeter -Jjmeter.save.saveservice.response_data=true -n -t test.jmx -l result.jtl
    
    jmeter.save.saveservice.response_data=true