You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by "Phillpotts, James" <ja...@logicacmg.com> on 2008/02/21 17:37:18 UTC

Can __javaScript call recalculate?

Hi all,

I'm having trouble with a Jmeter test plan where I'm trying to use
String.indexOf(String) in a __javaScript call. However, once the
expression has been evaluated once, it always returns the same value,
regardless of one or both of the strings being different each time it
should be called.

It seems this is the same for all __javaScript calls - in the attached
.jmx, every call for a random number returns the same value.

Is there any way to force __javaScript functions to always be
re-evaluated each time?

Cheers,
James


This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.



Re: Can __javaScript call recalculate?

Posted by "Phillpotts, James" <ja...@logicacmg.com>.
sebb [mailto:sebbaz@gmail.com] wrote:
> On 21/02/2008, Phillpotts, James <ja...@logicacmg.com>
wrote:
> > sebb [mailto:sebbaz@gmail.com] wrote:
> >  > On 21/02/2008, Phillpotts, James <ja...@logicacmg.com>
> >  wrote:
> >  > >  Is there any way to force __javaScript functions to always be
>
> > > re-evaluated each time?
> >  >
> >  > They  should work - depends where you are calling the function
from.
> >
> >
> > The function is in the value field of a User Defined Variables 
> > component. Perhaps I'm using the wrong component - I basically want
to 
> > set a bunch of parameters to new values between a couple of HTTP 
> > samplers.
> >
> 
> Yes, the UDV is a config item and is only processed once.
> 
> Try using a User Parameters Pre-Processor instead or just put the
function 
> call in the sampler.

Thanks - that worked a treat!

Cheers,
James

This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.



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


Re: Can __javaScript call recalculate?

Posted by sebb <se...@gmail.com>.
On 21/02/2008, Phillpotts, James <ja...@logicacmg.com> wrote:
> sebb [mailto:sebbaz@gmail.com] wrote:
>  > On 21/02/2008, Phillpotts, James <ja...@logicacmg.com>
>  wrote:
>  > > Hi all,
>  > >
>  > >  I'm having trouble with a Jmeter test plan where I'm trying to use
>  > >  String.indexOf(String) in a __javaScript call. However, once the
>  > > expression has been evaluated once, it always returns the same
>  value,
>  > > regardless of one or both of the strings being different each time
>  it
>  > > should be called.
>  > >
>  > >  It seems this is the same for all __javaScript calls - in the
>  > > attached  .jmx, every call for a random number returns the same
>  value.
>  > >
>  >
>  > Please don't send attachments to the list...
>
>
> Sorry - my bad - I checked here
>  (http://jakarta.apache.org/site/mail.html) and it didn't say anything
>  about not sending attachments... As it's a small file, I've pasted JMX
>  content below - hope nobody minds.
>

Not ideal either as they tend to get mangled ... this one was not too bad.

>
>  > >  Is there any way to force __javaScript functions to always be
>  > > re-evaluated each time?
>  >
>  > They  should work - depends where you are calling the function from.
>
>
> The function is in the value field of a User Defined Variables
>  component. Perhaps I'm using the wrong component - I basically want to
>  set a bunch of parameters to new values between a couple of HTTP
>  samplers.
>

Yes, the UDV is a config item and is only processed once.

Try using a User Parameters Pre-Processor instead or just put the
function call in the sampler.

>
>  > Also, which version of JMeter are you using? Java?
>
>
> JMeter 2.3, JDK 5 (1.5.0_11-b03)
>
>  Cheers,
>  James
>
>
>  [---JMX content follows---]
>  <?xml version="1.0" encoding="UTF-8"?>
>  <jmeterTestPlan version="1.2" properties="1.8">
>   <hashTree>
>     <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test
>  Plan" enabled="true">
>       <stringProp name="TestPlan.comments"></stringProp>
>       <boolProp name="TestPlan.functional_mode">false</boolProp>
>       <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
>       <elementProp name="TestPlan.user_defined_variables"
>  elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments"
>  testname="User Defined Variables" enabled="true">
>         <collectionProp name="Arguments.arguments"/>
>       </elementProp>
>       <stringProp name="TestPlan.user_define_classpath"></stringProp>
>     </TestPlan>
>     <hashTree>
>       <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup"
>  testname="Thread Group" enabled="true">
>         <elementProp name="ThreadGroup.main_controller"
>  elementType="LoopController" guiclass="LoopControlPanel"
>  testclass="LoopController" testname="Loop Controller" enabled="true">
>           <boolProp
>  name="LoopController.continue_forever">false</boolProp>
>           <intProp name="LoopController.loops">-1</intProp>
>         </elementProp>
>         <stringProp name="ThreadGroup.num_threads">1</stringProp>
>         <stringProp name="ThreadGroup.ramp_time">1</stringProp>
>         <longProp name="ThreadGroup.start_time">1203610294000</longProp>
>         <longProp name="ThreadGroup.end_time">1203610294000</longProp>
>         <boolProp name="ThreadGroup.scheduler">false</boolProp>
>         <stringProp
>  name="ThreadGroup.on_sample_error">continue</stringProp>
>         <stringProp name="ThreadGroup.duration"></stringProp>
>         <stringProp name="ThreadGroup.delay"></stringProp>
>       </ThreadGroup>
>       <hashTree>
>         <Arguments guiclass="ArgumentsPanel" testclass="Arguments"
>  testname="User Defined Variables" enabled="true">
>           <collectionProp name="Arguments.arguments">
>             <elementProp name="random" elementType="Argument">
>               <stringProp name="Argument.name">random</stringProp>
>               <stringProp
>  name="Argument.value">${__javaScript(Math.floor(Math.random()*500))}</st
>  ringProp>
>               <stringProp name="Argument.metadata">=</stringProp>
>             </elementProp>
>             <elementProp name="dummy" elementType="Argument">
>               <stringProp name="Argument.name">dummy</stringProp>
>               <stringProp
>  name="Argument.value">${__logn(${random},OUT)}</stringProp>
>               <stringProp name="Argument.metadata">=</stringProp>
>             </elementProp>
>           </collectionProp>
>         </Arguments>
>         <hashTree/>
>         <HTTPSampler guiclass="HttpTestSampleGui"
>  testclass="HTTPSampler" testname="HTTP Request" enabled="true">
>           <elementProp name="HTTPsampler.Arguments"
>  elementType="Arguments" guiclass="HTTPArgumentsPanel"
>  testclass="Arguments" testname="User Defined Variables" enabled="true">
>             <collectionProp name="Arguments.arguments"/>
>           </elementProp>
>           <stringProp
>  name="HTTPSampler.domain">www.google.co.uk</stringProp>
>           <stringProp name="HTTPSampler.port"></stringProp>
>           <stringProp name="HTTPSampler.protocol"></stringProp>
>           <stringProp name="HTTPSampler.method">GET</stringProp>
>           <stringProp name="HTTPSampler.contentEncoding"></stringProp>
>           <stringProp name="HTTPSampler.path">/</stringProp>
>           <boolProp name="HTTPSampler.follow_redirects">false</boolProp>
>           <boolProp name="HTTPSampler.auto_redirects">true</boolProp>
>           <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
>           <boolProp
>  name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
>           <stringProp name="HTTPSampler.mimetype"></stringProp>
>           <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
>           <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
>           <stringProp name="HTTPSampler.monitor">false</stringProp>
>           <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
>         </HTTPSampler>
>         <hashTree/>
>       </hashTree>
>     </hashTree>
>   </hashTree>
>  </jmeterTestPlan>
>
>
>  This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
>
>
>
>  ---------------------------------------------------------------------
>  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: Can __javaScript call recalculate?

Posted by "Phillpotts, James" <ja...@logicacmg.com>.
sebb [mailto:sebbaz@gmail.com] wrote:
> On 21/02/2008, Phillpotts, James <ja...@logicacmg.com>
wrote:
> > Hi all,
> >
> >  I'm having trouble with a Jmeter test plan where I'm trying to use
> >  String.indexOf(String) in a __javaScript call. However, once the 
> > expression has been evaluated once, it always returns the same
value, 
> > regardless of one or both of the strings being different each time
it 
> > should be called.
> >
> >  It seems this is the same for all __javaScript calls - in the 
> > attached  .jmx, every call for a random number returns the same
value.
> >
> 
> Please don't send attachments to the list...

Sorry - my bad - I checked here
(http://jakarta.apache.org/site/mail.html) and it didn't say anything
about not sending attachments... As it's a small file, I've pasted JMX
content below - hope nobody minds.

> >  Is there any way to force __javaScript functions to always be 
> > re-evaluated each time?
> 
> They  should work - depends where you are calling the function from.

The function is in the value field of a User Defined Variables
component. Perhaps I'm using the wrong component - I basically want to
set a bunch of parameters to new values between a couple of HTTP
samplers.

> Also, which version of JMeter are you using? Java?

JMeter 2.3, JDK 5 (1.5.0_11-b03)

Cheers,
James


[---JMX content follows---]
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="1.8">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test
Plan" enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables"
elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments"
testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup"
testname="Thread Group" enabled="true">
        <elementProp name="ThreadGroup.main_controller"
elementType="LoopController" guiclass="LoopControlPanel"
testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp
name="LoopController.continue_forever">false</boolProp>
          <intProp name="LoopController.loops">-1</intProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1203610294000</longProp>
        <longProp name="ThreadGroup.end_time">1203610294000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp
name="ThreadGroup.on_sample_error">continue</stringProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>
      <hashTree>
        <Arguments guiclass="ArgumentsPanel" testclass="Arguments"
testname="User Defined Variables" enabled="true">
          <collectionProp name="Arguments.arguments">
            <elementProp name="random" elementType="Argument">
              <stringProp name="Argument.name">random</stringProp>
              <stringProp
name="Argument.value">${__javaScript(Math.floor(Math.random()*500))}</st
ringProp>
              <stringProp name="Argument.metadata">=</stringProp>
            </elementProp>
            <elementProp name="dummy" elementType="Argument">
              <stringProp name="Argument.name">dummy</stringProp>
              <stringProp
name="Argument.value">${__logn(${random},OUT)}</stringProp>
              <stringProp name="Argument.metadata">=</stringProp>
            </elementProp>
          </collectionProp>
        </Arguments>
        <hashTree/>
        <HTTPSampler guiclass="HttpTestSampleGui"
testclass="HTTPSampler" testname="HTTP Request" enabled="true">
          <elementProp name="HTTPsampler.Arguments"
elementType="Arguments" guiclass="HTTPArgumentsPanel"
testclass="Arguments" testname="User Defined Variables" enabled="true">
            <collectionProp name="Arguments.arguments"/>
          </elementProp>
          <stringProp
name="HTTPSampler.domain">www.google.co.uk</stringProp>
          <stringProp name="HTTPSampler.port"></stringProp>
          <stringProp name="HTTPSampler.protocol"></stringProp>
          <stringProp name="HTTPSampler.method">GET</stringProp>
          <stringProp name="HTTPSampler.contentEncoding"></stringProp>
          <stringProp name="HTTPSampler.path">/</stringProp>
          <boolProp name="HTTPSampler.follow_redirects">false</boolProp>
          <boolProp name="HTTPSampler.auto_redirects">true</boolProp>
          <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
          <boolProp
name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
          <stringProp name="HTTPSampler.mimetype"></stringProp>
          <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
          <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
          <stringProp name="HTTPSampler.monitor">false</stringProp>
          <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
        </HTTPSampler>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.



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


Re: Can __javaScript call recalculate?

Posted by sebb <se...@gmail.com>.
On 21/02/2008, Phillpotts, James <ja...@logicacmg.com> wrote:
> Hi all,
>
>  I'm having trouble with a Jmeter test plan where I'm trying to use
>  String.indexOf(String) in a __javaScript call. However, once the
>  expression has been evaluated once, it always returns the same value,
>  regardless of one or both of the strings being different each time it
>  should be called.
>
>  It seems this is the same for all __javaScript calls - in the attached
>  .jmx, every call for a random number returns the same value.
>

Please don't send attachments to the list...

>  Is there any way to force __javaScript functions to always be
>  re-evaluated each time?

They  should work - depends where you are calling the function from.

Also, which version of JMeter are you using? Java?

>  Cheers,
>  James
>
>
>  This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
>
>
>
> ---------------------------------------------------------------------
>  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