JMeter BeanShell Assertion 在 " " 之后登记了 "\"



My BeanShell断言返回以下结果作为错误:

断言错误:true
断言失败:false
断言失败消息:org.apache.jorphan.util.JMeterException:调用bsh方法时出错:eval
源文件:内联求值:``String sentText=\"Changed the TEXT\";String receivedText="更改了文本";…''令牌分析错误:第2行第18列出现词法错误。遇到:"\\"(92),在:"之后

我使用BeanShell预处理器设置了如下属性,并在编辑中使用它,效果很好。

${__setProperty(textEdit,\"Changed the TEXT\")}

然后,我使用get调用获取信息,并使用下面的正则表达式获取特定信息。

\"edittedText\":(\".*?\")}

然后,我使用BeanShell断言将正则表达式的结果放入属性textEditPost中,如下所示。在BeanShell断言中,我还检查更改后的值是否为新值。

${__setProperty(textEditPost,${textEditPost})}
String sentText = ${__property(textEdit)};
String receivedText = ${__property(textEditPost)};
if (sentText.equals(receivedText))
{
    Failure = false;
}
else
{
    Failure = true;
    FailureMessage = "The Text does not match, expected: " + sentText + " but found: " + receivedText;
}

我完全不知道遇到两个反斜杠时的错误是从哪里来的,因为两个字符串都包含相同的数据。有人知道为什么会发生这种情况以及可能的解决方案吗?

我在为其他事情做了一些BeanShell断言后发现了这个问题。我现在也觉得很愚蠢,因为我没有早点意识到这一点。。。

问题是textEdit属性中的值是"Changed the TEXT",因此以反斜杠开头。由于这个反斜杠,程序在尝试将其分配给字符串变量sentText或直接在if语句中使用该属性时,不知道该如何处理它。

通过将属性调用放在引号之间,程序可以将其正确地保存在String变量中。像这样:

${__setProperty(textEditPost,${textEditPost})}
String sentText = "${__property(textEdit)}";
String receivedText = "${__property(textEditPost)}";
if (sentText.equals(receivedText))
{
    Failure = false;
}
else
{
    Failure = true;
    FailureMessage = "The Text does not match, expected: " + sentText + " but found: " + receivedText;
}

我希望这也能帮助其他有类似问题的人。

相关内容

最新更新