コード例 #1
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
コード例 #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))
     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
コード例 #3
0
 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
コード例 #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))
     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
コード例 #5
0
    def __init__(self, name, BuiltIn=True, variable_getters=None):
        """Initialize with a `name`
           and optional additional variable lookup functions.

        - If a Variable is not found in the Robot's Variables dictionary,
          the `variable_getters` will be called in the given order
          with the Variable string in Robot syntax ($/@{...})
          until no `LookupError` or `DataError` is raised.
          (Used by the `robot_shell` to extend Variables lookup
           to IPython's `user_ns` and Python's `builtins`).

        :param BuiltIn: Import RFW's BuiltIn Library by default?
        :param variable_getters: A sequence of callables.
        """
        self.name = name
        self.debug = False
        try:
            GLOBAL_VARIABLES
        except NameError:
            # Robot 2.9+
            self._variables = VariableScopes(RobotSettings())
        else:
            # Robot 2.8
            if not GLOBAL_VARIABLES: # HACK
                init_global_variables(RobotSettings())
            self._variables = GLOBAL_VARIABLES.copy()
        # HACK even more to extend variable lookup
        self._variables.__class__ = variablesclass(
            self._variables.__class__, extra_getters=variable_getters)

        self._output = Output()
        self._context = Context(testrobot=self)
        self._suite = TestSuite(name)

        argspec = getargspec(Namespace.__init__)
        namespace = partial(
            Namespace, suite=self._suite, variables=self._variables)
        if 'resource' in argspec.args:
            # Robot 3.0
            self._namespace = namespace(resource=self._suite.resource)
        else:
            namespace.keywords.update(user_keywords=[], imports=None)
            if 'parent_variables' in argspec.args:
                # Robot 2.8
                self._namespace = namespace(parent_variables=None)
            else:
                # Robot 2.9
                self._namespace = namespace()

        if BuiltIn:
            self.Import('BuiltIn')
コード例 #6
0
ファイル: run.py プロジェクト: yaogao000/robotframework
 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
コード例 #7
0
ファイル: run.py プロジェクト: nurruden/robotframework
 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
コード例 #8
0
ファイル: run.py プロジェクト: urska19/Plone-test
 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
コード例 #9
0
def TestSuiteFactory(datasources, **options):
    settings = RobotSettings(options)
    if isinstance(datasources, basestring):
        datasources = [datasources]
    suite = TestSuiteBuilder().build(*datasources)
    suite.configure(**settings.suite_config)
    return suite
コード例 #10
0
def TestSuiteFactory(datasources, **options):
    settings = RobotSettings(options)
    if is_string(datasources):
        datasources = [datasources]
    suite = TestSuiteBuilder(process_curdir=False).build(*datasources)
    suite.configure(**settings.suite_config)
    return suite
コード例 #11
0
 def __init__(self, lib_import_timeout=60):
     robot.running.namespace.IMPORTER = MyIMPORTER(
         robot.running.namespace.IMPORTER, lib_import_timeout)
     self.options, self.arguments = RobotFramework().parse_arguments(
         sys.argv[1:])
     self.settings = RobotSettings(**self.options)
     self.f_suites = self.settings.suite_config['include_suites']
コード例 #12
0
def TestSuiteFactory(datasources, **options):
    if isinstance(datasources, basestring):
        datasources = [datasources]
    populators.PROCESS_CURDIR = False
    try:
        return TestSuite(datasources, RobotSettings(options))
    finally:
        populators.PROCESS_CURDIR = True
コード例 #13
0
ファイル: run.py プロジェクト: IlfirinPL/RIDE
 def main(self, datasources, **options):
     STOP_SIGNAL_MONITOR.start()
     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
コード例 #14
0
def robot_run(suite, options):

    from robot.api import ResultWriter
    from robot.conf import RobotSettings
    settings = RobotSettings(options)
    suite.configure(**settings.suite_config)
    result = suite.run(settings, critical='smoke')

    ResultWriter(settings.output if settings.log else result).write_results(
        report=settings.report, log=settings.log)
コード例 #15
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
コード例 #16
0
ファイル: run.py プロジェクト: quangdt/plan_come_on_baby
 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
コード例 #17
0
ファイル: __init__.py プロジェクト: urska19/Plone_site
 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
コード例 #18
0
ファイル: __init__.py プロジェクト: datakurre/robotsuite
 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
コード例 #19
0
ファイル: run.py プロジェクト: oboehmer/robotframework
 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
コード例 #20
0
 def Run(self, path, **options):
     debug = options.pop('debug', self.debug)
     # post processed options
     settings = RobotSettings(**options)
     builder = TestSuiteBuilder()
     suite = builder.build(path)
     with self._context:
         runner = Runner(self._output, settings)
         suite.visit(runner)
         result = runner.result
         if debug and result.return_code:
             reraise(*self._output._last_fail_exc)
         return TestResult(runner.result, **options)
コード例 #21
0
 def get_suite_testcases(self, test_suite_path):
     """
     parse test case name from robot test suite
     :param test_suite_path:
     :return: test names list
     """
     settings = RobotSettings()
     builder = TestSuiteBuilder(settings['SuiteNames'],
                                settings['RunEmptySuite'])
     data = builder._parse(test_suite_path)
     tests = [test.name for test in data.testcase_table.tests]
     print('\n'.join(tests))
     return tests
コード例 #22
0
ファイル: robpy.py プロジェクト: mkorpela/robpy
def runner(datasources, **options):
    tests = _tests(datasources)
    settings = RobotSettings(options)
    rf_test_to_actual, suite = _build_rf_suite(datasources, settings, tests)
    LOGGER.register_console_logger(**settings.console_output_config)
    with pyloggingconf.robot_handler_enabled(settings.log_level):
        with STOP_SIGNAL_MONITOR:
            IMPORTER.reset()
            output = Output(settings)
            runner = JudasRunner(rf_test_to_actual, output, settings)
            suite.visit(runner)
        output.close(runner.result)
    return runner.result
コード例 #23
0
ファイル: __init__.py プロジェクト: collective/robotsuite
 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
コード例 #24
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
コード例 #25
0
ファイル: run.py プロジェクト: AlldreenDev/RobotFramework-OSS
class RobotFramework(Application):

    def __init__(self):
        self.logger1 = new_logger_for_thread()
        Application.__init__(self, USAGE, arg_limits=(1,),
                             env_options='ROBOT_OPTIONS', logger=self.logger1)
        self.settings = None
        self.suite = None
        self.builder = None

    def main(self, datasources, **options):
        self.settings = RobotSettings(options)
        self.logger1.register_console_logger(**self.settings.console_output_config)
        self.logger1.info('Settings:\n%s' % unic(self.settings))
        self.builder = TestSuiteBuilder(self.settings['SuiteNames'],
                                   included_extensions=self.settings.extension,
                                   rpa=self.settings.rpa,
                                   allow_empty_suite=self.settings.run_empty_suite)
        self.suite = self.builder.build(*datasources)
        self.settings.rpa = self.suite.rpa
        if self.settings.pre_run_modifiers:
            self.suite.visit(ModelModifier(self.settings.pre_run_modifiers,
                                      self.settings.run_empty_suite, self.logger1))
        self.suite.configure(**self.settings.suite_config)
        with pyloggingconf.robot_handler_enabled(self.settings.log_level):
            old_max_error_lines = text.MAX_ERROR_LINES
            text.MAX_ERROR_LINES = self.settings.max_error_lines
            try:
                result = self.suite.run(self.settings)
            finally:
                text.MAX_ERROR_LINES = old_max_error_lines
            self.logger1.info("Tests execution ended. Statistics:\n%s"
                        % result.suite.stat_message)
            if self.settings.log or self.settings.report or self.settings.xunit:
                writer = ResultWriter(self.settings.output if self.settings.log
                                      else result)
                writer.write_results(self.settings.get_rebot_settings())
        return result.return_code

    def validate(self, options, arguments):
        return self._filter_options_without_value(options), arguments

    def _filter_options_without_value(self, options):
        return dict((name, value) for name, value in options.items()
                    if value not in (None, []))
コード例 #26
0
 def main(self, data_sources, **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'],
                              settings['Extension']).build(*data_sources)
     suite.configure(**settings.suite_config)
     self._support_python_path(options)
     self._split_tests(suite)  # 递归,找到所有的tests, 写入self.long_names
     self._assert_data_source(
         data_sources)  # 只取第一个DataSource, 写入self.data_source
     self._assert_test_count()  # 如果没有要测试的, 直接退出, 返回码: 1
     self.output_dir = settings['OutputDir']
     self.clean_output_dir()  # 删掉主要输出目录下所有东东, 类似rm -rf self.output_dir
     self.log_debug_info(options)
     p_num = (int(options['processes']) if 'processes' in options else 2 *
              cpu_count())
     start_time, end_time = self.parallel_run(options, p_num)
     self.merge_report(start_time, end_time)
コード例 #27
0
    def main(self, datasources, **options):
        for key, value in options.items():
            if not value:
                options.pop(key)
        settings = RobotSettings(options)
        LOGGER.register_console_logger(**settings.console_output_config)
        LOGGER.info('Settings:\n%s' % unic(settings))
        suite = TestSuiteBuilder(settings['SuiteNames'],
                                 settings['WarnOnSkipped'],
                                 settings['Extension']).build(*datasources)
        suite.configure(**settings.suite_config)

        data_sources = '"' + '" "'.join(datasources) + '"'

        logFolder = settings['OutputDir']
        if options.has_key('processes'):
            p_num = int(options['processes'])
        else:
            p_num = 2 * cpu_count()  #默认两倍cpu核数

        longname = []
        testnames = self._split_tests(suite, longname)  #递归,找到所有的tests

        extra_options_cmd = self.unresolve_options(options)

        #运行前先清理环境,主要是把一些Output文件和图片文件清除
        self.clear_env(logFolder)

        #生成并行运行命令并运行
        self.parallel_run(testnames, logFolder, data_sources,
                          extra_options_cmd, p_num)

        #合并报告
        rebotCommand = 'rebot --outputdir "' + logFolder + '" --merge "' + logFolder + '/*_Output.xml"'
        print(rebotCommand)
        merge_proc = subprocess.Popen(rebotCommand, shell=True)
        merge_proc.communicate()
コード例 #28
0
ファイル: model.py プロジェクト: zoeltea/robotframework
    def run(self, settings=None, **options):
        """Executes the suite based based the given ``settings`` or ``options``.

        :param settings: :class:`~robot.conf.settings.RobotSettings` object
            to configure test execution.
        :param options: Used to construct new
            :class:`~robot.conf.settings.RobotSettings` object if ``settings``
            are not given.
        :return: :class:`~robot.result.executionresult.Result` object with
            information about executed suites and tests.

        If ``options`` are used, their names are the same as long command line
        options except without hyphens. Some options are ignored (see below),
        but otherwise they have the same semantics as on the command line.
        Options that can be given on the command line multiple times can be
        passed as lists like ``variable=['VAR1:value1', 'VAR2:value2']``.
        If such an option is used only once, it can be given also as a single
        string like ``variable='VAR:value'``.

        Additionally listener option allows passing object directly instead of
        listener name, e.g. ``run('tests.robot', listener=Listener())``.

        To capture stdout and/or stderr streams, pass open file objects in as
        special keyword arguments ``stdout`` and ``stderr``, respectively.

        Only options related to the actual test execution have an effect.
        For example, options related to selecting or modifying test cases or
        suites (e.g. ``--include``, ``--name``, ``--prerunmodifier``) or
        creating logs and reports are silently ignored. The output XML
        generated as part of the execution can be configured, though. This
        includes disabling it with ``output=None``.

        Example::

            stdout = StringIO()
            result = suite.run(variable='EXAMPLE:value',
                               critical='regression',
                               output='example.xml',
                               exitonfailure=True,
                               stdout=stdout)
            print result.return_code

        To save memory, the returned
        :class:`~robot.result.executionresult.Result` object does not
        have any information about the executed keywords. If that information
        is needed, the created output XML file needs to be read  using the
        :class:`~robot.result.resultbuilder.ExecutionResult` factory method.

        See the :mod:`package level <robot.running>` documentation for
        more examples, including how to construct executable test suites and
        how to create logs and reports based on the execution results.

        See the :func:`robot.run <robot.run.run>` function for a higher-level
        API for executing tests in files or directories.
        """
        from .namespace import IMPORTER
        from .signalhandler import STOP_SIGNAL_MONITOR
        from .runner import Runner

        with LOGGER:
            if not settings:
                settings = RobotSettings(options)
                LOGGER.register_console_logger(
                    **settings.console_output_config)
            with pyloggingconf.robot_handler_enabled(settings.log_level):
                with STOP_SIGNAL_MONITOR:
                    IMPORTER.reset()
                    output = Output(settings)
                    runner = Runner(output, settings)
                    self.visit(runner)
                output.close(runner.result)
        return runner.result
コード例 #29
0
from config import Config
from robot.conf import RobotSettings
from time import sleep

import logging
import sys
import docker
from robot import run
from robot.running import TestSuite

cfg = Config()
settings = RobotSettings()
logging.basicConfig(stream=sys.stderr, level=logging.INFO)


class ClusteringTests(object):

    def __init__(self):
        logging.info('Init docker client')
        self.docker_client = \
            docker.Client(base_url='unix://var/run/docker.sock',
                          version='1.9', timeout=10)
        logging.info('Get list of containers')
        self.containers = self.docker_client.containers()

    def test_general_cluster_functionality(self):
        logging.info('Start general test')

        suites = cfg.suites
        suites = map(
            lambda x: unicode('/'.join([cfg.test_repo_path, cfg.suites_path, x])), suites)
 def wrapper(*args, **kwargs):
     timeout_msg = func.__name__ + " timed out !!"
     timeout = KeywordTimeout(timeoutinseconds, timeout_msg,
                              VariableScopes(RobotSettings()))
     timeout.start()
     return timeout.run(func, args, kwargs)
コード例 #31
0
create_case_step(suite, suite_steps)

for case in testcases:
    test_case_name = case.get('name')
    tags = case.get('tags')
    steps = case.get('steps')
    assertions = case.get('assertions')

    # test = suite.tests.create(test_case_name, tags=tags)
    test = suite.tests.create(test_case_name, tags=tags)
    # test.keywords.create('test_builtin_keyword')
    create_case_step(test, steps)
    create_assertion_step(test, assertions)

path = "reports"
apiname = 'skynet'
options = {
    "output": "{}-output.xml".format(apiname),
    "log": "{}-log.html".format(apiname),
    "report": "{}-reporter.html".format(apiname),
    "outputdir": path,
    # "include": ['CI']
    # "exclude": ['SMOKE']
}
settings = RobotSettings(options)
suite.configure(**settings.suite_config)
result = suite.run(settings, critical='smoke')

ResultWriter(settings.output if settings.log else result).write_results(
    report=settings.report, log=settings.log)
コード例 #32
0
 def run(self, *tests, **options):
     debug = False
     app = Application(USAGE)
     dict_all_options, arguments = app._parse_arguments(*tests)
     # something weird is happening, from here _parse_arguments returns a dict with all
     # options (but with value None or []), while in robot it only gives the options that
     # are in the sys.argv. adding arg_limits, env_options and logger doesn't make a difference
     # workaround: build a new dict without the empty options
     dict_options = dict()
     list_included_test = []
     for option in dict_all_options:
         if dict_all_options[option] is not None:
             dict_options[option] = dict_all_options[option]
     settings = RobotSettings(dict_options)
     if debug is True:
         print(settings)
     suite = TestSuiteBuilder().build(arguments[0])
     if len(suite.suites) == 0:
         testsuites = [suite]
     else:
         testsuites = suite.suites
     for testsuite in testsuites:
         testsuite.filter(included_tests=dict_options['test'])
     suite.remove_empty_suites()
     for testsuite in testsuites:
         for test in testsuite.tests:
             tuple_tags = ()
             test_name = test.name
             for kw in test.keywords:
                 if kw.name.lower() == 'data tags':
                     tuple_tags = kw.args
             iterator = 1
             if len(tuple_tags) > 1:
                 new_test = robot.running.model.TestCase.deepcopy(test)
                 if "{ROLE}" in test.name:
                     test.name = test_name.replace("{ROLE}", tuple_tags[0])
                 else:
                     test.name = test_name + ' (' + tuple_tags[0] + ')'
                 for tag in tuple_tags[1:]:
                     if "{ROLE}" in test_name:
                         new_test.name = test_name.replace("{ROLE}", tag)
                     else:
                         new_test.name = test_name + ' (' + tag + ')'
                     for kw in new_test.keywords:
                         if kw.name.lower() == 'data tags':
                             kw.args = kw.args[1:]
                         if kw.name.lower() == 'data row':
                             kw.args = kw.args[1:]
                     testsuite.tests.insert(
                         testsuite.tests.index(test) + iterator, new_test)
                     iterator += 1
                     new_test = robot.running.model.TestCase.deepcopy(
                         new_test)
         # because we keep copying copies, we could not add tags and could not set the data row args to a single value
         # so we need to add the tags and set the data rg ow args to a single value in another loop
         for test in testsuite.tests:
             for kw in test.keywords:
                 if kw.name.lower() == 'data tags':
                     test.tags.add(kw.args[0])
                     kw.args = (kw.args[0], )
                 if kw.name.lower() == 'data row':
                     if len(kw.args) > 0:
                         kw.args = (kw.args[0], )
         if debug is True:
             print("\n\nTestsuite:", testsuite)
             print("------------------------")
             print("All tests in this testsuite:", testsuite.tests, "\n")
             print("Tests:", settings['TestNames'], "\n")
             print("Include tag:", dict_options['include'], "\n")
             print("Exclude tag:", dict_options['exclude'], "\n")
             print("Tests before filtering:", testsuite.tests, "\n")
         if len(settings['ReRunFailed']) > 0:
             # Only run the tests that are needed to be re-executed.
             testsuite.filter(included_tests=settings['ReRunFailed'])
         else:
             # 'normal' filtering
             # apply the -e and -i arguments by using a filter
             testsuite.filter(included_tags=dict_options['include'])
             testsuite.filter(excluded_tags=dict_options['exclude'])
         if debug is True:
             print("Tests after filtering:", testsuite.tests, "\n\n\n")
     suite.remove_empty_suites()
     # if suite.test_count == 0:
     results = suite.run(settings)
     # this only creates the output.xml, so we have to rebot to generate the htmls
     try:
         robot.rebot(settings['Output'],
                     outputdir=settings['OutputDir'],
                     log=settings['Log'],
                     report=settings['Report'])
     except:
         rebot(settings['Output'],
               outputdir=settings['OutputDir'],
               log=settings['Log'],
               report=settings['Report'])
     if results.return_code != 0:
         sys.exit(1)
     else:
         sys.exit(0)
コード例 #33
0
    def run(self, settings=None, **options):
        """Executes the suite based based the given ``settings`` or ``options``.

        :param settings: :class:`~robot.conf.settings.RobotSettings` object
            to configure test execution.
        :param options: Used to construct new
            :class:`~robot.conf.settings.RobotSettings` object if ``settings``
            are not given.
        :return: :class:`~robot.result.executionresult.Result` object with
            information about executed suites and tests.

        If ``options`` are used, their names are the same as long command line
        options except without hyphens, and they also have the same semantics.
        Options that can be given on the command line multiple times can be
        passed as lists like ``variable=['VAR1:value1', 'VAR2:value2']``.
        If such an option is used only once, it can be given also as a single
        string like ``variable='VAR:value'``.

        To capture stdout and/or stderr streams, pass open file objects in as
        special keyword arguments `stdout` and `stderr`, respectively. Note
        that this works only in version 2.8.4 and newer.

        Only options related to the actual test execution have an effect.
        For example, options related to selecting test cases or creating
        logs and reports are silently ignored. The output XML generated
        as part of the execution can be configured, though. This includes
        disabling it with ``output=None``.

        Example::

            stdout = StringIO()
            result = suite.run(variable='EXAMPLE:value',
                               critical='regression',
                               output='example.xml',
                               exitonfailure=True,
                               stdout=stdout)
            print result.return_code

        To save memory, the returned
        :class:`~robot.result.executionresult.Result` object does not
        have any information about the executed keywords. If that information
        is needed, the created output XML file needs to be read  using the
        :class:`~robot.result.resultbuilder.ExecutionResult` factory method.

        See the :mod:`package level <robot.running>` documentation for
        more examples, including how to construct executable test suites and
        how to create logs and reports based on the execution results.

        See the :func:`robot.run <robot.run.run>` function for a higher-level
        API for executing tests in files or directories.
        """
        if not settings:
            settings = RobotSettings(options)
            LOGGER.register_console_logger(**settings.console_logger_config)
        with STOP_SIGNAL_MONITOR:
            IMPORTER.reset()
            pyloggingconf.initialize(settings['LogLevel'])
            init_global_variables(settings)
            output = Output(settings)
            runner = Runner(output, settings)
            self.visit(runner)
        output.close(runner.result)
        return runner.result
コード例 #34
0
def TestSuiteFactory(datasources, **options):
    if isinstance(datasources, basestring):
        datasources = [datasources]
    return TestSuite(datasources, RobotSettings(options))
コード例 #35
0
ファイル: testdoc.py プロジェクト: gdw2/robot-framework
def generate_test_doc(args):
    opts, datasources = process_arguments(args)
    suite = TestSuite(datasources, RobotSettings(opts))
    outpath = get_outpath(opts['output'], suite.name)
    serialize_test_doc(suite, outpath, opts['title'])
    exit(msg=outpath)
コード例 #36
0
def TestSuiteFactory(datasources, **options):
    return TestSuite(datasources, RobotSettings(options), process_variables=False)