Antman
Antman

Reputation: 493

How to detect when Robot Framework test case failed during a particular Test Setup keyword

The problem

I am currently running Robot Framework test cases with a target HW. During the Test Setup, I am flashing the software under test (firmware) to the target device. Due to several reasons, the flashing of the firmware fails sometimes, which causes the whole test case to fail. This is currently preventing me from getting any further meaningful results.

What I want to achieve

I want to detect when the test case fails in a particular Robot keyword during Test Setup. If a test case fails during a particular Test Setup keyword, I will retry/rerun the test case with a different target HW (I have my own Python script that executes the Robot runner with a given target device).

The main problem is that I don't know how to detect when a test case failed in a Test Setup keyword.

What I tried so far

My first guess was that this could be achieved by parsing the output.xml file, but I couldn't extract this information from there.

I have already considered retrying the flashing operation in Test Setup, but this won't work for me. The test case needs to be restarted from scratch (running in a different target HW).

Lastly, using "Run Keyword And Ignore Error" is not a solution neither since Test Setup must be run successfully in order to continue the test case.

Upvotes: 2

Views: 1011

Answers (1)

Antman
Antman

Reputation: 493

The best solution I found so far: how to list all keywords used by a robotframework test suite

from robot.api import ExecutionResult, ResultVisitor

result = ExecutionResult('output.xml')
class MyVisitor(ResultVisitor):
    def visit_keyword(self, kw):
        print("Keyword Name: " + str(kw.name))
        print("Keyword Status: " + str(kw.status))
       
result.visit(MyVisitor())

Output:

Keyword Name: MyKeywords.My Test Setup
Keyword Status: FAIL

Upvotes: 1

Related Questions