Forum Discussion

swprabhu's avatar
swprabhu
Occasional Contributor
6 years ago

How to have a failed step within a loop to be logged in transaction log

I have a groovy step in a testcase with code as below. This  testcase has multiple requests which run based on a loop count. The issue I face :  My teststep "checkTransitionStatus" which is REST ...
  • KirillZakharov's avatar
    KirillZakharov
    6 years ago

    Hi swprabhu,

     

    You can use DataDriven Loop for example. You should set it like on this video. Then you will see all results in the Transaction Log. The second way, you can write the result into a file, then after the run, you can find the results in it. Here is the video. Here is the script:

    def count = context.expand( '${#TestCase#countOfRuns}' )
    int countOfRuns = count.toInteger()
    File file = new File("C:/Users/Kirill.Zakharov/Downloads/06062019/test.txt")
    for( def i = 1; i <= countOfRuns; i++){
    	file.append("\nRun number: " + i + "\r\n")
    	writeRes("test", file)
    	writeRes("test1", file)
    	writeRes("test2", file)
    }
    
    def writeRes(String stepName, File file){
    	def status = context.testCase.testSteps[stepName].run(testRunner, context).getStatus().toString()
    	log.info(status)
    	if(status == "PASS"){
    		file.append(stepName + " Test Step passed\r\n")
    	}else{
    		file.append(stepName + "Test Step failed\r\n")
    	}
    }