简体   繁体   English

HTTP 请求中的 XML 主体数据中的参数 (JMETER)

[英]Parameters in an XML body data in an HTTP Request (JMETER)

I have a problem and I can't find any solution... I am actually developing a test for a Web Service (let's call it WS).我有一个问题,我找不到任何解决方案......我实际上正在为 Web 服务(我们称之为 WS)开发测试。

To test it, I have an HTTP Request, with in the body data as XML.为了测试它,我有一个 HTTP 请求,正文数据为 XML。 The problem is that in this XML, I would like some attributes to be variable (or parameters I could change).问题是在这个 XML 中,我希望某些属性是可变的(或我可以更改的参数)。

For example, here is the XML file:例如,这里是 XML 文件:

    <measure>
        <time>2020-04-07T10:45:00</time>
        <value index="0">
            <value>
                <basicData xsi:type="DATA1">
                    <data1 data1number="10">
                        <numberd1>13</numberd1>
                    </data1>
                </basicData>
            </value>
        </value>
        <value index="0">
            <measuredValue>
                <basicData xsi:type="DATA2">
                    <data2 data2number="8">
                        <numberd2>22</numberd2>
                    </data2>
                </basicData>
            </value>
        </value>
    </measure>

I would like to get random values or variables values for the numberd1 and numberd2.我想获得 numberd1 和 numberd2 的随机值或变量值。 Is it possible to modify some attributes in the XML body data of an HTTP Request in JMETER?是否可以修改 JMETER 中 HTTP 请求的 XML 主体数据中的某些属性?

The XML in the body data would be a template, which would change with the different parameters (number d1n number d2) that would change.身体数据中的 XML 将是一个模板,它会随着不同的参数(数字 d1n 数字 d2)而改变。

Thank you for any anwser.谢谢你的任何回答。

Sure you can, for random numeric values you can substitute hard-coded numbers with __Random() function like:当然可以,对于随机数值,您可以用__Random() function替换硬编码数字,例如:

<numberd1>${__Random(0,100,)}</numberd1>

and

<numberd2>${__Random(0,100,)}</numberd2>

this way you will have a random number from 0 to 99 inclusively each time the function is called这样,每次调用 function 时,您将有一个从 0 到 99 的随机数

在此处输入图像描述


If you want the tests to be repeatable another option is to pre-generate numberd1 and numberd2 pairs, store them into a CSV file and use CSV Data Set Config for feeding the request with the values from the CSV file.如果您希望测试可重复,另一种选择是预先生成numberd1numberd2对,将它们存储到 CSV 文件中,并使用CSV 数据集配置为请求提供来自 ZCC8D68C551C4A9AFDZDE5331 文件的值。

1/ Just replace the content between the opening and closing time tags like this: 1/ 只需像这样替换开始和结束时间标签之间的内容:

  <time>${__time(yyyy-MM-dd'T'hh:mm:ss)}</time>

2/ add a Flow Control Action with a duration equals to 120000 (2min) in child of your thread group: 2/ 在您的线程组的子线程中添加一个持续时间等于 120000(2 分钟)的流控制操作:

在此处输入图像描述

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

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