Need help on on Groovy or condition

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Need help on on Groovy or condition

niraj
Hi,

Can someone please tell me what is wrong in below code? I am trying to
verify if testName is not equal to test 1 or test 2. Both expressions are
not working.


${__groovy(!vars.get('testName').contains("test1"))} ||
${__groovy(!vars.get('testName').contains("test2"),)}

${__groovy(!vars.get('testName').contains(" test1 ")||(" test2 ),)}

Thanks in advance,
Niraj
Reply | Threaded
Open this post in threaded view
|

Re: Need help on on Groovy or condition

Felix Schumacher

Am 06.05.19 um 12:58 schrieb Niraj:

> Hi,
>
> Can someone please tell me what is wrong in below code? I am trying to
> verify if testName is not equal to test 1 or test 2. Both expressions are
> not working.
>
>
> ${__groovy(!vars.get('testName').contains("test1"))} ||
> ${__groovy(!vars.get('testName').contains("test2"),)}
>
> ${__groovy(!vars.get('testName').contains(" test1 ")||(" test2 ),)}

Here are some pointers, why the code fragments don't work as expected:

* vars.get('testName') will give you a String. Strings don't have a
contain method, so "vars.get('name').contains('something')" will not work.

* (" test2 ) is not a valid groovy expression and therefore will not work.

Now to get something meaningful. I assume, that you want to do an exact
match on the var 'testName'. Then one possibility would be to use a List
which has a contains method. That could be expressed as

${__groovy(!['test1'\, 'test2'].contains(vars.get('testName')))}

Note the backslash before the comma. It is needed to distinguish between
a comma inside the groovy expression and a parameter for the JMeter
groovy function.

Regards

 ¬†Felix

>
> Thanks in advance,
> Niraj
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]