Ask a Question

Execution Stats TearDown Script By Lucian

SOLVED
richie
Community Hero

Execution Stats TearDown Script By Lucian

Hey!

 

TI am using a script @Lucian developed to record my execution stats.   Its a teardown script I've stuck at project level at moment and is as follows:

 

It's fantastic - does almost everything I want.  Currently it iteratively runs through each of the testsuites and returns the pass/fail numbers for the tests in each testsuite in the project.  This is great - but on top of the current stats returned I need it to return a total executed, total PASS and total FAIL for the project after all the other stats have been returned, rather than at testsuite level which is what it's doing at the moment. 

 

I think I could probably do that if the script wasn't iterative - if the script parked the values into variables that I could add up at the end - I think I could do that - but I just dont know where to start to alter the existing to give me those extra project level stats - or maybe it is easy and I'm just being dumb!?!? 😉

 

// Define variables for holding test suites, test cases and test steps
def testSuites
def testCases
def passedTestCases = 0
def failedTestCases = 0

// Get the list of test suites
testSuites = runner.getResults() 

// Iterate through each test suite
testSuites.each() {
	log.info "----------------------------------------"
	log.info "The " + "'" + it.getTestSuite().getName() +"'" + " test suite has " + it.getStatus() + "ED."
	log.info "Test case execution results as follows..."

	// Get all the test cases and iterate through them
	testCases = it.getResults()
	testCases.each() {
		log.info "Test case " + "'" + it.getTestCase().getName() + "' " + it.getStatus() + "ED."
		if ( it.getStatus().toString().equals("PASS") ) {
			passedTestCases++
		} else {
			failedTestCases++
		}
	}

	log.info " Number of PASSES = " + passedTestCases.toString() + " Number of FAILS = " + failedTestCases.toString() + "."
	passedTestCases = 0
	failedTestCases = 0
}

 

 

If anyone could give me a steer - I'd appreciate it - I just don't know where to start to alter the script accordingly.

 

As always - props to the originator of the work (Lucian) - I can't take credit! 🙂

 

nice one

 

richie

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
4 REPLIES 4
Radford
Super Contributor

Does the following give you what you want? I've just removed the resetting of the pass/fail counters, and then moved the logging of the totals to the very end.

 

// Define variables for holding test suites, test cases and test steps
def testSuites
def testCases
def passedTestCases = 0
def failedTestCases = 0

// Get the list of test suites
testSuites = runner.getResults() 

// Iterate through each test suite
testSuites.each() {
	log.info "----------------------------------------"
	log.info "The " + "'" + it.getTestSuite().getName() +"'" + " test suite has " + it.getStatus() + "ED."
	log.info "Test case execution results as follows..."

	// Get all the test cases and iterate through them
	testCases = it.getResults()
	testCases.each() {
		log.info "Test case " + "'" + it.getTestCase().getName() + "' " + it.getStatus() + "ED."
		if ( it.getStatus().toString().equals("PASS") ) {
			passedTestCases++
		} else {
			failedTestCases++
		}
	}
}

log.info " Number of PASSES = " + passedTestCases.toString() + " Number of FAILS = " + failedTestCases.toString() + "."

@Radford

 

hahaha! - almost - it gives me the total execution stats across the whole project now, but I lose the 'per test suite' stats when I apply the change you suggest.

 

I need to keep the 'per suite' SUB TOTAL (like the old version of script) AND the 'per project' TOTAL (like your version of the script) - I need both - not one nor just the other.

 

I'm stuffed -  either reset the stat counters each iteration (to keep the per suite stats) or remove them and have logging at the end to have a cumulative (per project count).

 

Thanks man - appreciate the help - I'm gonna keep digging! 🙂

 

richie

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Radford
Super Contributor

Opps... Sorry...

 

The following code is very "rough and ready" and I don't have time to fully test and refine, but try the following:

 

// Define variables for holding test suites, test cases and test steps
def testSuites
def testCases
def totalPassedTestCases = 0
def totalFailedTestCases = 0

def testSuitePassTotals = []
def testSuiteFailTotals = []

// Get the list of test suites
testSuites = runner.getResults() 

// Iterate through each test suite
testSuites.each() {
	log.info "----------------------------------------"
	log.info "The " + "'" + it.getTestSuite().getName() +"'" + " test suite has " + it.getStatus() + "ED."
	log.info "Test case execution results as follows..."

	// Get all the test cases and iterate through them

	def testSuitePassedTestCases = 0
	def testSuiteFailedTestCases = 0
			
	testCases = it.getResults()
	testCases.each() {
		log.info "Test case " + "'" + it.getTestCase().getName() + "' " + it.getStatus() + "ED."
		if ( it.getStatus().toString().equals("PASS") ) {
			totalPassedTestCases++
			testSuitePassedTestCases++
		} else {
			totalFailedTestCases++
			testSuiteFailedTestCases++
		}
	}

	testSuitePassTotals.add([name:it.getTestSuite().getName(), count:testSuitePassedTestCases])
	testSuiteFailTotals.add([name:it.getTestSuite().getName(), count:testSuiteFailedTestCases])
	
}

log.info "----------------------------------------" testSuitePassTotals.each(){ log.info('Test Suite "' + it.name + '" number of passed test cases = ' + it.count) }
log.info "----------------------------------------" testSuiteFailTotals.each(){ log.info('Test Suite "' + it.name + '" number of failed test cases = ' + it.count) }
log.info "----------------------------------------" log.info " Number of PASSES = " + totalPassedTestCases.toString() + " Number of FAILS = " + totalFailedTestCases.toString() + "."

 

Note sure if it's exactly what you want, but hopefully it might point you in the right direction.

@Radford

 

that's brilliant fella.  Gives me everything I need and this will help me alot - cos I can now spend some time comparing the 2 scripts and I can now follow the progression - this has helped me - really!

 

nice one!

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
cancel
Showing results for 
Search instead for 
Did you mean: