from __future__ import division
-import errno
import logging
import os
+from io import StringIO
import robot.api
from robot.errors import RobotError
+from robot.reporting import resultwriter
import robot.run
from robot.utils.robottime import timestamp_to_secs
-from six import StringIO
from xtesting.core import testcase
"""RobotFramework runner."""
__logger = logging.getLogger(__name__)
- dir_results = "/var/lib/xtesting/results"
def __init__(self, **kwargs):
- self.res_dir = os.path.join(self.dir_results, 'robot')
- self.xml_file = os.path.join(self.res_dir, 'output.xml')
super(RobotFramework, self).__init__(**kwargs)
+ self.xml_file = os.path.join(self.res_dir, 'output.xml')
def parse_results(self):
"""Parse output.xml and get the details in it."""
self.details['description'] = result.suite.name
self.details['tests'] = visitor.get_data()
+ def generate_report(self):
+ """Generate html and xunit outputs"""
+ result = robot.api.ExecutionResult(self.xml_file)
+ writer = resultwriter.ResultWriter(result)
+ return writer.write_results(
+ report='{}/report.html'.format(self.res_dir),
+ log='{}/log.html'.format(self.res_dir),
+ xunit='{}/xunit.xml'.format(self.res_dir))
+
def run(self, **kwargs):
"""Run the RobotFramework suites
except KeyError:
self.__logger.exception("Mandatory args were not passed")
return self.EX_RUN_ERROR
- try:
- os.makedirs(self.res_dir)
- except OSError as ex:
- if ex.errno != errno.EEXIST:
+ if not os.path.exists(self.res_dir):
+ try:
+ os.makedirs(self.res_dir)
+ except Exception: # pylint: disable=broad-except
self.__logger.exception("Cannot create %s", self.res_dir)
return self.EX_RUN_ERROR
- except Exception: # pylint: disable=broad-except
- self.__logger.exception("Cannot create %s", self.res_dir)
- return self.EX_RUN_ERROR
stream = StringIO()
robot.run(*suites, variable=variable, variablefile=variablefile,
include=include, output=self.xml_file, log='NONE',
report='NONE', stdout=stream)
- self.__logger.info("\n" + stream.getvalue())
- self.__logger.info("Results were successfully generated")
+ self.__logger.info("\n%s", stream.getvalue())
try:
self.parse_results()
self.__logger.info("Results were successfully parsed")
+ self.generate_report()
+ self.__logger.info("Results were successfully generated")
except RobotError as ex:
self.__logger.error("Run suites before publishing: %s", ex.message)
return self.EX_RUN_ERROR