André Campos
André Campos

Reputation: 21

How can I get the number of steps failed on a test case on Katalon?

I want to know how many steps failed on specific test cases and save it to a database. I already have a database.

My question now is how to save the number of test cases that failed in a test suite?

Upvotes: 2

Views: 428

Answers (1)

Mate Mrše
Mate Mrše

Reputation: 8414

This is the answer to the second question: how to obtain the number of test cases that failed/passed on a test suite run.

Create test cases and suite

I have 3 test cases named Test Case 1, 2, and 3 respectively. They are simple, they have just assert false or assert true as their steps, as seen in the screencap.

enter image description here

Test Suite 1 contains all of the above cases.

Create a test listener

Create a listener (right-click on Test Listeners [#1 in image] > New > New Test Listener) with the following two checkboxes selected:

New Test Listener

and add this to code:

class Listener {

    @AfterTestCase
    def sampleAfterTestCase(TestCaseContext testCaseContext) {
        if(testCaseContext.getTestCaseStatus()=='PASSED') {
            GlobalVariable.numOfPasses++
        }
        if(testCaseContext.getTestCaseStatus()=='FAILED') {
            GlobalVariable.numOfFails++
        }
    }

    @AfterTestSuite
    def sampleAfterTestSuite(TestSuiteContext testSuiteContext) {
        println 'Passes:' +GlobalVariable.numOfPasses
        println 'Failures:' +GlobalVariable.numOfFails
    }
}

Create global variables

Under Profiles > default [#2 in the first image] add two numeric variables numOfPasses and numOfFails and set them both to 0.

Run the test suite

Running the above setup will give you total number of failed/passed tests:

Passes:1
Failures:2

Upvotes: 1

Related Questions