Thanks Deepak, this is so good it's almost magic. There is one problem however -- the headers attached to the sampler seem to accumulate with each new request instead of resetting for each new line of CSV data. Do you know how I could address this?
Thanks, J -----Original Message----- From: Deepak Shetty [mailto:[email protected]] Sent: Monday, December 05, 2011 8:27 PM To: JMeter Users List Subject: Re: CSV with variable number of columns? Hi Assuming you have a CSV Data Set Config with a single line /foo/bar.html|header1name: header1value|header2name: header2value|headerNname: headerNvalue Configure the CSV Data Set Config to have a single variable e.g. var1 and delimiter ="," i.e. everything will be read into variable var1. Then Attach a beanshell pre processor under the HTTP Sampler So your test plan looks like ThreadGroup +CSV Data Set Config (delimiter is still ',' , single variable) +HTTP Sampler ++BeanShell Pre Processor (With the code below) ++HTTP Header Manager (empty) +Debug Sampler (for debug) +HTTP Sampler +View results Tree (for debug) import org.apache.jmeter.protocol.http.control.HeaderManager; import org.apache.jmeter.protocol.http.control.Header; String val = vars.get("var1"); //var1 is what is defined in CSV data set config as the variable name String[] entries = val.split("\\|"); // | is special for regex so escape it HeaderManager hm = sampler.getHeaderManager(); //needs a valid header manager in scope print(hm); for(int i=1;i<entries.length;i++){ //because the first value is a path String entry = entries[i]; print(entry); String[] keyVal = entry.split(":"); print(keyVal.length); Header h = new Header(keyVal[0].trim(),keyVal[1].trim()); print(h); hm.add(h); } //sampler.setPath(entries[0]); //not sure if I should be doing this basically this sets the sampler path to that read from the CSV works on 2.3.4(no error checking!) - hopefully works on later versions If you have a maximum number of entries allowed (i.e. at the most 10 headers , you might be able to avoid having to code it) regards deepak On Mon, Dec 5, 2011 at 4:42 PM, Jason Gilroy <[email protected]>wrote: > Thank you Deepak. I would appreciate any sample code or useful references > you could provide as I haven't touched any of the BeanShell stuff in JMeter > before. > > Jason > > -----Original Message----- > From: Deepak Shetty [mailto:[email protected]] > Sent: Monday, December 05, 2011 7:17 PM > To: JMeter Users List > Subject: Re: CSV with variable number of columns? > > Hi > One way is read all the header values from the CSV into a single variable . > > Then write a BeanShell Pre processor for the sampler which uses > sampler.getHeaderManager().add(header) > So you will read the variable in beanshell, split it on the delimiter and > add it to the sampler in a loop. > > Do you need sample code ?. > > > > regards > deepak > > > You want JMeter to make GET call which has a variable number of headers? > and you have > > On Mon, Dec 5, 2011 at 1:46 PM, Jason Gilroy <[email protected] > >wrote: > > > I have a CSV (ok, PSV - pipe separated file) file that looks something > > like: > > > > /foo/bar.html|header1name: header1value|header2name: > > header2value|...|headerNname: headerNvalue > > > > (this is the GET request coming into our system, followed by the list of > > HTTP Headers that accompanied that request.) I'm trying to replay these > in > > a test environment, but having a tough time envisioning a way to handle > the > > variable number of headers that might come with each request; both > getting > > them into individual variables and then stuffing them into the Header > > Manager. I would really appreciate any ideas for how to approach this. > > > > Thanks, > > J > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
