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
Radford
Super Contributor

I think that your prolem might be the property expansion in the line:

 

def req1 = context.expand('${#CLUB-ATM-UC#Request}') 

 

Assuming that CLUB-ATM-UC is a test step name, I don't think you need the first #.

 

Take a look at the property expansion help page:

 

https://support.smartbear.com/readyapi/docs/testing/properties/expansion.html

 

You'll see that the test step scope does not have a leading #.

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
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

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
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']

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.

st-pat
Occasional Contributor

@Radford The problem in that is that in the editor I don't get a result from the TC only from the teststeps as a property and this is the case I have above.

@sanj again missing property definition
Clipboard01.jpg

I have it like this now

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

 

 

nmrao
Community Hero

@st-pat, what's your objective? or trying to achieve? where do you need the status of the test case?


Regards,
Rao.
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

 

cancel
Showing results for 
Search instead for 
Did you mean: