Forum Discussion

testhrishi's avatar
testhrishi
Frequent Contributor
8 years ago

How to capture Test PASS or FAIL test count using a property

Hi,  I am looking to see if there is a way to count total PASS or FAILED tests and have it stored as a property at suite level.  Has anyone tried this?  I am looking to this for reporting purposes...
  • rupert_anderson's avatar
    rupert_anderson
    8 years ago

    Hi,

     

    I am guessing that you are trying to run the script at TestCase TearDown script level maybe? If so, there is no 'runner' variable, only 'log,testCase,context,testRunner' variables. Please see my TestSuite screen shot below:

     

    Note - If TestSuite isn't what you want, then the above script can be adapted to run at TestCase level.

     

    Regards,

    Rup

  • rupert_anderson's avatar
    rupert_anderson
    8 years ago

    Hi,

     

    Ok, glad it worked.

    Ok, a low tech way to get the totals at project level is to simply change the initialization of the passed, failed variables to take the current values stored at project level - something like:

    def passed=Integer.parseInt(runner.testSuite.project.getPropertyValue("passed"))
    def failed=Integer.parseInt(runner.testSuite.project.getPropertyValue("failed"))
    
    for ( testCaseResult in runner.results )
    {
        for ( testStepResult in testCaseResult.getResults() ){
    
        	log.info testCaseResult.getResults().metaClass.methods*.name.sort().unique()
        	log.info testStepResult.status
        	 if (testStepResult.status.toString()=="OK") passed++
        	 	else failed++
    	}	
    }
    log.info "passed="+passed+" failed="+failed
    
    runner.testSuite.project.setPropertyValue("passed", "$passed" ) 
    runner.testSuite.project.setPropertyValue("failed", "$failed" ) 

    Note - in this simple case, you'll have to be careful to manually set the properties passed,failed=0 in the properties section of the project before running. Then each TestSuite should simply increment the overall project level totals with it's totals when the TestSuites run their TearDown scripts. 

     

    Will this work for you?

     

    Regards,

    Rup