如何在JMeter中用动态值替换具有特殊字符的文件内容

时间:2019-05-22 21:05:36

标签: jmeter

即使文件具有特殊字符,我也可以用动态内容替换文件内容。

这就是我尝试这样做时得到的。 enter image description here

这就是我的文件的样子

[{"someName": "M`o\c\k","someNumber": "${randomNumber}"}]

并且我为${randomNumber}配置了一个变量。

2 个答案:

答案 0 :(得分:1)

请检查以下内容是否满足您的要求。

随机变量配置:- enter image description here 用于json的虚拟采样器 enter image description here JSR223后处理器将虚拟响应放入变量中 enter image description here 在HTTP中使用了变量。这仅用于演示。在您的情况下,可能是websocket。 enter image description here 输出量 enter image description here

此外,groovy还提供json支持。您可以在下面检查基于groovy的类似解决方案。提到要转义json特殊字符的地方。

Jmeter Groovy how can I replace this string with {

希望这会有所帮助。

答案 1 :(得分:0)

我能够通过向JMeter JSON.Simple添加json库来解决我的情况。我将罐子添加到了jmeter classpath中。然后我就能BeanShell PreProcessor

enter image description here

Json简单对象不会转义特殊字符,并且更易于操作。因此,这对于我的用例来说是很棒的。