You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Michel Duijvestijn <du...@gmail.com> on 2010/12/22 12:33:58 UTC

Using JMeter variables in Javascript function

In the documentation about the __javaScript function is stated that:

"The following variables are made available to the script:
* ...
* vars - JMeterVariables object
* ..."

Being rather new to JMeter I don't understand how to use this vars-object.
I found out that you can use a variable name within quotes like
${__javaScript(myOutput='${myVar}';,myOutput)}
but is this the only/best way to work with JMeter variables?

What I finally want to do is joining the value of quite a number of
JMeter variables (obtained with the ForEach controller) into a long
string. Something like
${__javaScript(myOutput ='';for (i=0;i<=99;i++){myOutput = myOutput +
'${myVar_' + i + '}';},myOutput)}.
This should join the values of ${myVar_1} to ${myVar_99} into one
(parameter)string.

Thanks for your help!
---
Michel Duijvestijn <du...@gmail.com>
Rotterdam University

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


Re: Using JMeter variables in Javascript function

Posted by Michel Duijvestijn <du...@gmail.com>.
Yes!!! That was the information I needed!
${__javaScript(for (i=0;i<=5;i++){myOutput=myOutput +
vars.get("myVar_"+i)+'&'};,myOutput)}
gives me the desired output!
Thanks again Sebb!

2010/12/22 sebb <se...@gmail.com>:
> On 22 December 2010 13:10, Michel Duijvestijn <du...@gmail.com> wrote:
>> Thx Sebb and Felix (Excuse!)
>>
>> @Felix: the $1$$2$$3$ is giving me only the results within one single
>> match, so that is not a solution.
>>
>> @Sebb: you wrote: "No, you can also use the vars Javascript object."
>> Does that give me access to the whole set of JMeter variables in some
>> way or another?
>
> Yes.
>
>> If so, can you give me a hint or an example how to do that?
>
> See the details of using vars in the BeanShell sampler.
>
> http://jakarta.apache.org/jmeter/usermanual/component_reference.html#BeanShell_Sampler
>
> I'm not all that familiar with Javascript, but AFAIK it can use
> variables such as "vars" using much the same syntax.
>
>> Michel
>>
>> 2010/12/22 sebb <se...@gmail.com>:
>>> On 22 December 2010 11:33, Michel Duijvestijn <du...@gmail.com> wrote:
>>>> In the documentation about the __javaScript function is stated that:
>>>>
>>>> "The following variables are made available to the script:
>>>> * ...
>>>> * vars - JMeterVariables object
>>>> * ..."
>>>>
>>>> Being rather new to JMeter I don't understand how to use this vars-object.
>>>
>>> This is a Javascript object, not a JMeter variable.
>>>
>>>> I found out that you can use a variable name within quotes like
>>>> ${__javaScript(myOutput='${myVar}';,myOutput)}
>>>> but is this the only/best way to work with JMeter variables?
>>>
>>> No, you can also use the vars Javascript object.
>>>
>>>> What I finally want to do is joining the value of quite a number of
>>>> JMeter variables (obtained with the ForEach controller) into a long
>>>> string. Something like
>>>> ${__javaScript(myOutput ='';for (i=0;i<=99;i++){myOutput = myOutput +
>>>> '${myVar_' + i + '}';},myOutput)}.
>>>> This should join the values of ${myVar_1} to ${myVar_99} into one
>>>> (parameter)string.
>>>>
>>>> Thanks for your help!
>>>> ---
>>>> Michel Duijvestijn <du...@gmail.com>
>>>> Rotterdam University

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


Re: Using JMeter variables in Javascript function

Posted by sebb <se...@gmail.com>.
On 22 December 2010 13:10, Michel Duijvestijn <du...@gmail.com> wrote:
> Thx Sebb and Felix (Excuse!)
>
> @Felix: the $1$$2$$3$ is giving me only the results within one single
> match, so that is not a solution.
>
> @Sebb: you wrote: "No, you can also use the vars Javascript object."
> Does that give me access to the whole set of JMeter variables in some
> way or another?

Yes.

> If so, can you give me a hint or an example how to do that?

See the details of using vars in the BeanShell sampler.

http://jakarta.apache.org/jmeter/usermanual/component_reference.html#BeanShell_Sampler

I'm not all that familiar with Javascript, but AFAIK it can use
variables such as "vars" using much the same syntax.

> Michel
>
> 2010/12/22 sebb <se...@gmail.com>:
>> On 22 December 2010 11:33, Michel Duijvestijn <du...@gmail.com> wrote:
>>> In the documentation about the __javaScript function is stated that:
>>>
>>> "The following variables are made available to the script:
>>> * ...
>>> * vars - JMeterVariables object
>>> * ..."
>>>
>>> Being rather new to JMeter I don't understand how to use this vars-object.
>>
>> This is a Javascript object, not a JMeter variable.
>>
>>> I found out that you can use a variable name within quotes like
>>> ${__javaScript(myOutput='${myVar}';,myOutput)}
>>> but is this the only/best way to work with JMeter variables?
>>
>> No, you can also use the vars Javascript object.
>>
>>> What I finally want to do is joining the value of quite a number of
>>> JMeter variables (obtained with the ForEach controller) into a long
>>> string. Something like
>>> ${__javaScript(myOutput ='';for (i=0;i<=99;i++){myOutput = myOutput +
>>> '${myVar_' + i + '}';},myOutput)}.
>>> This should join the values of ${myVar_1} to ${myVar_99} into one
>>> (parameter)string.
>>>
>>> Thanks for your help!
>>> ---
>>> Michel Duijvestijn <du...@gmail.com>
>>> Rotterdam University
>>>
>
> ---------------------------------------------------------------------
> 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: Using JMeter variables in Javascript function

Posted by Michel Duijvestijn <du...@gmail.com>.
Thx Sebb and Felix (Excuse!)

@Felix: the $1$$2$$3$ is giving me only the results within one single
match, so that is not a solution.

@Sebb: you wrote: "No, you can also use the vars Javascript object."
Does that give me access to the whole set of JMeter variables in some
way or another? If so, can you give me a hint or an example how to do
that?

Michel

2010/12/22 sebb <se...@gmail.com>:
> On 22 December 2010 11:33, Michel Duijvestijn <du...@gmail.com> wrote:
>> In the documentation about the __javaScript function is stated that:
>>
>> "The following variables are made available to the script:
>> * ...
>> * vars - JMeterVariables object
>> * ..."
>>
>> Being rather new to JMeter I don't understand how to use this vars-object.
>
> This is a Javascript object, not a JMeter variable.
>
>> I found out that you can use a variable name within quotes like
>> ${__javaScript(myOutput='${myVar}';,myOutput)}
>> but is this the only/best way to work with JMeter variables?
>
> No, you can also use the vars Javascript object.
>
>> What I finally want to do is joining the value of quite a number of
>> JMeter variables (obtained with the ForEach controller) into a long
>> string. Something like
>> ${__javaScript(myOutput ='';for (i=0;i<=99;i++){myOutput = myOutput +
>> '${myVar_' + i + '}';},myOutput)}.
>> This should join the values of ${myVar_1} to ${myVar_99} into one
>> (parameter)string.
>>
>> Thanks for your help!
>> ---
>> Michel Duijvestijn <du...@gmail.com>
>> Rotterdam University
>>

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


Re: Using JMeter variables in Javascript function

Posted by sebb <se...@gmail.com>.
On 22 December 2010 11:33, Michel Duijvestijn <du...@gmail.com> wrote:
> In the documentation about the __javaScript function is stated that:
>
> "The following variables are made available to the script:
> * ...
> * vars - JMeterVariables object
> * ..."
>
> Being rather new to JMeter I don't understand how to use this vars-object.

This is a Javascript object, not a JMeter variable.

> I found out that you can use a variable name within quotes like
> ${__javaScript(myOutput='${myVar}';,myOutput)}
> but is this the only/best way to work with JMeter variables?

No, you can also use the vars Javascript object.

> What I finally want to do is joining the value of quite a number of
> JMeter variables (obtained with the ForEach controller) into a long
> string. Something like
> ${__javaScript(myOutput ='';for (i=0;i<=99;i++){myOutput = myOutput +
> '${myVar_' + i + '}';},myOutput)}.
> This should join the values of ${myVar_1} to ${myVar_99} into one
> (parameter)string.
>
> Thanks for your help!
> ---
> Michel Duijvestijn <du...@gmail.com>
> Rotterdam University
>
> ---------------------------------------------------------------------
> 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: Using JMeter variables in Javascript function

Posted by Felix Frank <ff...@mpexnet.de>.
On 12/22/2010 12:56 PM, Michel Duijvestijn wrote:
> Thx Frank

It's "Felix".

> I have one sampler response in which ther is all the information I need,
> I'm using a regular expression extractor which gives the (say) 99
> matches. Within this postprocessor I can (as far as I know) only use
> one match (myVar). By using a negative number in the match No.
> parameter in combination with the ForEach controller (added
> afterwards) gives me effectively 99 variables.

You could set the Regex extractor template to $1$$2$$3$...
I'd advice to generate that string programatically outside of Jmeter.

Cheers,
Felix

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


Re: Using JMeter variables in Javascript function

Posted by Michel Duijvestijn <du...@gmail.com>.
Thx Frank

I have one sampler response in which ther is all the information I need,
I'm using a regular expression extractor which gives the (say) 99
matches. Within this postprocessor I can (as far as I know) only use
one match (myVar). By using a negative number in the match No.
parameter in combination with the ForEach controller (added
afterwards) gives me effectively 99 variables.

Michel

2010/12/22 Felix Frank <ff...@mpexnet.de>:
> On 12/22/2010 12:33 PM, Michel Duijvestijn wrote:
>> In the documentation about the __javaScript function is stated that:
>>
>> "The following variables are made available to the script:
>> * ...
>> * vars - JMeterVariables object
>> * ..."
>>
>> Being rather new to JMeter I don't understand how to use this vars-object.
>> I found out that you can use a variable name within quotes like
>> ${__javaScript(myOutput='${myVar}';,myOutput)}
>> but is this the only/best way to work with JMeter variables?
>>
>> What I finally want to do is joining the value of quite a number of
>> JMeter variables (obtained with the ForEach controller) into a long
>> string. Something like
>> ${__javaScript(myOutput ='';for (i=0;i<=99;i++){myOutput = myOutput +
>> '${myVar_' + i + '}';},myOutput)}.
>> This should join the values of ${myVar_1} to ${myVar_99} into one
>> (parameter)string.
>
> Careful: ${bla} substitution takes place before any javascript is run
> (before the __javaScript function is called at all, actually), so this
> approach will not work.
>
> I'm not sure how you obtian those values, but maybe you would fare
> better by using a PostProcessor in your loop that takes care of the
> concatenation while you are still gathering values.
>
> HTH,
> Felix
>
> ---------------------------------------------------------------------
> 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: Using JMeter variables in Javascript function

Posted by Felix Frank <ff...@mpexnet.de>.
On 12/22/2010 12:33 PM, Michel Duijvestijn wrote:
> In the documentation about the __javaScript function is stated that:
> 
> "The following variables are made available to the script:
> * ...
> * vars - JMeterVariables object
> * ..."
> 
> Being rather new to JMeter I don't understand how to use this vars-object.
> I found out that you can use a variable name within quotes like
> ${__javaScript(myOutput='${myVar}';,myOutput)}
> but is this the only/best way to work with JMeter variables?
> 
> What I finally want to do is joining the value of quite a number of
> JMeter variables (obtained with the ForEach controller) into a long
> string. Something like
> ${__javaScript(myOutput ='';for (i=0;i<=99;i++){myOutput = myOutput +
> '${myVar_' + i + '}';},myOutput)}.
> This should join the values of ${myVar_1} to ${myVar_99} into one
> (parameter)string.

Careful: ${bla} substitution takes place before any javascript is run
(before the __javaScript function is called at all, actually), so this
approach will not work.

I'm not sure how you obtian those values, but maybe you would fare
better by using a PostProcessor in your loop that takes care of the
concatenation while you are still gathering values.

HTH,
Felix

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