Forum Discussion

mayur_vats's avatar
mayur_vats
Occasional Contributor
5 years ago

get property value of a test case's step when this test case is called from another test case

Hi Guys. I am new to SoapUI tool and trying to setup a framework from scratch. I am using SoapUI for an end to end testing rather than API response validation.

 

So, as part of framework, I have setup it in such a way:

Suite1: 

 > TC1

 > TC2

Suite2:

 > TC3

 > TC4

Generic: (This suite contains generic reusable tests which can be called in Suite1&2)

  > loginToApp

  > createAccounts

  > fetchAccountDetails

 

I am creating a new custom report to report the execution detail of each step in extent report. I have used the test suite teardown script option to create a custom file for now.

 

The issue is: when I am trying to fetch response and request properties of my callable methods, they always return as Null. So I am not able to write them in my custom file.

 

This is my script below:

 

runner.results.each{ testCaseRunner ->


log.info 'test case name:'+testCaseRunner.testCase.name
testcase_logger = testsuite_logger.createNode(testCaseRunner.testCase.name);

testCaseRunner.results.each{testStepRunner->

def testStep=testStepRunner.testStep

log.info 'Config'+testStep.config
log.info 'Type'+testStep.config.type
if(testStep.config.type.toString().equals('calltestcase'))
{

def callableTest=testStep.targetTestCase
def callableTestName=callableTest.name
log.info 'callable test name--'+callableTestName

callableTest.getTestStepList().each{callableTestStep->
log.info 'callable step name---'+callableTestStep.name
log.info 'callable step type---'+callableTestStep.config.type


for(testProperty in callableTest.getTestStepByName(callableTestStep.name).getPropertyList()){
if(testProperty.isReadOnly()){
log.info( 'Output property: ' + testProperty.getName() + ' = ' + testProperty.getValue())
}else{
log.info( 'Input property: ' + testProperty.getName() + ' = ' + testProperty.getValue())
}
}

I have printed all the properties but request and response are always null.

 

Can anyone guide me on how to fetch request and response from the callable test step's response when the callable testcase is part of another testsuite?

  • mayur_vats :

     

    I have tried to automate the scenario which you have mentioned, hope below code will help you out :

    //For getting count from Properties step 1
    def propertiesStep = testRunner.testCase.getTestStepByName("Properties")
    HashMap<String,Integer> map = new HashMap<String,Integer>();
    for(testProperty in propertiesStep.getPropertyList()){
    	if(testProperty.name.contains("Serial")){
    		if(map.containsKey(testProperty.getValue()) )
    			map.put(testProperty.getValue(), map.get(testProperty.getValue())+1)
    		else{
    			map.put(testProperty.getValue(), 1)
    		}
    	}
    }
    //For setting count in Properties step 2
    def propertiesStep1 = testRunner.testCase.getTestStepByName("Properties1")
    for(testProperty in propertiesStep1.getPropertyList()){
    	
    	for(Map.Entry entry in map.entrySet()){
    		if(entry.getKey() in testProperty.value){
    			flag = testProperty.name.substring(testProperty.name.length()-1);
    			propertiesStep1.setPropertyValue("Count "+flag.toString(),entry.getValue().toString())
    		}
    	}
    }

     

     

    • mayur_vats's avatar
      mayur_vats
      Occasional Contributor

      Thank you, Himanshu for your prompt response. This script is executed as teardown script of a test suite so testRunner will not be an option there. It might work with runner object but I just figured it out with minor UI setting from SoapUI itself: I was calling a test case with the run mode option selected in the screenshot.

       

      If I select any option other than the selected one, I am able to read the properties of the callable test case when called as a Test Step.

       

      But thank you again for your help.

      • HimanshuTayal's avatar
        HimanshuTayal
        Community Hero

        mayur_vats :

         

        I have tried last piece of code but it is working at my end don't know what's the issue at your end refer below screenshot.