You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by DjinnS <dj...@chninkel.net> on 2011/05/13 13:39:44 UTC

JavaScript function

Bonjour,

I'm going crazy ! I can't used $__JavaScript{} to get a ratio.

I try to use the following code (in a "User Defined Variable"):

${__JavaScript(Math.round(10*50/100))}

(in fact, "10" is also a value from an another "User Defined Variable")

This code don't work.

If I try a very simple math operation, like this:

${__JavaScript(1+1)}

It's ok !

What's going wrong with my first code ?

Thx in advance,

Rergards,


--
DjinnS

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


Re: JavaScript function

Posted by Felix Frank <ff...@mpexnet.de>.
On 05/13/2011 02:55 PM, DjinnS wrote:
>> See:
>>
>> http://jakarta.apache.org/jmeter/usermanual/functions.html#__javaScript
>>
>>> What's going wrong with my first code ?
>> _Both_ are spelt incorrectly.
> 
> Yes, there is a mistake in my email.
> 
> So, with the correct spelt, my function is:
> 
> ${__javaScript(Math.round(${var}*50/100),total)}
> 
> It isn't working.
> 
> If I follow the documentation, I think I use correctly jemeter's
> variables in function.

Hi,

you should really read that link.

Commas must be escaped in scriptlets.

${__javaScript(Math.round(${var}*50/100)\,total)}

HTH,
Felix

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


Re: JavaScript function

Posted by sebb <se...@gmail.com>.
On 13 May 2011 14:39, DjinnS <dj...@chninkel.net> wrote:
> Le 13/05/2011 15:33, sebb a écrit :
>>
>> On 13 May 2011 14:25, DjinnS<dj...@chninkel.net>  wrote:
>>>
>>> Le 13/05/2011 15:13, sebb a écrit :
>>>>
>>>> On 13 May 2011 13:55, DjinnS<dj...@chninkel.net>    wrote:
>>>>>
>>>>> Le 13/05/2011 13:53, sebb a écrit :
>>>>>>
>>>>>> On 13 May 2011 12:39, DjinnS<dj...@chninkel.net>      wrote:
>>>>>>>
>>>>>>> Bonjour,
>>>>>>>
>>>>>>> I'm going crazy ! I can't used $__JavaScript{} to get a ratio.
>>>>>>>
>>>>>>> I try to use the following code (in a "User Defined Variable"):
>>>>>>>
>>>>>>> ${__JavaScript(Math.round(10*50/100))}
>>>>>>
>>>>>> There is no such function as __JavaScript.
>>>>>>
>>>>>>> (in fact, "10" is also a value from an another "User Defined
>>>>>>> Variable")
>>>>>>>
>>>>>>> This code don't work.
>>>>>>>
>>>>>>> If I try a very simple math operation, like this:
>>>>>>>
>>>>>>> ${__JavaScript(1+1)}
>>>>>>>
>>>>>>> It's ok !
>>>>>>
>>>>>> No, that fails for the same reason.
>>>>>>
>>>>>> See:
>>>>>>
>>>>>>
>>>>>> http://jakarta.apache.org/jmeter/usermanual/functions.html#__javaScript
>>>>>>
>>>>>>> What's going wrong with my first code ?
>>>>>>
>>>>>> _Both_ are spelt incorrectly.
>>>>>
>>>>> Yes, there is a mistake in my email.
>>>>>
>>>>> So, with the correct spelt, my function is:
>>>>>
>>>>> ${__javaScript(Math.round(${var}*50/100),total)}
>>>>>
>>>>> It isn't working.
>>>>
>>>> Works for me, provided that I define the "var" variable.
>>>>
>>>> What makes you think it is not working?
>>>> What are you expecting, what are you getting?
>>>>
>>> Felix,
>>>
>>> Yes, :/ , it's an another ctrl-c/ctrl-v mistake. I use this code in
>>> jmeter:
>>>
>>> ${__javaScript(Math.round(${var}*50/100))}
>>>
>>> Seb,
>>>
>>> I try to get working threads with variables. I have 4 threads groups and
>>> I
>>> want to run many tests with a differents number of simulated users. I
>>> divide
>>> the number of user with a ratio in order to simulate a "real" traffic.
>>>
>>> In the end, the result of the javascript execution is stored in a
>>> variable
>>> used in one on my threads groups.
>>>
>>> It's ok if I replace ${var} with an integer. Obviously, var is defined
>>> before.
>>
>> As you have not said where the var is defined nor where you are using
>> the function call it's impossible to say exactly what's wrong.
>>
>> I assume that var is being used before it has been defined.
>>
>> Try replacing the function call with ${var} and you can confirm this.
>>
>> Try defining var on the Test Plan (this should ensure it is defined
>> very early on).
>>
> Seb,
>
> Yeah, thank you !
>
> You have right about the "position" of my var. My var is defined in the same
> "Users defined variable". If I define var in the test plan, it's ok !

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

says:

"Also, the variables are not available for use until after the element
has been processed, so you cannot reference variables that are defined
in the same element. You can reference variables defined in earlier
UDVs or on the Test Plan. "

> Thank you.
>
> --
> DjinnS
>
> ---------------------------------------------------------------------
> 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: JavaScript function

Posted by DjinnS <dj...@chninkel.net>.
Le 13/05/2011 15:33, sebb a écrit :
> On 13 May 2011 14:25, DjinnS<dj...@chninkel.net>  wrote:
>> Le 13/05/2011 15:13, sebb a écrit :
>>> On 13 May 2011 13:55, DjinnS<dj...@chninkel.net>    wrote:
>>>> Le 13/05/2011 13:53, sebb a écrit :
>>>>> On 13 May 2011 12:39, DjinnS<dj...@chninkel.net>      wrote:
>>>>>> Bonjour,
>>>>>>
>>>>>> I'm going crazy ! I can't used $__JavaScript{} to get a ratio.
>>>>>>
>>>>>> I try to use the following code (in a "User Defined Variable"):
>>>>>>
>>>>>> ${__JavaScript(Math.round(10*50/100))}
>>>>> There is no such function as __JavaScript.
>>>>>
>>>>>> (in fact, "10" is also a value from an another "User Defined Variable")
>>>>>>
>>>>>> This code don't work.
>>>>>>
>>>>>> If I try a very simple math operation, like this:
>>>>>>
>>>>>> ${__JavaScript(1+1)}
>>>>>>
>>>>>> It's ok !
>>>>> No, that fails for the same reason.
>>>>>
>>>>> See:
>>>>>
>>>>> http://jakarta.apache.org/jmeter/usermanual/functions.html#__javaScript
>>>>>
>>>>>> What's going wrong with my first code ?
>>>>> _Both_ are spelt incorrectly.
>>>> Yes, there is a mistake in my email.
>>>>
>>>> So, with the correct spelt, my function is:
>>>>
>>>> ${__javaScript(Math.round(${var}*50/100),total)}
>>>>
>>>> It isn't working.
>>> Works for me, provided that I define the "var" variable.
>>>
>>> What makes you think it is not working?
>>> What are you expecting, what are you getting?
>>>
>> Felix,
>>
>> Yes, :/ , it's an another ctrl-c/ctrl-v mistake. I use this code in jmeter:
>>
>> ${__javaScript(Math.round(${var}*50/100))}
>>
>> Seb,
>>
>> I try to get working threads with variables. I have 4 threads groups and I
>> want to run many tests with a differents number of simulated users. I divide
>> the number of user with a ratio in order to simulate a "real" traffic.
>>
>> In the end, the result of the javascript execution is stored in a variable
>> used in one on my threads groups.
>>
>> It's ok if I replace ${var} with an integer. Obviously, var is defined
>> before.
> As you have not said where the var is defined nor where you are using
> the function call it's impossible to say exactly what's wrong.
>
> I assume that var is being used before it has been defined.
>
> Try replacing the function call with ${var} and you can confirm this.
>
> Try defining var on the Test Plan (this should ensure it is defined
> very early on).
>
Seb,

Yeah, thank you !

You have right about the "position" of my var. My var is defined in the 
same "Users defined variable". If I define var in the test plan, it's ok !

Thank you.

--
DjinnS

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


Re: JavaScript function

Posted by sebb <se...@gmail.com>.
On 13 May 2011 14:25, DjinnS <dj...@chninkel.net> wrote:
> Le 13/05/2011 15:13, sebb a écrit :
>>
>> On 13 May 2011 13:55, DjinnS<dj...@chninkel.net>  wrote:
>>>
>>> Le 13/05/2011 13:53, sebb a écrit :
>>>>
>>>> On 13 May 2011 12:39, DjinnS<dj...@chninkel.net>    wrote:
>>>>>
>>>>> Bonjour,
>>>>>
>>>>> I'm going crazy ! I can't used $__JavaScript{} to get a ratio.
>>>>>
>>>>> I try to use the following code (in a "User Defined Variable"):
>>>>>
>>>>> ${__JavaScript(Math.round(10*50/100))}
>>>>
>>>> There is no such function as __JavaScript.
>>>>
>>>>> (in fact, "10" is also a value from an another "User Defined Variable")
>>>>>
>>>>> This code don't work.
>>>>>
>>>>> If I try a very simple math operation, like this:
>>>>>
>>>>> ${__JavaScript(1+1)}
>>>>>
>>>>> It's ok !
>>>>
>>>> No, that fails for the same reason.
>>>>
>>>> See:
>>>>
>>>> http://jakarta.apache.org/jmeter/usermanual/functions.html#__javaScript
>>>>
>>>>> What's going wrong with my first code ?
>>>>
>>>> _Both_ are spelt incorrectly.
>>>
>>> Yes, there is a mistake in my email.
>>>
>>> So, with the correct spelt, my function is:
>>>
>>> ${__javaScript(Math.round(${var}*50/100),total)}
>>>
>>> It isn't working.
>>
>> Works for me, provided that I define the "var" variable.
>>
>> What makes you think it is not working?
>> What are you expecting, what are you getting?
>>
> Felix,
>
> Yes, :/ , it's an another ctrl-c/ctrl-v mistake. I use this code in jmeter:
>
> ${__javaScript(Math.round(${var}*50/100))}
>
> Seb,
>
> I try to get working threads with variables. I have 4 threads groups and I
> want to run many tests with a differents number of simulated users. I divide
> the number of user with a ratio in order to simulate a "real" traffic.
>
> In the end, the result of the javascript execution is stored in a variable
> used in one on my threads groups.
>
> It's ok if I replace ${var} with an integer. Obviously, var is defined
> before.

As you have not said where the var is defined nor where you are using
the function call it's impossible to say exactly what's wrong.

I assume that var is being used before it has been defined.

Try replacing the function call with ${var} and you can confirm this.

Try defining var on the Test Plan (this should ensure it is defined
very early on).

>
> ---------------------------------------------------------------------
> 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: JavaScript function

Posted by DjinnS <dj...@chninkel.net>.
Le 13/05/2011 15:13, sebb a écrit :
> On 13 May 2011 13:55, DjinnS<dj...@chninkel.net>  wrote:
>> Le 13/05/2011 13:53, sebb a écrit :
>>> On 13 May 2011 12:39, DjinnS<dj...@chninkel.net>    wrote:
>>>> Bonjour,
>>>>
>>>> I'm going crazy ! I can't used $__JavaScript{} to get a ratio.
>>>>
>>>> I try to use the following code (in a "User Defined Variable"):
>>>>
>>>> ${__JavaScript(Math.round(10*50/100))}
>>> There is no such function as __JavaScript.
>>>
>>>> (in fact, "10" is also a value from an another "User Defined Variable")
>>>>
>>>> This code don't work.
>>>>
>>>> If I try a very simple math operation, like this:
>>>>
>>>> ${__JavaScript(1+1)}
>>>>
>>>> It's ok !
>>> No, that fails for the same reason.
>>>
>>> See:
>>>
>>> http://jakarta.apache.org/jmeter/usermanual/functions.html#__javaScript
>>>
>>>> What's going wrong with my first code ?
>>> _Both_ are spelt incorrectly.
>> Yes, there is a mistake in my email.
>>
>> So, with the correct spelt, my function is:
>>
>> ${__javaScript(Math.round(${var}*50/100),total)}
>>
>> It isn't working.
> Works for me, provided that I define the "var" variable.
>
> What makes you think it is not working?
> What are you expecting, what are you getting?
>
Felix,

Yes, :/ , it's an another ctrl-c/ctrl-v mistake. I use this code in jmeter:

${__javaScript(Math.round(${var}*50/100))}

Seb,

I try to get working threads with variables. I have 4 threads groups and 
I want to run many tests with a differents number of simulated users. I 
divide the number of user with a ratio in order to simulate a "real" 
traffic.

In the end, the result of the javascript execution is stored in a 
variable used in one on my threads groups.

It's ok if I replace ${var} with an integer. Obviously, var is defined 
before.


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


Re: JavaScript function

Posted by sebb <se...@gmail.com>.
On 13 May 2011 13:55, DjinnS <dj...@chninkel.net> wrote:
> Le 13/05/2011 13:53, sebb a écrit :
>>
>> On 13 May 2011 12:39, DjinnS<dj...@chninkel.net>  wrote:
>>>
>>> Bonjour,
>>>
>>> I'm going crazy ! I can't used $__JavaScript{} to get a ratio.
>>>
>>> I try to use the following code (in a "User Defined Variable"):
>>>
>>> ${__JavaScript(Math.round(10*50/100))}
>>
>> There is no such function as __JavaScript.
>>
>>> (in fact, "10" is also a value from an another "User Defined Variable")
>>>
>>> This code don't work.
>>>
>>> If I try a very simple math operation, like this:
>>>
>>> ${__JavaScript(1+1)}
>>>
>>> It's ok !
>>
>> No, that fails for the same reason.
>>
>> See:
>>
>> http://jakarta.apache.org/jmeter/usermanual/functions.html#__javaScript
>>
>>> What's going wrong with my first code ?
>>
>> _Both_ are spelt incorrectly.
>
> Yes, there is a mistake in my email.
>
> So, with the correct spelt, my function is:
>
> ${__javaScript(Math.round(${var}*50/100),total)}
>
> It isn't working.

Works for me, provided that I define the "var" variable.

What makes you think it is not working?
What are you expecting, what are you getting?

> If I follow the documentation, I think I use correctly jemeter's variables
> in function.
>
> No ?
>
>>> Thx in advance,
>>>
>>> Rergards,
>>>
>>>
>>> --
>>> DjinnS
>>>
>>> ---------------------------------------------------------------------
>>> 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
>
>

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


Re: JavaScript function

Posted by DjinnS <dj...@chninkel.net>.
Le 13/05/2011 13:53, sebb a écrit :
> On 13 May 2011 12:39, DjinnS<dj...@chninkel.net>  wrote:
>> Bonjour,
>>
>> I'm going crazy ! I can't used $__JavaScript{} to get a ratio.
>>
>> I try to use the following code (in a "User Defined Variable"):
>>
>> ${__JavaScript(Math.round(10*50/100))}
> There is no such function as __JavaScript.
>
>> (in fact, "10" is also a value from an another "User Defined Variable")
>>
>> This code don't work.
>>
>> If I try a very simple math operation, like this:
>>
>> ${__JavaScript(1+1)}
>>
>> It's ok !
> No, that fails for the same reason.
>
> See:
>
> http://jakarta.apache.org/jmeter/usermanual/functions.html#__javaScript
>
>> What's going wrong with my first code ?
> _Both_ are spelt incorrectly.

Yes, there is a mistake in my email.

So, with the correct spelt, my function is:

${__javaScript(Math.round(${var}*50/100),total)}

It isn't working.

If I follow the documentation, I think I use correctly jemeter's 
variables in function.

No ?

>> Thx in advance,
>>
>> Rergards,
>>
>>
>> --
>> DjinnS
>>
>> ---------------------------------------------------------------------
>> 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: JavaScript function

Posted by sebb <se...@gmail.com>.
On 13 May 2011 12:39, DjinnS <dj...@chninkel.net> wrote:
> Bonjour,
>
> I'm going crazy ! I can't used $__JavaScript{} to get a ratio.
>
> I try to use the following code (in a "User Defined Variable"):
>
> ${__JavaScript(Math.round(10*50/100))}

There is no such function as __JavaScript.

> (in fact, "10" is also a value from an another "User Defined Variable")
>
> This code don't work.
>
> If I try a very simple math operation, like this:
>
> ${__JavaScript(1+1)}
>
> It's ok !

No, that fails for the same reason.

See:

http://jakarta.apache.org/jmeter/usermanual/functions.html#__javaScript

> What's going wrong with my first code ?

_Both_ are spelt incorrectly.

> Thx in advance,
>
> Rergards,
>
>
> --
> DjinnS
>
> ---------------------------------------------------------------------
> 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