You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by "Xie, Shawn Y." <sx...@Covad.COM> on 2004/11/02 08:46:58 UTC
createing MM/DD/YYYY date string
Hi,
In my functional test plan, I need to assert a page contains today's date string as MM/DD/YYYY (e.g. 01/02/2004 for Jan 2, 2004) or not. I tried to use JMeter javascript function to dynamically generate the date string. It seems JMeter javascript cannot run multiple lines of code (Please confirm this), I finally end up at an ugly, but close to work solution by defining a variable name as 'today' and value part as:
${__javaScript((((new Date().getMonth()+1)<10)?('0'+new Date().getMonth()+1):(new Date().getMonth()+1))+"/"+(new Date().getDate()<10?('0'+new Date().getDate()):new Date().getDate())+"/"+(new Date().getYear()+1900),)}
I said "close to work" as above code does return MM/DD/YYYY as expected but it somehow always appends with 3 white spaces at the end of it. These white spaces prevents me from using ${today} in the assertion as in the page the date has no space following it.
What I need your help are:
1. Is there a elegant way to generate MM/DD/YYYY in JMeter?
2. How to trim the white spaces at an javascript return (again in JMeter)?
Thanks a lot for your help in advance.
-Shawn
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
Re: createing MM/DD/YYYY date string
Posted by sebb <se...@gmail.com>.
On Mon, 1 Nov 2004 23:46:58 -0800, Xie, Shawn Y. <sx...@covad.com> wrote:
> Hi,
> In my functional test plan, I need to assert a page contains today's date string as MM/DD/YYYY (e.g. 01/02/2004 for Jan 2, 2004) or not. I tried to use JMeter javascript function to dynamically generate the date string. It seems JMeter javascript cannot run multiple lines of code (Please confirm this), I finally end up at an ugly, but close to work solution by defining a variable name as 'today' and value part as:
>
> ${__javaScript((((new Date().getMonth()+1)<10)?('0'+new Date().getMonth()+1):(new Date().getMonth()+1))+"/"+(new Date().getDate()<10?('0'+new Date().getDate()):new Date().getDate())+"/"+(new Date().getYear()+1900),)}
>
> I said "close to work" as above code does return MM/DD/YYYY as expected but it somehow always appends with 3 white spaces at the end of it. These white spaces prevents me from using ${today} in the assertion as in the page the date has no space following it.
>
> What I need your help are:
> 1. Is there a elegant way to generate MM/DD/YYYY in JMeter?
> 2. How to trim the white spaces at an javascript return (again in JMeter)?
I don't know JavaScript, so can't help you with that solution.
However you could pass in the date string as a property on the
command-line when starting JMeter. This might be easy to do on your OS
- or it might not ...
e.g. start JMeter using:
jmeter -Jtoday=mmddyyyy
then refer to ${today} in the assertion.
>
> Thanks a lot for your help in advance.
>
> -Shawn
>
> ---------------------------------------------------------------------
> 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