You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by "Kannan, Sengamalam" <Se...@AIG.COM> on 2009/03/31 11:23:25 UTC

Variable substitution in BeanShell Post Processor

Regular Expression Variable names are DateVal_1, DateVal_2, etc. In a for-loop within Beanshell post processor, I want to use these variables using variable substitution like DateVal_i if i is counter variable.

Problem:
Tried the following code but didn't work.

daten = vars.get("DateVal_matchNr");
begindt=vars.get("begin")
i=0;
for (int p = 0; p <= daten; p++)
{
   if (begin.equals(eval("DateVal_"+p)))
   {

     leave = vars.get(eval("LeaveNum_"+i));
     vars.put("leavenumber", leave);
    }
   i++;
}

I don't know how to use eval function within vars.get and retrieve the value of the variable.

Please help!


Thanks & Regards
Sengamalam Kannan
Testing CoE
Mobile: +91 99529 67005
Tel: +91 44 6615 2684


RE: Variable substitution in BeanShell Post Processor

Posted by "Kannan, Sengamalam" <Se...@AIG.COM>.
Sebb,
Its working now. Thanks. I tried the concatenation on beanshell editor and it doesn't work but in jMeter it worked.

Thanks & Regards
Sengamalam Kannan
Testing CoE
Mobile: +91 99529 67005
Tel: +91 44 6615 2684

-----Original Message-----
From: Kannan, Sengamalam [mailto:Sengamalam.Kannan@AIG.COM]
Sent: Tuesday, March 31, 2009 3:30 PM
To: JMeter Users List
Subject: RE: Variable substitution in BeanShell Post Processor

Thanks Sebb for your quick reply.

Without using eval function if I try

 if (begin.equals(vars.get("DateVal_"+p)))

vars.get("LeaveNum_"+i);

is not working as its taking "LeaveNum_" & "DateVal_" as a variable which doesn't exists.

I cannot use foreach controller for this as I have to compare the Regular Expression values (DateVal_1,2,etc) with a value in CSV Data config file and based on the comparison assign a value to a variable and pass  the same to the next HTTP request.

Please help!


Thanks & Regards
Sengamalam Kannan
Testing CoE
Mobile: +91 99529 67005
Tel: +91 44 6615 2684

-----Original Message-----
From: sebb [mailto:sebbaz@gmail.com]
Sent: Tuesday, March 31, 2009 3:23 PM
To: JMeter Users List
Subject: Re: Variable substitution in BeanShell Post Processor

On 31/03/2009, Kannan, Sengamalam <Se...@aig.com> wrote:
> Regular Expression Variable names are DateVal_1, DateVal_2, etc. In a for-loop within Beanshell post processor, I want to use these variables using variable substitution like DateVal_i if i is counter variable.
>
>  Problem:
>  Tried the following code but didn't work.
>
>  daten = vars.get("DateVal_matchNr");
>  begindt=vars.get("begin")
>  i=0;
>  for (int p = 0; p <= daten; p++)
>  {
>    if (begin.equals(eval("DateVal_"+p)))
>    {
>
>      leave = vars.get(eval("LeaveNum_"+i));
>      vars.put("leavenumber", leave);
>     }
>    i++;
>  }
>
>  I don't know how to use eval function within vars.get and retrieve the value of the variable.

There is no JMeter eval function in BeanShell.

To retrieve the value of a variable in BeanShell, use

get(<String name of variable>)

This is what you have done for daten and begindt.
Just do the same for variable names that you need to construct -
create a string containing the full variable name, e.g. using
concatenation.

Just remove the eval method calls.

>  Please help!
>
>
>  Thanks & Regards
>
> Sengamalam Kannan
>  Testing CoE
>  Mobile: +91 99529 67005
>  Tel: +91 44 6615 2684
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


RE: Variable substitution in BeanShell Post Processor

Posted by "Kannan, Sengamalam" <Se...@AIG.COM>.
Thanks Sebb for your quick reply.

Without using eval function if I try

 if (begin.equals(vars.get("DateVal_"+p)))

vars.get("LeaveNum_"+i);

is not working as its taking "LeaveNum_" & "DateVal_" as a variable which doesn't exists.

I cannot use foreach controller for this as I have to compare the Regular Expression values (DateVal_1,2,etc) with a value in CSV Data config file and based on the comparison assign a value to a variable and pass  the same to the next HTTP request.

Please help!


Thanks & Regards
Sengamalam Kannan
Testing CoE
Mobile: +91 99529 67005
Tel: +91 44 6615 2684

-----Original Message-----
From: sebb [mailto:sebbaz@gmail.com]
Sent: Tuesday, March 31, 2009 3:23 PM
To: JMeter Users List
Subject: Re: Variable substitution in BeanShell Post Processor

On 31/03/2009, Kannan, Sengamalam <Se...@aig.com> wrote:
> Regular Expression Variable names are DateVal_1, DateVal_2, etc. In a for-loop within Beanshell post processor, I want to use these variables using variable substitution like DateVal_i if i is counter variable.
>
>  Problem:
>  Tried the following code but didn't work.
>
>  daten = vars.get("DateVal_matchNr");
>  begindt=vars.get("begin")
>  i=0;
>  for (int p = 0; p <= daten; p++)
>  {
>    if (begin.equals(eval("DateVal_"+p)))
>    {
>
>      leave = vars.get(eval("LeaveNum_"+i));
>      vars.put("leavenumber", leave);
>     }
>    i++;
>  }
>
>  I don't know how to use eval function within vars.get and retrieve the value of the variable.

There is no JMeter eval function in BeanShell.

To retrieve the value of a variable in BeanShell, use

get(<String name of variable>)

This is what you have done for daten and begindt.
Just do the same for variable names that you need to construct -
create a string containing the full variable name, e.g. using
concatenation.

Just remove the eval method calls.

>  Please help!
>
>
>  Thanks & Regards
>
> Sengamalam Kannan
>  Testing CoE
>  Mobile: +91 99529 67005
>  Tel: +91 44 6615 2684
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Variable substitution in BeanShell Post Processor

Posted by sebb <se...@gmail.com>.
On 31/03/2009, Kannan, Sengamalam <Se...@aig.com> wrote:
> Regular Expression Variable names are DateVal_1, DateVal_2, etc. In a for-loop within Beanshell post processor, I want to use these variables using variable substitution like DateVal_i if i is counter variable.
>
>  Problem:
>  Tried the following code but didn't work.
>
>  daten = vars.get("DateVal_matchNr");
>  begindt=vars.get("begin")
>  i=0;
>  for (int p = 0; p <= daten; p++)
>  {
>    if (begin.equals(eval("DateVal_"+p)))
>    {
>
>      leave = vars.get(eval("LeaveNum_"+i));
>      vars.put("leavenumber", leave);
>     }
>    i++;
>  }
>
>  I don't know how to use eval function within vars.get and retrieve the value of the variable.

There is no JMeter eval function in BeanShell.

To retrieve the value of a variable in BeanShell, use

get(<String name of variable>)

This is what you have done for daten and begindt.
Just do the same for variable names that you need to construct -
create a string containing the full variable name, e.g. using
concatenation.

Just remove the eval method calls.

>  Please help!
>
>
>  Thanks & Regards
>
> Sengamalam Kannan
>  Testing CoE
>  Mobile: +91 99529 67005
>  Tel: +91 44 6615 2684
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org