testingfly.com

Groovy Scripts and Event Handlers - Sample Scripts

  • Scripts to log Request and Response
  • Add the following Project Event (i.e. RequestFilter.afterRequest) with the scripts to gracefully log the Request and Response Pairs along with the Test Case details -

    String rawRequest = new String(context.httpResponse.getRawRequestData(), "UTF-8") 
    String rawResponse = new String(context.httpResponse.getRawResponseData(), "UTF-8") 
    log.info "TEST CASE NAME: ${context.testCase.name}\n"
    if (rawRequest!=null){
       log.info "TEST CASE NAME: ${context.testCase.name}"
       log.info("RAW REQUEST"+rawRequest+"\n\n\n")
    }
    log.info "TEST CASE NAME: ${context.testCase.name}"
    log.info("RAW RESPONSE"+rawResponse+"\n\n\n")

  • Scripts to log Test case Status to Console
  • Add the following Project Event (i.e. TestSuiteRunListener.afterRun) with the scripts to gracefully log the Test Case Status -

    if ("${context.testRunner.getStatus()}"=="FINISHED")
       "TEST CASE STATUS: PASSED"
    else
       log.info "TEST CASE STATUS: FAILED"


    To go places and do things that have never been done before – that’s what living is all about.
    - Michael Collins, flew on Gemini 10 and Apollo 11