Hello, we start pytest in a robot file. Is there a way to merge the pytest report files with RF report files?
Or a way to pass the results to RF?
Now it just shows if all tests are passed or failed but you can’t see the single pytest testcases separately.
The same question about jest.
It may be possible, I just haven’t figured it out yet.
Robot framework has a Python API and you can run keyword that are written in python.
If we create a keyword called something like Log Test Result or Create Test Result that takes arguments like test case name and result as well as optional arguments like execution time, tags, etc.
Then it would be a simple matter of parsing the results from the external test, in your case pytest but for someone else it might be something else, and for each test result we could call this keyword to add a test result to the report.
Hopefully someone can chime in with how to use python to add the test result, I think it’ll be related to the TestSuite class but I haven’t figured out how to call this class to get the current test.
Note: that article was for RobotFramework before version 4, so I need to tweak it a bit to get it to work, this should hopefully give you enough to build a solution for yourself.
[exeres.py]
from robot.running.model import TestSuite
# @library
class exeres(object):
ROBOT_LISTENER_API_VERSION = 3
ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
def __init__(self):
self.ROBOT_LIBRARY_LISTENER = self
self.current_suite = None
def _start_suite(self, suite, result):
# save current suite so that we can modify it later
self.current_suite = suite
# @keyword
def log_test_result(self, testname, testresult="PASS"):
print("testname:", testname, " testresult:", testresult)
tc = self.current_suite.tests.create(name=testname)
kwname = "Pass Execution"
if testresult == "FAIL":
kwname = "Fail"
args = [testname]
tc.body.create_keyword(name=kwname, args=args)
[exeres.robot]
*** Settings ***
Library exeres.py
*** Test Cases ***
Execution Result Example
Log Test Result Test Name 1 PASS
Log Test Result Test Name 2 FAIL
My result:
% robot exeres.robot
==============================================================================
Exeres
==============================================================================
Execution Result Example | PASS |
------------------------------------------------------------------------------
Test Name 1 | PASS |
Test Name 1
------------------------------------------------------------------------------
Test Name 2 | FAIL |
Test Name 2
------------------------------------------------------------------------------
Exeres | FAIL |
3 tests, 2 passed, 1 failed
==============================================================================
Output: /Users/dave/tmp/output.xml
Log: /Users/dave/tmp/log.html
Report: /Users/dave/tmp/report.html
That’s a good question
We’re actually running them parallel or one after the other when we’re running the test automated after each build but locally for laziness reasons we start pytest in RF