def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_output_config)
     if settings['Critical'] or settings['NonCritical']:
         LOGGER.warn("Command line options --critical and --noncritical have been "
                     "deprecated. Use --skiponfailure instead.")
     if settings['XUnitSkipNonCritical']:
         LOGGER.warn("Command line option --xunitskipnoncritical has been "
                     "deprecated and has no effect.")
     LOGGER.info('Settings:\n%s' % unic(settings))
     builder = TestSuiteBuilder(settings['SuiteNames'],
                                included_extensions=settings.extension,
                                rpa=settings.rpa,
                                allow_empty_suite=settings.run_empty_suite)
     suite = builder.build(*datasources)
     settings.rpa = suite.rpa
     if settings.pre_run_modifiers:
         suite.visit(ModelModifier(settings.pre_run_modifiers,
                                   settings.run_empty_suite, LOGGER))
     suite.configure(**settings.suite_config)
     with pyloggingconf.robot_handler_enabled(settings.log_level):
         old_max_error_lines = text.MAX_ERROR_LINES
         text.MAX_ERROR_LINES = settings.max_error_lines
         try:
             result = suite.run(settings)
         finally:
             text.MAX_ERROR_LINES = old_max_error_lines
         LOGGER.info("Tests execution ended. Statistics:\n%s"
                     % result.suite.stat_message)
         if settings.log or settings.report or settings.xunit:
             writer = ResultWriter(settings.output if settings.log
                                   else result)
             writer.write_results(settings.get_rebot_settings())
     return result.return_code
Esempio n. 2
0
 def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_output_config)
     LOGGER.info('Settings:\n%s' % unic(settings))
     if settings['WarnOnSkipped'] is not None:
         LOGGER.error("Option '--warnonskippedfiles is deprecated and "
                      "has no effect.")
     builder = TestSuiteBuilder(settings['SuiteNames'],
                                extension=settings.extension,
                                rpa=settings.rpa)
     suite = builder.build(*datasources)
     settings.rpa = builder.rpa
     suite.configure(**settings.suite_config)
     if settings.pre_run_modifiers:
         suite.visit(
             ModelModifier(settings.pre_run_modifiers,
                           settings.run_empty_suite, LOGGER))
     with pyloggingconf.robot_handler_enabled(settings.log_level):
         result = suite.run(settings)
         LOGGER.info("Tests execution ended. Statistics:\n%s" %
                     result.suite.stat_message)
         if settings.log or settings.report or settings.xunit:
             writer = ResultWriter(
                 settings.output if settings.log else result)
             writer.write_results(settings.get_rebot_settings())
     return result.return_code
Esempio n. 3
0
 def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_output_config)
     LOGGER.info('Settings:\n%s' % unic(settings))
     builder = TestSuiteBuilder(settings['SuiteNames'],
                                extension=settings.extension,
                                rpa=settings.rpa,
                                allow_empty_suite=settings.run_empty_suite)
     suite = builder.build(*datasources)
     settings.rpa = suite.rpa
     if settings.pre_run_modifiers:
         suite.visit(ModelModifier(settings.pre_run_modifiers,
                                   settings.run_empty_suite, LOGGER))
     suite.configure(**settings.suite_config)
     with pyloggingconf.robot_handler_enabled(settings.log_level):
         old_max_error_lines = text.MAX_ERROR_LINES
         text.MAX_ERROR_LINES = settings.max_error_lines
         try:
             result = suite.run(settings)
         finally:
             text.MAX_ERROR_LINES = old_max_error_lines
         LOGGER.info("Tests execution ended. Statistics:\n%s"
                     % result.suite.stat_message)
         if settings.log or settings.report or settings.xunit:
             writer = ResultWriter(settings.output if settings.log
                                   else result)
             writer.write_results(settings.get_rebot_settings())
     return result.return_code
Esempio n. 4
0
 def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_output_config)
     LOGGER.info('Settings:\n%s' % unic(settings))
     builder = TestSuiteBuilder(settings['SuiteNames'],
                                extension=settings.extension,
                                rpa=settings.rpa)
     suite = builder.build(*datasources)
     settings.rpa = builder.rpa
     suite.configure(**settings.suite_config)
     if settings.pre_run_modifiers:
         suite.visit(ModelModifier(settings.pre_run_modifiers,
                                   settings.run_empty_suite, LOGGER))
     with pyloggingconf.robot_handler_enabled(settings.log_level):
         old_max_error_lines = text.MAX_ERROR_LINES
         text.MAX_ERROR_LINES = settings.max_error_lines
         try:
             result = suite.run(settings)
         finally:
             text.MAX_ERROR_LINES = old_max_error_lines
         LOGGER.info("Tests execution ended. Statistics:\n%s"
                     % result.suite.stat_message)
         if settings.log or settings.report or settings.xunit:
             writer = ResultWriter(settings.output if settings.log
                                   else result)
             writer.write_results(settings.get_rebot_settings())
     return result.return_code
def generate_report(suite: TestSuite, outputdir: str):
    process_screenshots(outputdir)

    writer = ResultWriter(os.path.join(outputdir, "output.xml"))
    writer.write_results(
        log=os.path.join(outputdir, "log.html"),
        report=None,
        rpa=getattr(suite, "rpa", False),
    )

    with open(os.path.join(outputdir, "log.html"), "rb") as fp:
        log = fp.read()
        log = log.replace(b'"reportURL":"report.html"', b'"reportURL":null')

    html = """
        <button
          class="jp-mod-styled jp-mod-accept"
          onClick="{};event.preventDefault();event.stopPropagation();"
        >
            <i class="fa fa-file" aria-hidden="true"></i>
            Log
        </button>
        """.format(display_log(log, "log.html"))

    return {"text/html": html}
Esempio n. 6
0
 def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_logger_config)
     LOGGER.info('Settings:\n%s' % unicode(settings))
     suite = TestSuiteBuilder(settings['SuiteNames'],
                              settings['WarnOnSkipped'],
                              settings['RunEmptySuite']).build(*datasources)
     suite.configure(**settings.suite_config)
     result = suite.run(settings)
     LOGGER.info("Tests execution ended. Statistics:\n%s" %
                 result.suite.stat_message)
     if settings.log or settings.report or settings.xunit:
         writer = ResultWriter(settings.output if settings.log else result)
         writer.write_results(settings.get_rebot_settings())
     return result.return_code
Esempio n. 7
0
 def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_logger_config)
     LOGGER.info('Settings:\n%s' % unicode(settings))
     suite = TestSuiteBuilder(settings['SuiteNames'],
                              settings['WarnOnSkipped'],
                              settings['RunEmptySuite']).build(*datasources)
     suite.configure(**settings.suite_config)
     result = suite.run(settings)
     LOGGER.info("Tests execution ended. Statistics:\n%s"
                 % result.suite.stat_message)
     if settings.log or settings.report or settings.xunit:
         writer = ResultWriter(settings.output if settings.log else result)
         writer.write_results(settings.get_rebot_settings())
     return result.return_code
Esempio n. 8
0
 def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_output_config)
     LOGGER.info("Settings:\n%s" % unic(settings))
     suite = TestSuiteBuilder(settings["SuiteNames"], settings["WarnOnSkipped"]).build(*datasources)
     suite.configure(**settings.suite_config)
     if settings.pre_run_modifiers:
         suite.visit(ModelModifier(settings.pre_run_modifiers, settings.run_empty_suite, LOGGER))
     with pyloggingconf.robot_handler_enabled(settings.log_level):
         result = suite.run(settings)
         LOGGER.info("Tests execution ended. Statistics:\n%s" % result.suite.stat_message)
         if settings.log or settings.report or settings.xunit:
             writer = ResultWriter(settings.output if settings.log else result)
             writer.write_results(settings.get_rebot_settings())
     return result.return_code
Esempio n. 9
0
 def main(self, datasources, **options):
     settings = RebotSettings(options)
     LOGGER.register_console_logger(**settings.console_logger_config)
     LOGGER.disable_message_cache()
     rc = ResultWriter(*datasources).write_results(settings)
     if rc < 0:
         raise DataError('No outputs created.')
     return rc
Esempio n. 10
0
def executeScript(inputScript, scriptOptionalArgs, inputFile=None):
    global testcaseInfoList
    global testcaseInfo
    global yamlCont
    testcaseInfoList = []
    yamlCont = {}
    if inputFile != None:
        fil = open(inputFile, "r")
        yamlCont = yaml.load(fil)


#        inputFileType = re.search('(.*).yaml', inputFile).group(1)

    inputFileType = 'unknown'
    if inputFile != None:
        inputFileType = re.search('(.*).yaml', inputFile).group(1)
    cmd = "%s %s" % (inputScript, ' '.join(scriptOptionalArgs))
    #inputFileType = 'unknown'
    print "@@@@@@@@@@@@@@@"
    print cmd
    print "@@@@@@@@@@@@@@@"
    ps = winpexpect.winspawn(cmd)
    ps.logfile_read = sys.stdout

    ## Initialize testcaseInfo if the script is not a flist.
    if inputFileType in ['unknown']:
        scriptName = inputScript
        testcaseInfo = testInfo(scriptName)
        testcaseInfoList.append(testcaseInfo)

    timeout = -1
    ps.interact(output_filter=scriptExecutionMonitor)

    if inputFileType is 'unknown':
        ## creates a nested suite
        suiteList = []
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.flush()
            suite = createRobotSuite(testcaseInfo)
            suiteList.append(suite)
        suite = TestSuite(inputScript)
        suite.suites = suiteList
        result = suite.run(output='output.xml', loglevel='debug')
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.variableFile.close()
    else:
        ## creates a single suite
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.flush()
            print testcaseInfo
            suite = createRobotSuite(testcaseInfo)
            result = suite.run(output='output.xml', loglevel='debug')
            testcaseInfo.variableFile.close()

    # Generating log files requires processing the earlier generated output XML.
    ResultWriter('output.xml').write_results()
    pp = postProcess.postProcess(suiteFile=testcaseInfo.scriptName)
    pp.close()
Esempio n. 11
0
 def main(self, datasources, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(**settings.console_output_config)
     LOGGER.info('Settings:\n%s' % unicode(settings))
     suite = TestSuiteBuilder(settings['SuiteNames'],
                              settings['WarnOnSkipped']).build(*datasources)
     suite.configure(**settings.suite_config)
     if settings.pre_run_modifiers:
         suite.visit(ModelModifier(settings.pre_run_modifiers,
                                   settings.run_empty_suite, LOGGER))
     with pyloggingconf.robot_handler_enabled(settings.log_level):
         result = suite.run(settings)
         LOGGER.info("Tests execution ended. Statistics:\n%s"
                     % result.suite.stat_message)
         if settings.log or settings.report or settings.xunit:
             writer = ResultWriter(settings.output if settings.log
                                   else result)
             writer.write_results(settings.get_rebot_settings())
     return result.return_code
Esempio n. 12
0
    def save_intermediate_results(self):
        """Method creates intermediate robot result files during test execution

        :return:
        """
        xml_path, html_path, log_path = self.generate_output_file_names()
        execution_result = Result(root_suite=self.current_suite_result)
        ResultWriter(execution_result).write_results(
            output=xml_path, report=html_path, log=log_path
        )
Esempio n. 13
0
 def main(self, datasources, **options):
     settings = RebotSettings(options)
     LOGGER.register_console_logger(colors=settings['MonitorColors'],
                                    stdout=settings['StdOut'],
                                    stderr=settings['StdErr'])
     LOGGER.disable_message_cache()
     rc = ResultWriter(*datasources).write_results(settings)
     if rc < 0:
         raise DataError('No outputs created.')
     return rc
Esempio n. 14
0
 def _runTest(self, parsed, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(width=settings['MonitorWidth'],
                                    colors=settings['MonitorColors'],
                                    markers=settings['MonitorMarkers'],
                                    stdout=settings['StdOut'],
                                    stderr=settings['StdErr'])
     LOGGER.info('Settings:\n%s' % six.text_type(settings))
     suite = TestSuiteBuilder(
         settings['SuiteNames'], settings['WarnOnSkipped'],
         settings['RunEmptySuite'])._build_suite(parsed)
     suite.configure(**settings.suite_config)
     result = suite.run(settings)
     LOGGER.info("Tests execution ended. Statistics:\n%s" %
                 result.suite.statistics.message)
     rc = result.return_code
     if settings.log or settings.report or settings.xunit:
         writer = ResultWriter(settings.output if settings.log else result)
         writer.write_results(settings.get_rebot_settings())
     return rc
Esempio n. 15
0
    def overwrite_output_file(self):
        """ Method removes all dummy test results from output.xml file together with messages related with those tests
        It overwrites output.xml file generated by robot executor
        :return: None
        """
        result = ExecutionResult(self.output_file_path)
        result.suite.tests = [test for test in result.suite.tests if self.REMOVE_NAME.lower() not in test.name.lower()]

        ResultWriter(result).write_results(
            output=self.output_file_path, report=self.report_file_path, log=self.logger_file_path
        )
Esempio n. 16
0
 def main(self, datasources, **options):
     settings = RebotSettings(options)
     LOGGER.register_console_logger(**settings.console_output_config)
     if settings['XUnitSkipNonCritical']:
         LOGGER.warn(
             "Command line option --xunitskipnoncritical has been deprecated."
         )
     LOGGER.disable_message_cache()
     rc = ResultWriter(*datasources).write_results(settings)
     if rc < 0:
         raise DataError('No outputs created.')
     return rc
Esempio n. 17
0
 def _runTest(self, parsed, **options):
     settings = RobotSettings(options)
     LOGGER.register_console_logger(width=settings['MonitorWidth'],
                                    colors=settings['MonitorColors'],
                                    markers=settings['MonitorMarkers'],
                                    stdout=settings['StdOut'],
                                    stderr=settings['StdErr'])
     LOGGER.info('Settings:\n%s' % six.text_type(settings))
     suite = TestSuiteBuilder(
         settings['SuiteNames'],
         settings['WarnOnSkipped'],
         settings['RunEmptySuite'])._build_suite(parsed)
     suite.configure(**settings.suite_config)
     result = suite.run(settings)
     LOGGER.info("Tests execution ended. Statistics:\n%s"
                 % result.suite.statistics.message)
     rc = result.return_code
     if settings.log or settings.report or settings.xunit:
         writer = ResultWriter(settings.output if settings.log else result)
         writer.write_results(settings.get_rebot_settings())
     return rc
Esempio n. 18
0
 def main(self, datasources, **options):
     try:
         settings = RobotSettings(options)
     except:
         LOGGER.register_console_logger(stdout=options.get('stdout'),
                                        stderr=options.get('stderr'))
         raise
     LOGGER.register_console_logger(**settings.console_output_config)
     LOGGER.info(f'Settings:\n{settings}')
     if settings.pythonpath:
         sys.path = settings.pythonpath + sys.path
     builder = TestSuiteBuilder(settings.suite_names,
                                included_extensions=settings.extension,
                                rpa=settings.rpa,
                                lang=settings.languages,
                                allow_empty_suite=settings.run_empty_suite)
     suite = builder.build(*datasources)
     settings.rpa = suite.rpa
     if settings.pre_run_modifiers:
         suite.visit(
             ModelModifier(settings.pre_run_modifiers,
                           settings.run_empty_suite, LOGGER))
     suite.configure(**settings.suite_config)
     with pyloggingconf.robot_handler_enabled(settings.log_level):
         old_max_error_lines = text.MAX_ERROR_LINES
         old_max_assign_length = text.MAX_ASSIGN_LENGTH
         text.MAX_ERROR_LINES = settings.max_error_lines
         text.MAX_ASSIGN_LENGTH = settings.max_assign_length
         try:
             result = suite.run(settings)
         finally:
             text.MAX_ERROR_LINES = old_max_error_lines
             text.MAX_ASSIGN_LENGTH = old_max_assign_length
         LOGGER.info("Tests execution ended. Statistics:\n%s" %
                     result.suite.stat_message)
         if settings.log or settings.report or settings.xunit:
             writer = ResultWriter(
                 settings.output if settings.log else result)
             writer.write_results(settings.get_rebot_settings())
     return result.return_code
Esempio n. 19
0
def report_html(reporter):
    """ Generate report
    """
    path = reporter.runner.path

    output_path = path / "output.xml"
    log_path = path / "log.html"
    report_path = path / "report.html"
    writer = ResultWriter(str(output_path))
    writer.write_results(log=str(log_path), report=str(report_path))

    # Clear status and display results
    if not reporter.silent:
        reporter.runner.send_display_data({
            "text/html":
            ('<a href="{}">Log</a> | <a href="{}">Report</a>').format(
                util.javascript_uri(log_path.read_bytes().replace(
                    b'"reportURL":"report.html"', b'"reportURL":null')),
                util.javascript_uri(report_path.read_bytes().replace(
                    b'"logURL":"log.html"', b'"logURL":null')),
            )
        })
Esempio n. 20
0
 def main(self, datasources, **options):
     try:
         settings = RebotSettings(options)
     except:
         LOGGER.register_console_logger(stdout=options.get('stdout'),
                                        stderr=options.get('stderr'))
         raise
     LOGGER.register_console_logger(**settings.console_output_config)
     LOGGER.disable_message_cache()
     rc = ResultWriter(*datasources).write_results(settings)
     if rc < 0:
         raise DataError('No outputs created.')
     return rc
Esempio n. 21
0
 def _runTest(self, parsed, **options):
     settings = RobotSettings(options)
     output_config = getattr(settings, 'console_output_config', {
         'width': getattr(settings, 'console_width', 78),
         'colors': getattr(settings, 'console_colors', 'AUTO'),
         'markers': getattr(settings, 'console_markers', 'AUTO'),
         'stdout': settings['StdOut'],
         'stderr': settings['StdErr']
     })
     LOGGER.register_console_logger(**output_config)
     LOGGER.info('Settings:\n%s' % six.text_type(settings))
     suite = TestSuiteBuilder(
         settings['SuiteNames'],
         settings['WarnOnSkipped'])._build_suite(parsed)
     suite.configure(**settings.suite_config)
     result = suite.run(settings)
     LOGGER.info("Tests execution ended. Statistics:\n%s"
                 % result.suite.statistics.message)
     rc = result.return_code
     if settings.log or settings.report or settings.xunit:
         writer = ResultWriter(settings.output if settings.log else result)
         writer.write_results(settings.get_rebot_settings())
     return rc
Esempio n. 22
0
 def main(self, datasources, **options):
     settings = RebotSettings(options)
     LOGGER.register_console_logger(**settings.console_output_config)
     if settings['Critical'] or settings['NonCritical']:
         LOGGER.warn("Command line options --critical and --noncritical have been "
                     "deprecated and have no effect with Rebot. Use --skiponfailure "
                     "when starting execution instead.")
     if settings['XUnitSkipNonCritical']:
         LOGGER.warn("Command line option --xunitskipnoncritical has been "
                     "deprecated and has no effect.")
     LOGGER.disable_message_cache()
     rc = ResultWriter(*datasources).write_results(settings)
     if rc < 0:
         raise DataError('No outputs created.')
     return rc
Esempio n. 23
0
 def _runTest(self, parsed, **options):
     settings = RobotSettings(options)
     output_config = getattr(
         settings, 'console_output_config', {
             'width': getattr(settings, 'console_width', 78),
             'colors': getattr(settings, 'console_colors', 'AUTO'),
             'markers': getattr(settings, 'console_markers', 'AUTO'),
             'stdout': settings['StdOut'],
             'stderr': settings['StdErr']
         })
     LOGGER.register_console_logger(**output_config)
     LOGGER.info('Settings:\n%s' % six.text_type(settings))
     suite = TestSuiteBuilder(
         settings['SuiteNames'],
         settings['WarnOnSkipped'])._build_suite(parsed)
     suite.configure(**settings.suite_config)
     result = suite.run(settings)
     LOGGER.info("Tests execution ended. Statistics:\n%s" %
                 result.suite.statistics.message)
     rc = result.return_code
     if settings.log or settings.report or settings.xunit:
         writer = ResultWriter(settings.output if settings.log else result)
         writer.write_results(settings.get_rebot_settings())
     return rc
Esempio n. 24
0
 def main(self, datasources, **options):
     STOP_SIGNAL_MONITOR.start()
     namespace.IMPORTER.reset()
     settings = RobotSettings(options)
     pyloggingconf.initialize(settings['LogLevel'])
     LOGGER.register_console_logger(width=settings['MonitorWidth'],
                                    colors=settings['MonitorColors'],
                                    stdout=settings['StdOut'],
                                    stderr=settings['StdErr'])
     init_global_variables(settings)
     suite = TestSuite(datasources, settings)
     output = Output(settings)
     suite.run(output)
     LOGGER.info("Tests execution ended. Statistics:\n%s" %
                 suite.get_stat_message())
     output.close(suite)
     if settings.is_rebot_needed():
         output, settings = settings.get_rebot_datasource_and_settings()
         ResultWriter(output).write_results(settings)
     return suite.return_code
Esempio n. 25
0
def executeScript(inputScript, scriptOptionalArgs, inputFile=None):
    global testcaseInfoList
    global testcaseInfo
    global yamlCont
    testcaseInfoList = []
    yamlCont = {}
    if inputFile != None:
        fil = open(inputFile, "r")
        yamlCont = yaml.load(fil)
#        inputFileType = re.search('(.*).yaml', inputFile).group(1)

    if re.search("\.log\.", inputScript):
        cmd = "python /work/swtest01_1/sgsubramaniam/sw-test/special_script/demoScript/slowcat.py -d 0.002 %s" %inputScript
    else:
        cmd = "f10tool %s %s" %(inputScript, ' '.join(scriptOptionalArgs))
    if re.search("\.flist$", inputScript):
        inputFileType = 'flist'
        cmd = "f10tool %s %s" %(inputScript, ' '.join(scriptOptionalArgs))
    elif re.search("\.f10$", inputScript):
        inputFileType = 'f10'
        cmd = "f10tool %s %s" %(inputScript, ' '.join(scriptOptionalArgs))
    else:
        inputFileType = 'unknown'
        if inputFile != None:
            inputFileType = re.search('(.*).yaml', inputFile).group(1)
        cmd = "%s %s;echo '----------'" %(inputScript, ' '.join(scriptOptionalArgs))


    ps = winpexpect.winspawn(cmd)
    ps.logfile_read = sys.stdout

    ## Initialize testcaseInfo if the script is not a flist.
    if inputFileType in ['f10', 'unknown']:
        scriptName = inputScript
        testcaseInfo = testInfo(scriptName)
        testcaseInfoList.append(testcaseInfo)

    timeout = -1
    ps.interact(output_filter=scriptExecutionMonitor)

    if inputFileType is 'flist' or 'rspec':
        ## creates a nested suite
        suiteList = []
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.flush()
            suite = createRobotSuite(testcaseInfo)
            suiteList.append(suite)
        suite = TestSuite(inputScript)
        suite.suites = suiteList
        result = suite.run(output='output.xml', loglevel='debug')
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.variableFile.close()
    else:
        ## creates a single suite
        for testcaseInfo in testcaseInfoList:
            testcaseInfo.flush()
            print testcaseInfo
            suite = createRobotSuite(testcaseInfo)
            result = suite.run(output='output.xml', loglevel='debug')
            testcaseInfo.variableFile.close()

    # Generating log files requires processing the earlier generated output XML.
    ResultWriter('output.xml').write_results()
    pp = postProcess.postProcess(suiteFile=testcaseInfo.scriptName)
    pp.close()
Esempio n. 26
0
    def _run_robot_suite(self, suite, silent, path):
        listener = []
        display_id = str(uuid.uuid4())
        return_values = []

        def update_progress(progress_, status):
            progress_.append({'PASS': '******'}.get(status, 'F'))
            return progress_

        # Init status
        if not silent:
            self.send_display_data({'text/plain': '.'}, display_id=display_id)
            listener.append(
                StatusEventListener(lambda s: self.send_update_display_data(
                    {'text/plain': ''.join(update_progress(progress, s))},
                    display_id=display_id)))
            listener.append(
                ReturnValueListener(lambda v: return_values.append(v)))

        # Run suite
        stdout = StringIO()
        progress = []
        results = suite.run(outputdir=path, stdout=stdout, listener=listener)
        stats = results.statistics

        # Reply error on error
        if stats.total.critical.failed:
            if not silent:
                self.send_error({
                    'ename': '',
                    'evalue': '',
                    'traceback': stdout.getvalue().splitlines(),
                })

        # Display result of the last keyword, if it was JSON
        elif return_values and return_values[-1] and not silent:
            try:
                result = json.dumps(json.loads(return_values[-1].strip()),
                                    sort_keys=False,
                                    indent=4)
                self.send_execute_result({
                    'text/html':
                    '<pre>{}</pre>'.format(highlight('json', result))
                })
            except (AttributeError, ValueError):
                pass

        # Process screenshots
        self.process_screenshots(path, silent)

        # Generate report
        writer = ResultWriter(os.path.join(path, 'output.xml'))
        writer.write_results(log=os.path.join(path, 'log.html'),
                             report=os.path.join(path, 'report.html'))

        with open(os.path.join(path, 'log.html'), 'rb') as fp:
            log = fp.read()
            log = log.replace(b'"reportURL":"report.html"',
                              b'"reportURL":null')

        with open(os.path.join(path, 'report.html'), 'rb') as fp:
            report = fp.read()
            report = report.replace(b'"logURL":"log.html"', b'"logURL":null')

        # Clear status and display results
        if not silent:
            self.send_update_display_data(
                {
                    'text/html':
                    '<a href="{}">Log</a> | <a href="{}">Report</a>'.format(
                        javascript_uri(log), javascript_uri(report))
                },
                display_id=display_id)

        # Reply ok on pass
        if stats.total.critical.failed:
            return {
                'status': 'error',
                'ename': '',
                'evalue': '',
                'traceback': stdout.getvalue().splitlines(),
            }
        else:
            return {
                'status': 'ok',
                'execution_count': self.execution_count,
            }
Esempio n. 27
0
 def writer(self):
     """Return a :class:`robot.reporting.ResultWriter` interface
        for the wrapped test run result,
        which can generate output/log/report data.
     """
     return ResultWriter(self.robot_result)
Esempio n. 28
0
def run_robot_suite(
    kernel: DisplayKernel,
    suite: TestSuite,
    listeners: list,
    silent: bool,
    display_id: str,
    path: str,
    widget: bool = False,
):
    return_values = []
    if not (silent or widget):
        progress = ProgressUpdater(kernel, display_id, sys.__stdout__)
    else:
        progress = None

    # Init status
    listeners = listeners[:]
    if not (silent or widget):
        listeners.append(StatusEventListener(lambda data: progress.update(data)))
    if not silent:
        listeners.append(ReturnValueListener(lambda v: return_values.append(v)))

    stdout = StringIO()
    if progress is not None:
        sys.__stdout__ = progress
    try:
        results = suite.run(outputdir=path, stdout=stdout, listener=listeners)
    finally:
        if progress is not None:
            sys.__stdout__ = progress.stdout

    stats = results.statistics

    # Reply error on error
    if stats.total.critical.failed:
        if not silent:
            kernel.send_error(
                {"ename": "", "evalue": "", "traceback": stdout.getvalue().splitlines()}
            )

    # Display result of the last keyword
    elif (
        len(return_values)
        and return_values[-1] is not None
        and return_values[-1] != ""
        and return_values[-1] != b""
        and not silent
    ):  # this comparison is "numpy compatible"
        bundle, metadata = to_mime_and_metadata(return_values[-1])
        if bundle:
            kernel.send_execute_result(bundle, metadata)

    # Process screenshots
    process_screenshots(kernel, path, silent)

    # Generate report
    writer = ResultWriter(os.path.join(path, "output.xml"))
    writer.write_results(
        log=os.path.join(path, "log.html"),
        report=os.path.join(path, "report.html"),
        rpa=getattr(suite, "rpa", False),
    )

    with open(os.path.join(path, "log.html"), "rb") as fp:
        log = fp.read()
        log = log.replace(b'"reportURL":"report.html"', b'"reportURL":null')

    with open(os.path.join(path, "report.html"), "rb") as fp:
        report = fp.read()
        report = report.replace(b'"logURL":"log.html"', b'"logURL":null')

    # Clear status and display results
    if not silent:
        (widget and kernel.send_display_data or kernel.send_update_display_data)(
            {
                "text/html": ""
                '<p><a href="about:" onClick="{}">Log</a> | <a href="about:" onClick="{}">Report</a></p>'.format(
                    javascript_uri(log, "log.html"),
                    javascript_uri(report, "report.html"),
                )
            },
            display_id=display_id,
        )

    # Reply ok on pass
    if stats.total.critical.failed:
        return {
            "status": "error",
            "ename": "",
            "evalue": "",
            "traceback": stdout.getvalue().splitlines(),
        }
    else:
        return {"status": "ok", "execution_count": kernel.execution_count}