Knowledge Base Article

How to capture teststep status as pass/fail using groovy to write it in txt file

Question

How to capture teststep status as pass/fail using groovy to write it in txt file

Answer

This can be done very simply by using the following TearDown Script:

// Define variables for holding test suites, test cases and test steps
def testSuites
def testCases
def testSteps

// Get all the test suites from the project
testSuites = project.testSuiteList

File file = new File("C:\\Users\\luciana\\Desktop\\test.txt")

/**
 * Iterate through each test suite, test case and test step
 */
testSuites.each() {
	// Log test suite name
	file << "-----------------------------------\n"
	file << "Running test suite: " + it.getName() + "\n"
	file << "-----------------------------------\n"
	// Get a list with the contained test cases
	testCases = it.getTestCaseList()
	testCases.each() {
		// Log test case name
		file << "-----------------------------------\n"
		file << "Running test case: " + it.getName() + "\n"
		file << "-----------------------------------\n"
		// Get a list with the contained test steps
		testSteps = it.getTestStepList()
		testSteps.each() {
			file << it.getName() + " - " + it.getAssertionStatus() + "\n"
		}
	}
}
Published 3 years ago
Version 1.0

Was this article helpful?

No CommentsBe the first to comment