Ask a Question

get testcase status via groovy script

st-pat
Occasional Contributor

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 11
nmrao
Community Hero

When would that happen (testcases that are not run by testrunner)?


Regards,
Rao.

One thing I noticed with the groovy script snippets posted is that your reference to "testsuite" is not defined as far as I can see.

 

Instead of this:

import com.eviware.soapui.support.*; 
def  tc = testsuite.getTestCaseByName("CLUB-ATM-UC")
/def testStep = tc.testSteps['brianSisClubWrite - Request']
def req = new File(tc)

 

 

You may want this:

import com.eviware.soapui.support.*; 
def  tc = context.testCase.testSuite.getTestCaseByName("CLUB-ATM-UC")
/def testStep = tc.testSteps['brianSisClubWrite - Request']
def req = new File(tc)



---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
cancel
Showing results for 
Search instead for 
Did you mean: