Forum Discussion

amarnath1234's avatar
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 =
method = it.getHttpRequest().getHttpResponse().getmethod() method
statusCode = it.testRequest.Response.ResponseHeaders["#status#"][0] statusCode

  • this is not working,observed below error.

    Error detail 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
    testStepName =
    if(testStepName == "Request_GlobalOffersAvailable_Flag") {
    method = it.getHttpRequest().getResponse().getMethod()
    statusCode = it.testRequest.response.responseHeaders["#status#"][0]
    endpointURL = it.getHttpRequest().getResponse().getURL() method statusCode endpointURL
    } 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).

4 Replies

  • avidCoder's avatar
    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() method
    def statusCode= testStepName.testRequest.response.responseHeaders["#status#"][0] statusCode

    Let me know for any concerns.