cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Occasional Contributor

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
}

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

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

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")
	}
}

Kirill Zakharov
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
5 REPLIES 5
Frequent Contributor

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

Can you edit your post and embed the code in code tags, you're making it hard to read and therefore less likely to get an answer.

 

All useful tests need to assert that the behaviour is correct, that what was expected actually happened.  You will need to assert something after each step to ensure you catch the error.

 

http://groovy-lang.org/style-guide.html#_catch_any_exception

 

passed = true
// while (...) {
   // get test step by name
   // run the test step
   // verify the result
   verify(expected == actualResult)
}
assert passed

def verify(def condition) {
	try {
		assert condition
	} catch (AssertionError assertion) {
		log.info assertion
		passed = false
	}
}

 

TestRunner. runTestStepByName(...) returns a TestStepResult you can use.

https://support.smartbear.com/readyapi/apidocs/soapui/com/eviware/soapui/impl/wsdl/panels/support/Mo...

 

public TestStepResult runTestStepByName(String name)

 

 

Occasional Contributor

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

Thanks. But I did not get where exactly do I need to use it. I tried something like below and it gave an error. Also when it get the results , what does it basically get? The assertion status ?

def loop = 1
log.info loop
while (loop < 4 ){ //must match if loop
log.info "Still Running " + loop
//You have to explicitly list all steps to run between the loop script and the test step loop start
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

public TestStepResult runTestStepByName("checkTransitionStatus")

loop = loop + 1
}

Occasional Contributor

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

Can anyone please help!

Highlighted

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

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")
	}
}

Kirill Zakharov
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Moderator

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

Thanks for providing the instructions, @KirillZakharov !

@swprabhu does this help? Have you found a solution?

 


Olga Terentieva
SmartBear Assistant Community Manager

New Here?
Join us and watch the welcome video:
Join the exciting event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win