jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: Regular Expressions
Date Fri, 17 Apr 2009 10:31:42 GMT
On 17/04/2009, Noel O'Brien <nobrien@newbay.com> wrote:
> Hi Jannetta,
>
>  Happy to help :)
>
>  I'm not sure whether it's a beanshell thing or a JMeter thing, but
>  System.out.println doesn't seem to print to standard out for me. I use the

Works for me - and print() just calls it anyway.

Both appear in the console window.

>  print() function instead for stdout, or log.info() for writing to jmeter.log
>
>  Regards,
>
> Noel
>
>
>  On Friday 17 April 2009 10:36:55 Jannetta Steyn wrote:
>  > Hi Noel
>  >
>  > The beanshell worked. Thank you very much for the suggestion. It was much
>  > simpler than your example though. This is all I had to do:
>  >
>  > String desc = vars.get("DESCRIPTION");
>  >
>  > desc = desc.replaceAll("<br/>","\r\n\r\n");
>  > vars.put("DESCRIPTION",desc);
>  >

Or you could use a script function to return the changed string, for
example in BeanShell:

${__BeanShell("${DESCRIPTION}".replaceAll("<br/>"\,"\r\n\r\n"))}

N.B. the comma in the replaceAll() parameter list needs to be escaped
with backslash so it is treated as part of the script.

and if you want to change the variable as well:

${__BeanShell("${DESCRIPTION}".replaceAll("<br/>"\,"\r\n\r\n"),DESCRIPTION)}

Similar code should work for Javascript and Jexl.

Have a look at BeanShellFunction.bshrc, as that contains an example
function definition for replacing "&amp;" with "&". It is called as
follows:

${__BeanShell(fixamps(vars.get("DESCRIPTION")))}

You could create your own function:

String fixBRinVar(varname) {
  return vars.get(varname).replaceAll("<br/>","\r\n\r\n");
}

and call as

${__BeanShell(fixBRinVar("DESCRIPTION"))}

>  > I was just wondering. Where does the output of a System.out.println go?
>  >
>  > Kind Regards
>  > Jannetta
>  >
>  > 2009/4/16 Noel O'Brien <nobrien@newbay.com>
>  >
>  > >  I have a beanshell pre processor script that I use to replace values in
>  > > parameters of a HTTP Request, maybe you can modify it to do a find and
>  > > replace on the <br> placeholders:
>  > >
>  > > import org.apache.jmeter.protocol.http.util.HTTPArgument;
>  > >
>  > >  ....
>  > >
>  > > ....
>  > >
>  > >  // Get HTTP Params
>  > >
>  > > params = sampler.getArguments();
>  > >
>  > >  passArg = params.getArgument(0);
>  > >
>  > > userArg = params.getArgument(1);
>  > >
>  > >  if (!passArg.getName().equals("password")) {
>  > >
>  > > log.error("Password not first HTTP Param: " + userArg.getName());
>  > >
>  > > return;
>  > >
>  > > }
>  > >
>  > > if (!userArg.getName().trim().equals("username")) {
>  > >
>  > > log.error("Username not second HTTP Param: " + passArg.getName());
>  > >
>  > > return;
>  > >
>  > > }
>  > >
>  > >  pass = passArg.getValue();
>  > >
>  > > user = userArg.getValue();
>  > >
>  > >  if (user == null || pass == null)
>  > >
>  > > return;
>  > >
>  > >  ...
>  > >
>  > > ...
>  > >
>  > > ...
>  > >
>  > > userArg.setValue(user);
>  > >
>  > > passArg.setValue(pass);
>  > >
>  > >  Regards,
>  > >
>  > > Noel
>  > >
>  > > On Wednesday 15 April 2009 18:50:35 Jannetta Steyn wrote:
>  > > > Yes the data of one of the fields I want to submit is a textarea which
>  > > >
>  > > > sometimes contains line breaks.
>  > > >
>  > > >
>  > > >
>  > > > I have two ways of retrieving the data. The first is as I mentioned
>  > >
>  > > before
>  > >
>  > > > from the CSV file, so it is in a variable. Because the CSV data config
>  > > >
>  > > > can't read line breaks, I replaced the line breaks with <br/>.I
can
>  > >
>  > > replace
>  > >
>  > > > it with anything really as long as when I submit it to the text field
I
>  > >
>  > > can
>  > >
>  > > > replace it with line breaks again.
>  > > >
>  > > >
>  > > >
>  > > > Alternatively I can retrieve the data from a database, but then I don't
>  > > >
>  > > > know how to get it into a variable to submit in the form.
>  > > >
>  > > >
>  > > >
>  > > > I tried to use a Regular Expression Extractor to retrieve the data from
>  > >
>  > > the
>  > >
>  > > > Response Data. The data is then broken up into separate variables by
>  > > > each
>  > > >
>  > > > line break. For instance, if the reference name I specify is
>  > > > DESCRIPTION,
>  > > >
>  > > > the Regular expression is (.+), template is $1$, match no is -1, then
>  > > >
>  > > > DESCRIPTION_matchNr will contain the number of lines read and the lines
>  > > >
>  > > > will be in DESCRIPTION_1 to DESCRIPTION_n. What I then can't figure out
>  > >
>  > > is
>  > >
>  > > > how to submit the whole lot to the form again - in an automated manner
>  > > > of
>  > > >
>  > > > course.
>  > > >
>  > > >
>  > > >
>  > > > Regards
>  > > >
>  > > > Jannetta
>  > > >
>  > > >
>  > > >
>  > > >
>  > > >
>  > > >
>  > > >
>  > > >
>  > > >
>  > > > 2009/4/15 Noel O'Brien <nobrien@newbay.com>
>  > > >
>  > > >
>  > > >
>  > > > Do you need to have line breaks in your data?
>  > > >
>  > > > > Is the data in question sent as a parameter or in the request body?
>  > > > >
>  > > > >
>  > > > >
>  > > > > Regards,
>  > > > >
>  > > > >
>  > > > >
>  > > > > Noel
>  > > > >
>  > > > > On Wednesday 15 April 2009 17:05:47 Jannetta Steyn wrote:
>  > > > > > Hi Folks
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > > I posted this message earlier today but it didn't seem to go
>  > > > > > through.
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > > Apologies if it now ends up having gone through twice.
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > > I wonder if someone can perhaps help. I am using JMeter to
test a
>  > > > > > web
>  > > > >
>  > > > > site
>  > > > >
>  > > > > > which consist of forms submitted by POST. I read data from
a CSV
>  > > > > > file
>  > > > > >
>  > > > > > and
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > > then submit the information using HTTP Request. The problem
I have
>  > > > > > is
>  > > > >
>  > > > > with
>  > > > >
>  > > > > > the CSV Data Set Config not being able to read data with line
>  > > > > > breaks
>  > >
>  > > in
>  > >
>  > > > > the
>  > > > >
>  > > > > > fields. So what I have done is to replace the line breaks with
an
>  > > > > > odd
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > > character (or with <br/>). However before I submit I
would like to
>  > > > >
>  > > > > replace
>  > > > >
>  > > > > > the odd character (or the <br/>) with a line break.
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > > I have tried a few things but just can't get it to work. Does
>  > > > > > anybody
>  > > > >
>  > > > > have
>  > > > >
>  > > > > > any advice regarding this?
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > > Thanks in advance.
>  > > > > >
>  > > > > >
>  > > > > >
>  > > > > > Jannetta
>
>

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


Mime
View raw message