Forum Discussion

MikeSchoolik's avatar
MikeSchoolik
Occasional Contributor
10 years ago

Rest Project RequestFilter.afterRequest Target issue

On a rest project at the project level I have an event :RequestFilter.AfterRequest with a target for a given step as "Authenticate.aspx - Request 1".
The groovy script for it is (stripping out extra characters):

if( request.response == null )

return

// get response content

def content = context.httpResponse.responseContent
//def tvar

// manipulate content
//tvar=content[0..35]
//log.info (tvar)
content=content [0..35]
log.info (content)

// write it back

context.httpResponse.responseContent = content

When I run this, it doesn't work at all. If I strip out the target, it works for just the individual step
but not the suite (I only want it to run for this step for as I only want it on this step)

My goal is to strip out extra characters for a key and then pass it off to the additional steps that are all request which use this generated key. The key changes with each run.

Any ideas?

3 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Is the event handler not being ran at certain levels i.e. TestSuite, project level the problem? If so, remove the following code.


    if( request.response == null )

    return



    Regards,
    Marcus
    SmartBear Support
  • MikeSchoolik's avatar
    MikeSchoolik
    Occasional Contributor
    yes its not being passed to the lower levels (testsuite)...Does Target work?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    If removing the below works then the issue is not with Target, you can remove the Target and you will still see the same problem. The response is null and the event handler is returning before executing the code afterwards, so the main problem is that the response is null when running from certain levels. I believe this has to do with the response not being populated yet in the request object. You can use context.httpResponse.responseContent in place of request.response instead if that is working.

    if( request.response == null )
    return



    Regards,
    Marcus
    SmartBear Support