Search code examples
jmeterbeanshell

Jmeter Beanshell Assertion arithmetic operators


I am trying to get a Beanshell Assertion in Jmeter to perform an arithmetic operation on the result of a JDBC query.

Basically, I'm querying the number of rows in a table, and want Beanshell to fail the assertion of the number of rows > 0.

a = vars.get("F_1");


if (a > 0)
{
    Failure = false;
}

else
{
    Failure = true;
    FailureMessage = "Threshold breach: " + actual;
}

In this case, F_1 is the Jmeter variable obtained from the JDBC query.

I get the following error:

Operator: '">"' inappropriate for objects

If I apply a type to the variable:

int a = vars.get("F_1")

I get the following error:

Typed variable declaration

Any help appreciated.

(I'm an Ops guy trying to do Java. Be nice.)


Solution

  • for integer datatype please try following code int a = Integer.parseInt(a);