Forum Discussion

ashkht's avatar
ashkht
Contributor
8 years ago

How to get current data row# from DataSource TestStep into list using groovy script

Hello,

 

I am trying to fetch current data row # from DataSource (containing different test data - test data driven concept) TestStep using groovy script TestStep and then add it to list. But i am facing an issue wherein, if there are multiple test failures - while adding data row# to list, only last failed data row is been saved in list by overriding previous data row#.

 

Tool used: Ready API 1.9.0

 

Please find groovy script below which i have tried: 

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projPath = groovyUtils.projectPath
def reportId = context.expand( '${DataSource#Report ID}' )
def desc = context.expand( '${DataSource#TC Description}' )
def row = testRunner.testCase.testSteps["DataSource"].currentRow
def testStepcount=testRunner.testCase.getTestStepCount();
def testsuitename=testRunner.testCase.testSuite.getName()
def testcase = testRunner.testCase.getName()
def rowStatus=[]
def Status='OK'
def dataRowList = []
def failDetails1=new File(projPath+"/SoapUIResults/"+testsuitename+"/"+"failDetails1.html")
log.info testStepcount
for(i=1;i<=(testStepcount-1);i++)
{
rowStatus[i]=context.expand( '${=testRunner.results[testRunner.results.size()-'+i+'].status}')
if(rowStatus[i]=='FAILED')
{
Status='FAILED'
dataRowList.add(row)
}
}

 

Also, please find attached SOAP UI testcase to know structure of test case.

 

Can you please assist me on the same.

 

Regards,

Ashish

3 Replies

  • Hello,

     

    Appreciate your help on the issue as mentioned above..

     

    Regards,

    Ashish

  • ashkht

    I am trying to follow the flow you have and I'm not sure why you would want to add the row number to a list. It looks like you are looping inside your script loop. Unless I am totally misunderstanding what you are trying to accomplish my input would be to write out to a file with the current row number and any additional parameters to would like to include. It looks like you are using "failDetails1.html" for something so here is what I would suggest.

     

    import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus
    def TestCase = testRunner.getTestCase()
    def StepList = TestCase.getTestStepList()
    def row = testRunner.testCase.testSteps["DataSource"].currentRow
    def failDetails=new File("C:/folder/failDetails1.html")   //failed being written to

     

     

    StepList.each{
    if(it.metaClass.hasProperty(it,'assertionStatus')){
    if(it.assertionStatus == AssertionStatus.FAILED){
    testRunner.testCase.setPropertyValue("Result", "Fail" )
    failDetails.append row + ' row failed' + '<br>'    //append the results
    log.info "${it.name} FAIL"
    }else if(it.assertionStatus == AssertionStatus.VALID){
    testRunner.testCase.setPropertyValue("Result", "Pass" )
    log.info "${it.name} OK"
    }else if(it.assertionStatus == AssertionStatus.UNKNOWN){
    log.info "${it.name} UNKNOWN (PROBABLY NOT ALREADY EXECUTED)"
    }
    }
    }

    • ashkht's avatar
      ashkht
      Contributor

      Hello bagochips

      Thanks for your response!

       

      I am trying to save data row # to a list for failed test cases, since i have written a Tear down script at Test Suite level,
      to capture messages for failed test steps across all test cases from a test suite.

       

      Then, i am publishing captured failed test step messages under Log details section of HTML report generated from test suite level. But i am stuck at one thing, wherein i wanted to print Data row # for corresponding failed test step messages so that it can be segregated and can give more clarity to logs section.

       

      During this course of generating HTML report, found below issues due to which i have come up with this approach:

       

      1. SOAP UI provides Data Row # as a message at end of each test data row execution and it is independent of failed test steps, due to which i am unable to capture this message even if i add boolean condition to check test step status = 'FAILED' at tear down script.
      2. The below groovy statement, is only supported at test case level and not at test suite since 'runner' class doesn't support
      below statement or methods.
      def row = testRunner.testCase.testSteps["DataSource"].currentRow

       

      PFA Tear down script written at test suite level - capturing messages for failed test steps and also snippet of HTML report and SOAPUI test case structure.

       

      Appreciate your help on the same.

       

      Regards,
      Ashish

       

Recent Discussions