Forum Discussion

st-pat's avatar
st-pat
Occasional Contributor
6 years ago

get testcase status via groovy script

Hi,

I'm fighting with groovy since a week or two (I'm totally new to it and have hardly any knowledge) 
I found over all the forums a lot of scripts for groov or teardown or more but all of them seem to miss something so I can't run in inside my Ready/Soap API.

Now I found at https://softwaretestersforum.blogspot.com/2013/03/groovy-script-to-save-test-results-to.html

a working one

import com.eviware.soapui.support.*; 
//Get the TestCase Name to use it as a File Name. 
def testCase = testRunner.getTestCase() 
fileName= testCase.getName() 
//Get Current date time stamp to append the same in the file name. 
def date = new Date() 
def dts = date.format("yyyy-MM-dd-HH-mm-ss") 
//Write Request to a XML File and save it with Date Time stamp appended to your filename. 
def myXmlRequest = "x:/"+fileName+"Request_"+dts+".xml" 
def req1 = context.expand('${brianSisClubQuery - Request#Request}') 
def req2 = context.expand('${brianSisClubWrite - Request#Request}') 
def req3 = context.expand('${CLUBFOR-Fail#Request}') 
def request = req1+req2+req3
def req = new File(myXmlRequest) 
req.write(request, "UTF-8") 
// Write Response to a XMl File and save it with Date Time stamp appended to your filename. 
def myXmlResponse = "x:/groove/"+fileName+"Response_"+dts+".xml" 
def resp = context.expand( '${brianSisClubQuery - Request#Response}' ) 
def resp1 = context.expand( '${brianSisClubWrite - Request#Response}' ) 
def resp2 = context.expand( '${CLUBFOR-Fail#Response}' ) 
def response =resp+resp1+resp2
def res = new File(myXmlResponse) 
res.write(response, "UTF-8")

the thing is it only takes the testeps (which are ok for that case where there's only 3 but I have like 60 steps in other cases)

if i change it to the Testcase property the file stays empty

import com.eviware.soapui.support.*; 
//Get the TestCase Name to use it as a File Name. 
def testCase = testRunner.getTestCase() 
fileName= testCase.getName() 
//Get Current date time stamp to append the same in the file name. 
def date = new Date() 
def dts = date.format("yyyy-MM-dd-HH-mm-ss") 
//Write Request to a XML File and save it with Date Time stamp appended to your filename. 
def myXmlRequest = "x:/groove"+fileName+"Request_"+dts+".xml" 
def req1 = context.expand('${#CLUB-ATM-UC#Request}')  
//def req2 = context.expand('${brianSisClubWrite - Request#Request}') 
//def req3 = context.expand('${CLUBFOR-Fail#Request}') 
def request = req1 //+req2+req3
def req = new File(myXmlRequest) 
req.write(request, "UTF-8") 
// Write Response to a XMl File and save it with Date Time stamp appended to your filename. 
def myXmlResponse = "x:/groove/"+fileName+"Response_"+dts+".xml" 
def resp = context.expand( '${#CLUB-ATM-UCt#Response}' )
//def resp1 = context.expand( '${brianSisClubWrite - Request#Response}' ) 
//def resp2 = context.expand( '${CLUBFOR-Fail#Response}' ) 
def response =resp//+resp1+resp2
def res = new File(myXmlResponse) 
res.write(response, "UTF-8")

so where's my error (maybe only in my brains)..
thnx

 

 

11 Replies

    • st-pat's avatar
      st-pat
      Occasional Contributor

      The CLUB-ATM-UC is actually the complete case that's why I chose the leading # I think it's more a problem of wrong results definition

      • Radford's avatar
        Radford
        Super Contributor

        st-pat responding to when you mention about the wrong results definition. When trying to get properties/data into a Groovy Script test step, have you investigated the "point and click" Get Data functionality, access this from the within the right mouse click menu when within a Groovy script editor (In fact this can be accessed most places that allow property expansions). This helped me a lot when I was getting started with SoapUI.

  • sanj's avatar
    sanj
    Super Contributor

    This will get you the status of a test step

    def result= testStep.run(testRunner,context).getStatus().toString()

    OK means its pass

    • st-pat's avatar
      st-pat
      Occasional Contributor

      sanj I had read this somewhere but when I paste this I get "missing property exception" for the 'testStep' do i need to fill in my testcase name with # ?!?
      Furthermore I'd need it to work for the testcase

      • sanj's avatar
        sanj
        Super Contributor

        Do the following to get  reference to tc and test step,

        After that you should be able run using context and get status of the test step

         

        tc = testsuite.getTestCaseByName("TC Name")
        def testStep = tc.testSteps['TS name']

  • nmrao's avatar
    nmrao
    Champion Level 3
    st-pat, what's your objective? or trying to achieve? where do you need the status of the test case?
    • st-pat's avatar
      st-pat
      Occasional Contributor

      The need is for testcases that are not run by testrunner to have the logs on a network folder because other applications need to know if the run of the case was successful or not so they can continue automatically. Teststeps are not so practical because 1st i have up to two hundreds in my different cases and secondly some of them are purposely failing (e.g. wrong input address country codes...)so it would take also some way to bring the positive negative for other applications to know.Since there's now way to store the error logs outside of \user\.readyapi I only have this solution

       

      • nmrao's avatar
        nmrao
        Champion Level 3
        When would that happen (testcases that are not run by testrunner)?