Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get whether a test suite passed or failed in TestListener? #2

Closed
zyong812 opened this issue Dec 28, 2017 · 4 comments

Comments

@zyong812
Copy link

commented Dec 28, 2017

TestListener is a new feature for katalon 5.2.
I add a sampleAfterTestSuite hook, and there is a TestSuiteContext instance.
How can I get whether a test suite passed or failed?
Is there any document or source code for TestSuiteContext?
image

@vinhpnguyen

This comment has been minimized.

Copy link
Contributor

commented Dec 28, 2017

There is no status for a test suite, so you can't get whether it is passed or failed.

@zyong812

This comment has been minimized.

Copy link
Author

commented Dec 28, 2017

@vinhpnguyen
Thank you for reply.
How about getting how many test cases failed?

Because I want to add a hook which can notify me by sms or phone call if there are failed cases, but the testSuiteContext provides so little information and I can't find detailed docs of it.

@vinhpnguyen

This comment has been minimized.

Copy link
Contributor

commented Dec 29, 2017

Hi there,

Please find below sample code to resolve your current concern as a workaround solution:

import java.util.concurrent.atomic.AtomicInteger
import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.AfterTestSuite
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.context.TestSuiteContext

class NewTestListener {
	AtomicInteger passedTC = new AtomicInteger(0)
	AtomicInteger failedTC = new AtomicInteger(0)

	/**
	 * Executes after every test case ends.
	 * @param testCaseContext related information of the executed test case.
	 */
	@AfterTestCase
	def sampleAfterTestCase(TestCaseContext testCaseContext) 
	{
		if (testCaseContext.getTestCaseStatus() == 'PASSED')
		{
			passedTC.andIncrement()
		}
		else if (testCaseContext.getTestCaseStatus() == 'FAILED')
		{
			failedTC.andIncrement()
		}
	}

	/**
	 * Executes after every test suite ends.
	 * @param testSuiteContext: related information of the executed test suite.
	 */
	@AfterTestSuite
	def sampleAfterTestSuite(TestSuiteContext testSuiteContext)
	{
		println "Number of passed TCs is: " + passedTC.get()
		println "Number of failed TCs is: " + failedTC.get()
	}
}

Regards to information about either TestSuiteContext or TestCaseContext, actually the sample methods generated from sample template are all of available functions within these contexts and they are quite easily understandable, so I think that's why there is no further documentation for the current Test Listeners

@zyong812

This comment has been minimized.

Copy link
Author

commented Dec 29, 2017

@vinhpnguyen
It can help to solve my problem. Thank you so much

@zyong812 zyong812 closed this Dec 29, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.