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 operation has a script assertion . I notice that if an assertion fails during one of the loop runs, it doesnot get logged under 'Transaction log' tab. So basically after the 4 runs , if my second run has an assertion failure , I still get a pass for that step in transaction log . Also when I manually observe I see that different values are passed to the step as per my expectation on each loop run , but the transaction log doesnot show these loop runs separately. It just shows one run as pass but in actual, it runs the step multiple times based on the count. So how can I have the individual runs of the loop logged in transaction log so that I can see the status of the assertion for each run
def loop = 1 while (loop < 4 ) { testRunner.runTestStepByName("getUniqueExternalReferenceValues 2") sleep 700 testRunner.runTestStepByName("getTransitionPackages") sleep 700 testRunner.runTestStepByName("TransitionProps") sleep 700 testRunner.runTestStepByName("UpdateService_TransitionServiceItem") sleep 700 testRunner.runTestStepByName("getSoaTransactionsByExternalAccountReference 3") sleep 700 testRunner.runTestStepByName("checkTransitionStatus") sleep 700 testRunner.runTestStepByName("TransitionVariables") sleep 700 loop = loop + 1 }
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") } }