You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by "Epp, Jeremiah W (Contractor)" <je...@cas.org> on 2016/04/08 20:33:34 UTC

Saving responses while recording (from code)

I've been working on automating captures of e2e test cases for use in load testing of our upcoming product line.  Getting a recording without the use of GUI has been pretty awful, but I've managed to reach parity with the manual recordings one of our QAs has been getting (mostly).

Unfortunately, we need some information from responses at the time of recording.

Through a lot of mucking about in the GUI, I discovered I can add a SimpleDataWriter as the child of a ProxyControl and capture the responses of a recording [0] in an XML file.  But how do I represent this relationship in code?  The API is rather opaque, and the relationship between AbstractVisualizer, Result(Collector|Saver|Renderer), et al is unclear even after digging into the source for a while.  I can:

        SimpleDataWriter writer = new SimpleDataWriter();
        writer.setEnabled(true);
        writer.setFile("/tmp/response.xml");

...easily enough, but I'm lost on how to properly bind that to my ProxyControl and how to make it spit a file out.  (Preferably without having to stop the recorder like with the GUI.)

Alternatively, is there a better way to get the response header and data out of the ProxyControl?  It seems like there's some intent to be able to get the response while doing traversal of the ProxyControl.target to build the final test plan: ProxyControl.deliverSampler() docs have a TODO about adding a serverResponse parameter.  But that's been there for a while.

Cheers,
Wyatt

PS: Sorry about the overly-large footer our MTA adds. I can't stop it. orz

[0] Found a funny bug where this only works once per writer; have to make a new one if you want to do more.

Confidentiality Notice: This electronic message transmission, including any attachment(s), may contain confidential, proprietary, or privileged information from Chemical Abstracts Service ("CAS"), a division of the American Chemical Society ("ACS"). If you have received this transmission in error, be advised that any disclosure, copying, distribution, or use of the contents of this information is strictly prohibited. Please destroy all copies of the message and contact the sender immediately by either replying to this message or calling 614-447-3600.


RE: Saving responses while recording (from code)

Posted by "Epp, Jeremiah W (Contractor)" <je...@cas.org>.
> -----Original Message-----
> From: Philippe Mouawad [mailto:philippe.mouawad@gmail.com]
> Sent: Tuesday, April 12, 2016 08:45
> To: dev@jmeter.apache.org
> Subject: Re: Saving responses while recording (from code)
> 
> If you mean that you need the response from api of Proxy then you will have
> to contribute a PR.

That would be cool, but I already noted it's a TODO for ProxyControl.deliverSampler().  I considered doing that, but I'd be blocked on the same thing I'm blocked on already: getting the response from the proxy at all.

> If not, then just put a View Results Tree under Proxy where filename is
> setup and request/response will be saved in xml or csv depending on your
> choice.
>
This is basically what I'm trying to do for now.  Except without the GUI.

What does " put a View Results Tree under Proxy " look like from a code standpoint?

I've been digging at the JMeter code for days, now, and I cannot for the life of me figure out the underlying mechanism for associating an AbstractVisualizer (presumably, it'd be this because SimpleDataWriter is basically a no-op) with a ProxyControl object such that I can then save the output to an XML file.  It's obviously possible because I can get it to work in the GUI.

Right now, I have something like this:

        SimpleDataWriter writer = new SimpleDataWriter();
        writer.setEnabled(true);
        ResultCollector collector = (ResultCollector) writer.createTestElement(); //This SHOULD set up the default ResultCollector
        collector.setFilename("/tmp/response.xml");
        proxyControl.addTestElement(collector); //This is probably where I've gotten it wrong

But when I hit the breakpoint after I stop the proxy and look at the ResultCollector, nothing's been saved.  That last line is probably wrong, but it's not clear what is right.  I can't add the writer itself because it's not a TestElement, but the other add* methods for ProxyControl make even less sense.  ResultCollector implements TestStateListener, so notifyTestListenersOfStop() should work on it, but since it's not getting populated, something is clearly not set up right.  But what?

Regards,
Wyatt

Confidentiality Notice: This electronic message transmission, including any attachment(s), may contain confidential, proprietary, or privileged information from Chemical Abstracts Service ("CAS"), a division of the American Chemical Society ("ACS"). If you have received this transmission in error, be advised that any disclosure, copying, distribution, or use of the contents of this information is strictly prohibited. Please destroy all copies of the message and contact the sender immediately by either replying to this message or calling 614-447-3600.


Re: Saving responses while recording (from code)

Posted by Philippe Mouawad <ph...@gmail.com>.
If you mean that you need the response from api of Proxy then you will have
to contribute a PR.
If not, then just put a View Results Tree under Proxy where filename is
setup and request/response will be saved in xml or csv depending on your
choice.

Thanks

On Friday, April 8, 2016, Epp, Jeremiah W (Contractor) <je...@cas.org> wrote:

> I've been working on automating captures of e2e test cases for use in load
> testing of our upcoming product line.  Getting a recording without the use
> of GUI has been pretty awful, but I've managed to reach parity with the
> manual recordings one of our QAs has been getting (mostly).
>
> Unfortunately, we need some information from responses at the time of
> recording.
>
> Through a lot of mucking about in the GUI, I discovered I can add a
> SimpleDataWriter as the child of a ProxyControl and capture the responses
> of a recording [0] in an XML file.  But how do I represent this
> relationship in code?  The API is rather opaque, and the relationship
> between AbstractVisualizer, Result(Collector|Saver|Renderer), et al is
> unclear even after digging into the source for a while.  I can:
>
>         SimpleDataWriter writer = new SimpleDataWriter();
>         writer.setEnabled(true);
>         writer.setFile("/tmp/response.xml");
>
> ...easily enough, but I'm lost on how to properly bind that to my
> ProxyControl and how to make it spit a file out.  (Preferably without
> having to stop the recorder like with the GUI.)
>
> Alternatively, is there a better way to get the response header and data
> out of the ProxyControl?  It seems like there's some intent to be able to
> get the response while doing traversal of the ProxyControl.target to build
> the final test plan: ProxyControl.deliverSampler() docs have a TODO about
> adding a serverResponse parameter.  But that's been there for a while.
>
> Cheers,
> Wyatt
>
> PS: Sorry about the overly-large footer our MTA adds. I can't stop it. orz
>
> [0] Found a funny bug where this only works once per writer; have to make
> a new one if you want to do more.
>
> Confidentiality Notice: This electronic message transmission, including
> any attachment(s), may contain confidential, proprietary, or privileged
> information from Chemical Abstracts Service ("CAS"), a division of the
> American Chemical Society ("ACS"). If you have received this transmission
> in error, be advised that any disclosure, copying, distribution, or use of
> the contents of this information is strictly prohibited. Please destroy all
> copies of the message and contact the sender immediately by either replying
> to this message or calling 614-447-3600.
>
>

-- 
Cordialement.
Philippe Mouawad.