1
votes

My BeanShell Assertion returns the following result as error:

Assertion error: true
Assertion failure: false
Assertion failure message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval
Sourced file: inline evaluation of: `` String sentText = \"Changed the TEXT\"; String receivedText = \"Changed the TEXT\"; . . . '' Token Parsing Error: Lexical error at line 2, column 18. Encountered: "\\" (92), after : ""

I have used a BeanShell PreProcessor to set a property as following and I use it in an edit, which works fine.

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

Then I get the information using a GET call and I use the following regular expression to get that specific information back.

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

Then I use BeanShell Assertion to put the result from that regular expression in the property textEditPost like this. In that BeanShell Assertion I also check if the changed value is the new value.

${__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;
}

I have absolutely no idea where the error on encountering the two backslashes is coming from, as both Strings contain the same data. Does anyone have an idea why this is happening and a possible solution?

1

1 Answers

0
votes

I have found the problem after making some BeanShell Assertions for other things. And I also feel pretty stupid now for not realizing this earlier...

The problem is that the value in the property textEdit is \"Changed the TEXT\" and thus starts with a backslash. Due to this backslash the program has no idea what to do with it when trying to assign it to the String variable sentText or when using the property directly in the if statement.

By placing the property call between quotes the program can properly save it in the String variable. Like this:

${__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;
}

I hope this can help others with similar problems too.