jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shmuel Krakower <shmul...@gmail.com>
Subject Re: beanshell suggestion - adding a cookie to the manager
Date Tue, 10 Jun 2014 20:56:41 GMT
Look into this example:

http://jmeter.512774.n5.nabble.com/Clear-cookies-per-need-td5719912.html

www.beatsoo.org - free application performance monitoring from world wide
locations.
On Jun 10, 2014 11:43 PM, "Adrian Speteanu" <asp.adieu@gmail.com> wrote:

> Thwarted by the extra digit. It's because the way I was using the sampler
> object, though, that made me experiment with the values setup of the
> cookie... However, I still can't make the samplers at a certain level to
> use the new cookie, it's the existing cookie manager that I was hoping to
> add to.
>
> --Adrian S
>
>
> On Tue, Jun 10, 2014 at 7:50 PM, Deepak Shetty <shettyd@gmail.com> wrote:
>
> > Hi
> > long expiry = -1l;
> > Cookie cookie = new Cookie("cookieAddedByPreprocessor", value, site,
> path,
> > false, expiry);
> >
> > the expiry parameter is a long
> >
> >
> > On Tue, Jun 10, 2014 at 8:43 AM, Adrian Speteanu <asp.adieu@gmail.com>
> > wrote:
> >
> > > Sorry, I've written the code snippet out of the top of my head, I had
> the
> > > imports and the right getCookieCount method name as bellow. the
> complete
> > > version looks like this:
> > >
> > > -Cookie Manager
> > > -HTTP Sampler #1 - simple GET request
> > >  \- BS PreProcessor:
> > >    import org.apache.jmeter.protocol.http.control.CookieManager;
> > >    import org.apache.jmeter.protocol.http.control.Cookie;
> > >    CookieManager manager = sampler.getCookieManager();
> > >    vars.putObject("CookieMananger",manager);
> > >    value = "test-value";
> > >    site = "localhost";
> > >    path = "/";
> > >    Cookie cookie = new Cookie("cookieAddedByPreprocessor", value, site,
> > > path, false, 9999999999);
> > >    int count = manager.getCookieCount();
> > >    vars.put("count", String.valueOf(count));
> > >    manager.add(cookie);
> > > -Debug Sampler
> > > -HTTP Sampler #2
> > > -View Results Tree
> > >
> > > In the debug sampler I can see the site's cookies,
> > >
> >
> CookieManager=rg.apache.jmeter.protocol.http.control.CookieManager@30b49c1d
> > > and no "count" variable. HTTP Sampler #1 didn't make the use of the
> > cookie.
> > >
> > > --Adrian S
> > >
> > >
> > > On Tue, Jun 10, 2014 at 6:15 PM, Deepak Shetty <shettyd@gmail.com>
> > wrote:
> > >
> > > > You have (atleast) two issues (Im assuming you have added a cookie
> > > manager
> > > > in your test)
> > > >
> > > > import org.apache.jmeter.protocol.http.control.CookieManager;
> > > > CookieManager manager = sampler.getCookieManager();
> > > > vars.putObject("CookieMananger",manager);
> > > > int count = manager.getCookieCount(); //method is getCookieCount not
> > > > getCookiesCount
> > > > vars.put("count", String.valueOf(count)); //method accepts string as
> > > > key/value , not integer
> > > >
> > > > ThreadGroup
> > > > +Sampler
> > > > ++BeanshellPreProcessor
> > > > +CookieManager
> > > >
> > > >
> > > >
> > > > On Tue, Jun 10, 2014 at 8:05 AM, Adrian Speteanu <
> asp.adieu@gmail.com>
> > > > wrote:
> > > >
> > > > > Thanks for the input. First of all, I didn't realise that I can't
> use
> > > it
> > > > in
> > > > > a beanshell sampler, but I moved the code to a sampler as opposed
> to
> > a
> > > > > preprocessor because it wasn't working. And I can't even do
> something
> > > > like:
> > > > >
> > > > > CookieManager manager = sampler.getCookieManager();
> > > > > vars.putObject("CookieMananger",manager);
> > > > > int count = manager.getCookiesCount();
> > > > > vars.put("count", count);
> > > > >
> > > > > CookieManager is null at the level of the pre-processor (just to
> make
> > > > sure,
> > > > > the pre-processor is a child to the HTTP Sampler).
> > > > >
> > > > > So, I'm still not sure that I'm not doing the correct thing, but
it
> > > > appears
> > > > > to not work and I'm not aware of other restrictions.
> > > > >
> > > > > --Adrian S
> > > > >
> > > > >
> > > > >
> > > > > On Tue, Jun 10, 2014 at 5:53 PM, Deepak Shetty <shettyd@gmail.com>
> > > > wrote:
> > > > >
> > > > > > I dont think sampler HTTPSampler creates a CookieManager - the
> > > > framework
> > > > > > sets it on the sampler so CookieManager manager =
> > > > > > sampler.getCookieManager(); should be returning it null
> > > > > >
> > > > > > If you are trying to manipulate cookies in places other than
a
> > > pre/post
> > > > > > processor of an HTTPSampler , then on your first HTTPSampler
you
> > can
> > > do
> > > > > > something like (in a pre processor scoped to this sampler)
> > > > > > CookieManager manager = sampler.getCookieManager();
> > > > > > vars.putObject("CookieMananger",manager)
> > > > > >
> > > > > > Then (CookieManager)vars.getObject("CookieManager") will allow
> you
> > to
> > > > get
> > > > > > it anywhere
> > > > > >
> > > > > >
> > > > > > On Tue, Jun 10, 2014 at 1:56 AM, Adrian Speteanu <
> > > asp.adieu@gmail.com>
> > > > > > wrote:
> > > > > >
> > > > > > > Hi guys,
> > > > > > >
> > > > > > > Need a suggestion with a piece of code that is not compiling
in
> > > > > > beanshell,
> > > > > > > and I have no idea why it doesn't work. The code is simple
and
> > it's
> > > > in
> > > > > a
> > > > > > > beanshell sampler at the moment:
> > > > > > > "
> > > > > > > import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
> > > > > > > import org.apache.jmeter.protocol.http.control.CookieManager;
> > > > > > > import org.apache.jmeter.protocol.http.control.Cookie;
> > > > > > >
> > > > > > > HTTPSampler sampler = new HTTPSampler();
> > > > > > > CookieManager manager = sampler.getCookieManager();
> > > > > > > Cookie cookie = new Cookie("SessionPersistence", "value",
> > > > > > "localhost:8080",
> > > > > > > "/", true, 0);
> > > > > > > manager.add(cookie);
> > > > > > > "
> > > > > > > Fails with
> > > > > > > "Response message: org.apache.jorphan.util.JMeterException:
> Error
> > > > > > invoking
> > > > > > > bsh method: eval"
> > > > > > > because of the very last line.
> > > > > > >
> > > > > > > Any ideas what to do and why it fails?
> > > > > > >
> > > > > > > Thanks,
> > > > > > > --Adrian S
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message