Forum Discussion

amarnath1234's avatar
amarnath1234
Contributor
6 years ago

how to get method and status for the testcases

how to get method and status for the corrosponding test cases .

below is my script,when i ran this script for testStepName i got all the list of teststeps for the testcase(Ref:-ss1) but for method and StatusCode i found error(ref-ss2),it should work.attached  doc for ref,need help.

 please let me know highlight below is correct or not ?

 

def testStepName
def method
def statusCode
testCase.testStepList.each {
testStepName = it.name
method = it.getHttpRequest().getHttpResponse().getmethod()
log.info method
statusCode = it.testRequest.Response.ResponseHeaders["#status#"][0]
log.info statusCode
}

  • this is not working,observed below error.

    Error detail

    com.eviware.soapui.support.scripting.ScriptException: Error in TearDown Script of TS1_global offer override Flag_Verification

     

    below  is the code which is working fine-attached SS detail for ref.

    script detail

    def testStepName
    def method
    def statusCode
    def endpointURL
    testCase.testStepList.each{
    testStepName = it.name
    if(testStepName == "Request_GlobalOffersAvailable_Flag") {
    method = it.getHttpRequest().getResponse().getMethod()
    statusCode = it.testRequest.response.responseHeaders["#status#"][0]
    endpointURL = it.getHttpRequest().getResponse().getURL()
    log.info method
    log.info statusCode
    log.info endpointURL
    }
    log.info testStepName
    }
  • Hi Amarnath1234,

     

    Just to clarify - does the last script you posted do what you want?

    If it does, it's worth marking your reply as a solution (just click the Accept as Solution button next to the reply).

  • avidCoder's avatar
    avidCoder
    Super Contributor

    Hi Amarnath1243,

     

    Please use below code to fetch the method name and status code for REST Request.

    def testStepName = testRunner.testCase.getTestStepByName("REST REQUEST")
    def method = testStepName.getRestMethod().getMethod()
    log.info method
    def statusCode= testStepName.testRequest.response.responseHeaders["#status#"][0]
    log.info statusCode

    Let me know for any concerns.