way to get current date into a variable?

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

way to get current date into a variable?

Seth Ladd
Hello,

I searched the FAQs and manual, but couldn't find this answer.

Is there a way to get the current date into reference name?  I need to
set some input fields to "today".

Thanks very much!
Seth

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

Reply | Threaded
Open this post in threaded view
|

Re: way to get current date into a variable?

sebb-2-2
On 5/19/05, Seth Ladd <[hidden email]> wrote:
> Hello,
>
> I searched the FAQs and manual, but couldn't find this answer.
>
> Is there a way to get the current date into reference name?  I need to
> set some input fields to "today".
>

Yes, several methods. All rely on functions.

1) Get the date from the OS, and set a property on the command line
with the value, then use one of the property functions to retrieve it.
E.g.
jmeter -Dtoday="`date`"
Then refer to it as ${today}

2) Use the JavaScript function to create a suitable date string, e.g.
${__javaScript(new Date(),Dummy)}

3) Use the BeanShell function to create a suitable date string e.g.
${__BeanShell(new java.util.Date())}

You'll need to adjust the format.

S.

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

Reply | Threaded
Open this post in threaded view
|

AW: way to get current date into a variable?

Stephan Wiesner
In reply to this post by Seth Ladd
I tried that by adding it to the jmeter.bat file (last line):
%JM_START% %JM_LAUNCH% %JVM_ARGS% %ARGS% -jar ApacheJMeter.jar -Dtoday="`date`" %JMETER_CMD_LINE_ARGS%

The variable is just printed as ${today} when using it as a form parameter and running a test, though. User defined variables in JMeter work, though.
Can anybody tell me what I did wrong?

Stephan

-----Urspr√ľngliche Nachricht-----
Von: sebb [mailto:[hidden email]]
Gesendet: Freitag, 20. Mai 2005 01:05
An: JMeter Users List
Betreff: Re: way to get current date into a variable?


On 5/19/05, Seth Ladd <[hidden email]> wrote:
> Hello,
>
> I searched the FAQs and manual, but couldn't find this answer.
>
> Is there a way to get the current date into reference name?  I need to
> set some input fields to "today".
>

Yes, several methods. All rely on functions.

1) Get the date from the OS, and set a property on the command line
with the value, then use one of the property functions to retrieve it.
E.g.
jmeter -Dtoday="`date`"
Then refer to it as ${today}

2) Use the JavaScript function to create a suitable date string, e.g.
${__javaScript(new Date(),Dummy)}

3) Use the BeanShell function to create a suitable date string e.g.
${__BeanShell(new java.util.Date())}

You'll need to adjust the format.

S.

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


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

Reply | Threaded
Open this post in threaded view
|

Re: way to get current date into a variable?

sebb-2-2
In 5/20/05, Stephan Wiesner <[hidden email]> wrote:
> I tried that by adding it to the jmeter.bat file (last line):
> %JM_START% %JM_LAUNCH% %JVM_ARGS% %ARGS% -jar ApacheJMeter.jar -Dtoday="`date`" %JMETER_CMD_LINE_ARGS%
>
> The variable is just printed as ${today} when using it as a form parameter and running a test, though. User defined variables in JMeter work, though.
> Can anybody tell me what I did wrong?
>

Yes - nothing ...

Sorry, my mistake - you need to use one of the property functions to
refer to it.

For example:

${__P(today)}

BTW, no need to edit jmeter.bat - you can pass parameters to it.

Seems you are using DOS - you cannot use `date` to get the date.

Short of writing a program, I think it's very tricky to automatically
get the date in DOS.

But for test purposes, you can of course do it manually:

jmeter -Dtoday=20050520 -n -t testplan.jmx

This will run the test plan in non-GUI mode with output to testplan.jtl

S.

> Stephan
>
> -----Urspr√ľngliche Nachricht-----
> Von: sebb [mailto:[hidden email]]
> Gesendet: Freitag, 20. Mai 2005 01:05
> An: JMeter Users List
> Betreff: Re: way to get current date into a variable?
>
>
> On 5/19/05, Seth Ladd <[hidden email]> wrote:
> > Hello,
> >
> > I searched the FAQs and manual, but couldn't find this answer.
> >
> > Is there a way to get the current date into reference name?  I need to
> > set some input fields to "today".
> >
>
> Yes, several methods. All rely on functions.
>
> 1) Get the date from the OS, and set a property on the command line
> with the value, then use one of the property functions to retrieve it.
> E.g.
> jmeter -Dtoday="`date`"
> Then refer to it as ${today}
>
> 2) Use the JavaScript function to create a suitable date string, e.g.
> ${__javaScript(new Date(),Dummy)}
>
> 3) Use the BeanShell function to create a suitable date string e.g.
> ${__BeanShell(new java.util.Date())}
>
> You'll need to adjust the format.
>
> S.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

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

Reply | Threaded
Open this post in threaded view
|

Re: way to get current date into a variable?

Seth Ladd
In reply to this post by sebb-2-2
Hello,

Thanks very much for the quick and helpful reply.

I tried this technique in a User Defined Variable:

Name Value
today ${__javaScript(new Date(),Dummy)}
bizName ${today} ${counter}

(note that counter is a counter setup in the thread group)

When I try to reference the ${bizName} variable, it resolves to the
literal string '${today} ${counter}'

Are variables not dereferenced in the value of a User Defined Variable?

I am using JMeter 2.0.3

Thanks very much for your help!
Seth


> Yes, several methods. All rely on functions.
>
> 1) Get the date from the OS, and set a property on the command line
> with the value, then use one of the property functions to retrieve it.
> E.g.
> jmeter -Dtoday="`date`"
> Then refer to it as ${today}
>
> 2) Use the JavaScript function to create a suitable date string, e.g.
> ${__javaScript(new Date(),Dummy)}
>
> 3) Use the BeanShell function to create a suitable date string e.g.
> ${__BeanShell(new java.util.Date())}
>
> You'll need to adjust the format.
>
> S.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


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

Reply | Threaded
Open this post in threaded view
|

Re: way to get current date into a variable?

Seth Ladd
Seth Ladd wrote:

> Hello,
>
> Thanks very much for the quick and helpful reply.
>
> I tried this technique in a User Defined Variable:
>
> Name        Value
> today        ${__javaScript(new Date(),Dummy)}
> bizName        ${today} ${counter}
>
> (note that counter is a counter setup in the thread group)
>
> When I try to reference the ${bizName} variable, it resolves to the
> literal string '${today} ${counter}'
>
> Are variables not dereferenced in the value of a User Defined Variable?

Sorry about that... I just saw in the reference documentation that User
Defined Variables have to be static.

What is the recommended way to construct a variable from the value of
two different variables?

Thanks again!
Seth

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

Reply | Threaded
Open this post in threaded view
|

Re: way to get current date into a variable?

sebb-2-2
On 5/20/05, Seth Ladd <[hidden email]> wrote:

> Seth Ladd wrote:
> > Hello,
> >
> > Thanks very much for the quick and helpful reply.
> >
> > I tried this technique in a User Defined Variable:
> >
> > Name        Value
> > today        ${__javaScript(new Date(),Dummy)}
> > bizName        ${today} ${counter}
> >
> > (note that counter is a counter setup in the thread group)
> >
> > When I try to reference the ${bizName} variable, it resolves to the
> > literal string '${today} ${counter}'
> >
> > Are variables not dereferenced in the value of a User Defined Variable?
>
> Sorry about that... I just saw in the reference documentation that User
> Defined Variables have to be static.
>
> What is the recommended way to construct a variable from the value of
> two different variables?
>

No need, one can use them all in a field, e.g. the HTTP Path field
could contain:

/${dir1}/${dir2}/${file}?${p1}&${p2}

Of course, this does get a bit messy, so you can use the User
Parameters Pre-Processor instead of UDV. This does support
variables/functions.

BTW, no need to provide entries for more than 1 user - JMeter will
keep using User_1 if necessary.

S.

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

Reply | Threaded
Open this post in threaded view
|

Re: way to get current date into a variable?

Seth Ladd
Thanks sebb,

> BTW, no need to provide entries for more than 1 user - JMeter will
> keep using User_1 if necessary.

This doesn't seem to be the case if you have specified values for more
than one user in a single User Parameters.

For instance, I have 10 users.  I have specified a username and a
password parameter names, and each user has their own values.

I then have a 'today' parameter name, and I really only need to specify
it once.  I defined the value for user 1 only.  It appears that for
users 2 - 10, when I try to dereference it, the value of 'today' is blank.

I'm wondering if JMeter won't reuse values from parameters if multiple
users are defined in the user parameters.  I'll try to setup a special
user parameters with only the 'today' parameter.

Thanks!
Seth

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

Reply | Threaded
Open this post in threaded view
|

Re: way to get current date into a variable?

Seth Ladd

> I then have a 'today' parameter name, and I really only need to specify
> it once.  I defined the value for user 1 only.  It appears that for
> users 2 - 10, when I try to dereference it, the value of 'today' is blank.
>
> I'm wondering if JMeter won't reuse values from parameters if multiple
> users are defined in the user parameters.  I'll try to setup a special
> user parameters with only the 'today' parameter.

Update:  If you have have some user parameters that are set for each
user, and some user parameters that are shared among all users, you need
to create two sets of User Parameters.

This way, JMeter will reuse the shared parameters for all users.

Thanks,
Seth

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

Reply | Threaded
Open this post in threaded view
|

Re: way to get current date into a variable?

Michael Stover
In reply to this post by sebb-2-2
User-Defined Variables
User Parameters

One is static, one is a pre-processor - does anyone but me have a hard
time keeping these straight?  Maybe we could come up with some better
names for them.  There's also an old HTTP User Parameters or something
like that.  Ugh.

-Mike


On Fri, 2005-05-20 at 22:30 +0100, sebb wrote:

> On 5/20/05, Seth Ladd <[hidden email]> wrote:
> > Seth Ladd wrote:
> > > Hello,
> > >
> > > Thanks very much for the quick and helpful reply.
> > >
> > > I tried this technique in a User Defined Variable:
> > >
> > > Name        Value
> > > today        ${__javaScript(new Date(),Dummy)}
> > > bizName        ${today} ${counter}
> > >
> > > (note that counter is a counter setup in the thread group)
> > >
> > > When I try to reference the ${bizName} variable, it resolves to the
> > > literal string '${today} ${counter}'
> > >
> > > Are variables not dereferenced in the value of a User Defined Variable?
> >
> > Sorry about that... I just saw in the reference documentation that User
> > Defined Variables have to be static.
> >
> > What is the recommended way to construct a variable from the value of
> > two different variables?
> >
>
> No need, one can use them all in a field, e.g. the HTTP Path field
> could contain:
>
> /${dir1}/${dir2}/${file}?${p1}&${p2}
>
> Of course, this does get a bit messy, so you can use the User
> Parameters Pre-Processor instead of UDV. This does support
> variables/functions.
>
> BTW, no need to provide entries for more than 1 user - JMeter will
> keep using User_1 if necessary.
>
> S.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]



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