# List all failed tests as final execution step

**URL:** <https://forum.robotframework.org/t/list-all-failed-tests-as-final-execution-step/5366>\
**Category:** Robot Framework\
**Created:** [27 February 2023 20:14 UTC](https://forum.robotframework.org/t/list-all-failed-tests-as-final-execution-step/5366 "2023-02-27T20:14:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OrrinGradwell](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/orringradwell/32/2387_2.png) [@OrrinGradwell](https://forum.robotframework.org/u/OrrinGradwell)\
**Post date:** [27 February 2023 20:14 UTC](https://forum.robotframework.org/t/list-all-failed-tests-as-final-execution-step/5366/1 "2023-02-27T20:14:01Z")

</div>

I have quite a complicated setup and the one use case that we have is that when all the tests have completed, as a last step, I should list all the failed test case names.

This data will then be written to a 3rd party logger via API. I already post data to said logger but struggling to get the list of failed test cases.

What I do have is a python script that does get all the names as a list but I am unsure how to get that data to robot framework so that it can be used in the REST call. (Json payload.)

Working script:  
robotAPI.py

```
    from robot.api import ExecutionResult, ResultVisitor
    
    class Visitor(ResultVisitor):
    
        def __init__ (self):
            self.failed = []
    
        def end_test(self, test):
            if test.status == "FAIL":
                self.failed.append(test)
    
    visitor = Visitor()
    
    result = ExecutionResult('assets/results/output.xml')
    result.visit(visitor)
    
    for x in visitor.failed:
        print(x)

```

Any help at this stage will be welcomed.

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [28 February 2023 00:48 UTC](https://forum.robotframework.org/t/list-all-failed-tests-as-final-execution-step/5366/2 "2023-02-28T00:48:00Z")

</div>

Hi Orrin,

- Using your code, you can combine [Run Process](http://robotframework.org/robotframework/latest/libraries/Process.html#Run%20Process) with [Split To Lines](http://robotframework.org/robotframework/latest/libraries/String.html#Split%20To%20Lines)

```python
    ${result}= Run Process python robotAPI.py|
    @{lines}= Split To Lines ${result.stdout}

```

- Another way it track it in robot framework itself, create a [test teardown](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#toc-entry-274), declared in the ` ***Settings*** ` section the test teardown will run at the end of every test case. Inside the test teardown the [automatic variables](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#toc-entry-321) `${TEST STATUS}` and `${TEST NAME}` are available for you, so you can append the `${TEST NAME}` to a list if the `${TEST STATUS}` is FAIL.  
Then you can simply use a [suite teardown](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#toc-entry-291) to send the list of failed tests to the 3rd party logger.

- Yet another option, if the system you are sending to supports it, then send the Failed `${TEST NAME}` to the 3rd party logger individually in the [test teardown](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#toc-entry-274), this will make the coding much simpler, because it’s just an if statement in the test teardown;  
If `${TEST STATUS}` = FAIL then send `${TEST NAME}` to the 3rd party logger

Hopefully that gives you some ideas and options,

Dave.

---

<div class="post-metadata">

**Author:** ![OrrinGradwell](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/orringradwell/32/2387_2.png) [@OrrinGradwell](https://forum.robotframework.org/u/OrrinGradwell)\
**Post date:** [28 February 2023 07:40 UTC](https://forum.robotframework.org/t/list-all-failed-tests-as-final-execution-step/5366/3 "2023-02-28T07:40:32Z")

</div>

Thank you @Dave

I have become blind to what is in front of me after all the struggle.
