Return-Path: Delivered-To: apmail-jakarta-jmeter-user-archive@www.apache.org Received: (qmail 35954 invoked from network); 4 Nov 2004 12:30:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 4 Nov 2004 12:30:26 -0000 Received: (qmail 3158 invoked by uid 500); 4 Nov 2004 12:30:22 -0000 Delivered-To: apmail-jakarta-jmeter-user-archive@jakarta.apache.org Received: (qmail 3121 invoked by uid 500); 4 Nov 2004 12:30:22 -0000 Mailing-List: contact jmeter-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "JMeter Users List" Reply-To: "JMeter Users List" Delivered-To: mailing list jmeter-user@jakarta.apache.org Received: (qmail 3108 invoked by uid 99); 4 Nov 2004 12:30:21 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of sebbaz@gmail.com designates 216.239.56.251 as permitted sender) Received: from [216.239.56.251] (HELO mproxy.gmail.com) (216.239.56.251) by apache.org (qpsmtpd/0.28) with ESMTP; Thu, 04 Nov 2004 04:30:21 -0800 Received: by mproxy.gmail.com with SMTP id q44so102982cwc for ; Thu, 04 Nov 2004 04:30:14 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=kFxVvsPneDLzfYweN+6a8Z40lkHoL93lCRHyiLWBa5cR+hu7EB2Po3Em25+gN0anhqnXULZ7xXUTzb69CNTk8ZFyEw+M/tHtye50ZXsjdl/22D9bKxbLYY9CLloMTPgL49nM+6m7YL7yppycfooITLt/fQdzGwGsclVT1YmkXjw= Received: by 10.11.116.24 with SMTP id o24mr180727cwc; Thu, 04 Nov 2004 04:30:14 -0800 (PST) Received: by 10.11.118.42 with HTTP; Thu, 4 Nov 2004 04:30:14 -0800 (PST) Message-ID: <25aac9fc04110404301419a3e9@mail.gmail.com> Date: Thu, 4 Nov 2004 12:30:14 +0000 From: sebb Reply-To: sebb To: "Xie, Shawn Y." Subject: Re: Creating MM/DD/YYYY date string Cc: JMeter Users List In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N On Wed, 3 Nov 2004 18:29:53 -0800, Xie, Shawn Y. wrote: > Dear friends, > > The MM/DD/YYYY has completely solved with the help of Sebb, Neil, and > Kyle. I'd like to share my experience with others: > > 1. using javaScript function: > ${__javaScript(var d=new Date(); var date=d.getDate(); var > month=d.getMonth()+1; $DATE=(month<10?"0"+month:month) + "/" + > (date<10?"0"+date:date) + "/" + d.getFullYear();,DATE)} > > Thus __javaScript() allows multiple lines of code as long as they are > separated by ";" This is a feature of JavaScript itself, not JMeter. > > 2. or using BeanShell > ${__BeanShell(new java.text.SimpleDateFormat("MM/dd/yyyy").format(new > Date()))} > > I downloaded bsh-2.0b2.jar from http://www.beanshell.org/download.html, > put it in JMeter/lib, then restarted JMeter, and it works. > > 3. The trailing white space that bugged me turns out came from the end > of line of javaScript function. i.e., the following code will return a > value with trailing white spaces ("|" is used to indicate the bound of > the line. > |${__javaScript(blabla)} | > > On the other hand, this will not (and is desired): > |${__javaScript(blabla)}| > > So be careful, JMeter is not syntax free. (Might need to be improved in > the future releases). This is deliberate. If you include spaces in a variable definition, they will be preserved, trailing or not, unless they are removed by a function call. JMeter takes the contents of the field, and replaces any function calls with the result of calling the function. The spaces after the function call are not passed to the function. One can use multiple functions, nested if necessary, as well as plain text characters in JMeter variable definitions. > > Thanks for all of your help. > > > > -Shawn Xie > > -----Original Message----- > From: Kyle McAbee [mailto:k.mcabee@treev.com] > Sent: Wednesday, November 03, 2004 9:11 AM > To: JMeter Users List; sebb > Subject: RE: Creating MM/DD/YYYY date string > > Dear Shawn, Sebb, Neil, and JMeter Users: > > Neil's suggested __javaScript function creates a date string in the > format MM/DD/YYYY with JMeter 2.0.1. It does not require installing the > BeanShell jar. > > ${__javaScript(var d = new Date(); var date = d.getDate(); $DATE = > (d.getMonth() + 1) + "/" + (date < 10 ? "0"+date : date) + "/" + > d.getFullYear();,DATE)} > > A possible work-around for Shawn if he must use the function that > creates the date with three trailing spaces: > > 1. Use one parameter with the __javaScript function that creates the > date with the trailing three spaces. > > 2. Use a second parameter with a __regexFunction to get just the date, > excluding the trailing three spaces. > > Sincerely yours, > > Kyle > > -----Original Message----- > From: sebb [mailto:sebbaz@gmail.com] > Sent: Wednesday, November 03, 2004 8:53 AM > To: JMeter Users List > Subject: Re: createing MM/DD/YYYY date string > > On Tue, 2 Nov 2004 21:54:41 -0800, Xie, Shawn Y. wrote: > > Sebb, > > Your suggestion is a good idea. Unfortunately, when I tried it, I > found it returns nothing (an empty string). Maybe I did something wrong > in my test. Are there any detail documents that includes examples about > this function some where? The doc of this function (and actually all > other functions) in the usermanual is just too brief. > > Did you install the BeanShell jar? It's not included with JMeter - I > should have mentioned that. > > Did you check jmeter.log in case there were any error messages? > > The next release of JMeter has better documentation ... > > > Thanks for your help. > > > > -Shawn Xie > > > > ________________________________ > > > > From: sebb [mailto:sebbaz@gmail.com] > > Sent: Tue 11/2/2004 4:33 PM > > To: Xie, Shawn Y. > > Cc: JMeter Users List > > > > > > Subject: Re: createing MM/DD/YYYY date string > > > > On Tue, 2 Nov 2004 16:06:19 -0800, Xie, Shawn Y. > wrote: > > > Sebb, > > > Thanks for your reply. I knew I can pass the date string to > > > JMeter but what I want to achieve is to dynamically generate it. I > am > > > > Re-reading my reply, I see I was not very clear: I was suggesting that > > you might be able to use the OS to dynamically generate the date > > string. > > > > ... another possibility would be to use the __BeanShell() function to > > generate the date. > > > > For example > > > > ${__BeanShell(new java.text.SimpleDateFormat("MM/dd/yyyy").format(new > Date()))} > > > > This is best done in a User Parameters Pre-Processor element. > > > > > already very close to get what I want, but just those tail white > spaces > > > give me trouble. I think this might be a bug of the javaScript > function > > > at JMeter. If the function does not add undesired white spaces or if > it > > > can make a trim before return, it would be ok. > > > > > > Regards, > > > > > > -Shawn Xie > > > > > > > > > > > > > > > -----Original Message----- > > > From: sebb [mailto:sebbaz@gmail.com] > > > Sent: Tuesday, November 02, 2004 3:41 PM > > > To: JMeter Users List > > > Subject: Re: createing MM/DD/YYYY date string > > > > > > On Mon, 1 Nov 2004 23:46:58 -0800, Xie, Shawn Y. > 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 > > > > > > > > > > --------------------------------------------------------------------- > > > > > > 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 > > --------------------------------------------------------------------- To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: jmeter-user-help@jakarta.apache.org