Jmeter在SOAP/xml请求中删除空字符串 [英] Jmeter remove empty strings at a SOAP/xml request

查看:154
本文介绍了Jmeter在SOAP/xml请求中删除空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有CSV和SOAP/xml请求的Jmeter". 我的测试在80个数据集中运行,并且CSV中的某些字段对于测试问题必须为空.

I am using "Jmeter with CSV and SOAP/xml request". My tests are running within like 80 data sets and some fields in the CSV must be empty for testing issues.

我的JMeter版本: -线程组 -CSV数据 -SOAP/XML -XPathExtractor -结果

My JMeter Build: -ThreadGroup -CSV Data -SOAP/XML -XPathExtractor -Outcome

CSV,如矩阵表,多行和多列.

CSV like a matrix table, multiple rows and columns.

SOAP/XML

...
<attribute xsi:type="ns2:stringType" name = "freeText2">
<value>${freeText2}</value>
</attribute>
<attribute xsi:type="ns2:longType" name = "amount">
<value>${amount}</value>
</attribute>
...

我的问题: 当Jmeter替换了变量时:

My Problem: When Jmeter has replaced the varibles:

<attribute xsi:type="ns2:stringType" name = "freeText2">
<value>This is my free Text</value>
</attribute>
<attribute xsi:type="ns2:longType" name = "amount">
<value>455667</value>
</attribute>

一切都很好 但是当有些空的时候

ALL IS FINE BUT when some are empty

<attribute xsi:type="ns2:stringType" name = "freeText2">
<value></value> ==>interpreted as STRING
</attribute>
<attribute xsi:type="ns2:longType" name = "amount">
<value></value> ==>interpreted as STRING
</attribute>

系统告诉我不可能有大量的",并且我也不想在我的系统中包含带有"的空字符串的freeText2.

The System tells me that "Long Amount with "" is not possible" and also i dont want to have in my System a freeText2 with "" empty String.

现在我的问题是: 有什么办法可以浪费适配器/处理程序/提取器...什么都可以将请求空字符串转换为空(不是Null,因为它会抛出NullPointerException),就像==>

Now my Question: Is there any way to wirte a adapter/handler/extractor...anything to get the Request empty String converted just to nothing (not Null because it will throw me a NullPointerException) like ==>

<attribute xsi:type="ns2:longType" name = "amount">
<value></value>
</attribute>

转换为

<attribute xsi:type="ns2:longType" name = "amount">

</attribute>

推荐答案

如果我正确地回答了您的问题,并且您需要消除空值的出现,例如删除所有<value></value>元素,则可以使用Beanshell轻松完成.

If I'm correctly getting your question and you need to get rid of empty values occurrences like remove all <value></value> elements it can be easily done using Beanshell.

  1. 添加 Beanshell预处理器 作为子级有问题的SOAP/XML-RPC请求

  1. Add a Beanshell Pre Processor as a child of problematic SOAP/XML-RPC Request

将以下代码插入脚本"区域:

Insert the following code into "Script" area:

String data = sampler.getXmlData();
data = data.replaceAll("<value></value>","");
sampler.setXmlData(data);

  • 运行测试

  • Run your test

    Beanshell预处理程序在请求之前执行,因此它将用空字符串替换所有出现的<value></value>

    Beanshell Pre Processor is executed before request so it'll replace all occurrences of <value></value> with an empty string

    您可以参考如何使用BeanShell:JMeter最喜欢的内置工具组件指南,了解有关将Beanshell与Apache JMeter一起使用的扩展信息.

    You can refer to How to use BeanShell: JMeter's favorite built-in component guide for extended information on using Beanshell with Apache JMeter.

    这篇关于Jmeter在SOAP/xml请求中删除空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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