0

I am testing a webapp, i want to log all http request and response, how do i do that?
I am just writing

log = grinder.logger.info
def page15(self):
"""GET COPSApp (request 1501)."""
result = request1501.GET('/webdynpro/call_agent_dtop-login_wd/COPSApp')
log("-----------------------------------")
return result

But it is not logging. what do i need to do in order to login

Thanks a lot

Arvind
  • 1,207
  • 6
  • 27
  • 55

1 Answers1

1

Request Logging

Grinder will normally log all of your HTTP requests. So at least for the request logging, the default behaviour may be good enough for you. Look for a log file with a name like

<hostname>-0.log

In this file, you'll see your requests, plus the server response codes.

If you want to explicitly log your http request from your code, you'll need to use a slightly different pattern than the one you are currently using.

    request1501.setUrl('/webdynpro/call_agent_dtop-login_wd/COPSApp')
    response1501=request1501.GET()
    log(request1501.getUrl())

Response Logging

When logging the HTTP response, you need to deal with the body and the headers separately. Based on your code example above, you could log the body like this:

    log(response1501.getText())

There are a couple of ways you can log the HTTP response headers. The easiest way would be to dump them all to the log in a single statement, like this:

    log(response1501.toString())

To get an idea of the other options for logging http response headers, and the different things you can access separately, see the HTTPResponse API here:

http://grinder.sourceforge.net/g3/script-javadoc/HTTPClient/HTTPResponse.html

Login

In your question, you also asked "what do i need to do in order to login". I assume this is a typo, and that what you really mean is how do you write stuff to the log. To do an actual login, you need to submit a username and password, typically via HTTP post. Grinder can do this for you easily enough, but that topic should be addressed in a separate question.

Travis Bear
  • 13,039
  • 7
  • 42
  • 51
  • Thanks for your reply , I came to know many thing by your answer, I am still facing problem that i am not able to log anything even simple text like my name etc. *log = grinder.logger.info* i have wiritten this in starting of my .py file and than written *log("-----------------------------------")* in some method . Do i need to import some package or sth else . I just want to log a simple text in some of calling function . Thanks a lot – Arvind Jul 09 '12 at 04:16
  • And in my .py file start with
    from net.grinder.script import Test
    from net.grinder.script.Grinder import grinder
    from net.grinder.plugin.http import HTTPPluginControl,
    HTTPRequest
    from HTTPClient import NVPair
    connectionDefaults = HTTPPluginControl.getConnectionDefaults()
    httpUtilities = HTTPPluginControl.getHTTPUtilities()
    – Arvind Jul 09 '12 at 04:21
  • is it possible (for debugging purposes) to control the log output and have grinder log to e.g. '.log' all the time? – moin moin Aug 07 '15 at 09:08
  • for me it works like this: `from net.grinder.script.Grinder.grinder import logger as log` `log.info("-----------")` – moin moin Sep 16 '15 at 15:50