Forum Discussion

richie's avatar
richie
Community Hero
7 years ago

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 ever...
  • Radford's avatar
    Radford
    7 years ago

    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.