0

I have a test suite directory which contains test suite files with one or more test cases. Let's say it looks like this:

TestSuite
  Test-1
    Step 1
    Step 2
  Test-2
    Step 1
  Test-3
    Step 1
    Step 2
    Step 3

I would like to parse output.xml to get results like this:

Test-1 | PASS
Test-1 | Step 1 | PASS
Test-1 | Step 2 | PASS
Test-2 | PASS
Test-2 | Step 1 | PASS
Test-3 | PASS
Test-3 | Step 1 | PASS
Test-3 | Step 2 | PASS
Test-3 | Step 3 | PASS

So far I have managed to get only suite files names and results using this code:

from robot.api import ExecutionResult, SuiteVisitor

class PrintSuiteInfo(SuiteVisitor):

    def visit_suite(self, suite):
        print('{} | {}'.format(suite.name, suite.status))

result = ExecutionResult('output.xml')
result.suite.suites.visit(PrintSuiteInfo())

which gives this output:

Test-1 | PASS
Test-2 | PASS
Test-3 | PASS

I can get test case names and results with this code:

from robot.api import ExecutionResult, ResultVisitor

class PrintTestInfo(ResultVisitor):

    def visit_test(self, test):
        print('{} | {}'.format(test.name, test.status))

result = ExecutionResult('output.xml')
result.visit(PrintTestInfo())

but the output is:

Step 1 | PASS
Step 2 | PASS
Step 1 | PASS
Step 1 | PASS
Step 2 | PASS
Step 3 | PASS

so there is no relation to suite files which I need to update results in Jira.

The only thing that came to my mind is to include the suite file name in each test case name but I would like to learn more about robot.api. I looked into the documentation many times but it is not clear enough for me now.

1 Answer 1

1

One of my colleagues helped me with solving this. What I was missing was:

test.parent

or one that I figured out myself:

test.longname

which gives output like this:

TestSuite.Test-1.Step 1
TestSuite.Test-1.Step 2
...

It is documented here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.