コード例 #1
0
def path_worker(filepath: Any) -> Optional[int]:
    """Worker used by Pool.

    Runs instance of RobotFramework for given .robot file.
    
    Arguments:
        filepath {Any} -- python PurePath to .robot file to be executed by robot.run.run

    Returns:
        status {Optional[int]} -- None:OK, 1: NOK
    
    See:
        https://docs.python.org/3/library/pathlib.html
        https://robot-framework.readthedocs.io/en/v3.1.2/autodoc/robot.html#module-robot.run
    """
    basepath: Any = get_parent_dir(filepath)
    stdout: Any = StringIO()
    stderr: Any = StringIO("")
    run(
        filepath,
        outputdir=create_output_folder(basepath, filepath.name),
        stdout=stdout,
        stderr=stderr,
    )
    print(stdout.getvalue())
    stdout.close()

    return _check_stderr(stderr)
コード例 #2
0
def tag_worker(tag: str) -> Optional[int]:
    """Worker used by Process.

    Runs instance of RobotFramework for given tag.
    
    Arguments:
        tag {str} -- tag

    Returns:
        status {Optional[int]} -- None: OK, 1: NOK
    
    See:
        https://robot-framework.readthedocs.io/en/v3.1.2/autodoc/robot.html#module-robot.run
    """
    stdout: Any = StringIO()
    stderr: Any = StringIO("")
    run(
        "./",
        outputdir=create_output_folder("./reports/", tag),
        include=[tag],
        stdout=stdout,
        stderr=stderr,
    )
    print(stdout.getvalue())
    stdout.close()

    return _check_stderr(stderr)
コード例 #3
0
def start_library_auto_discovering(port, suite_names, variable_mappings,
                                   data_source_paths):
    import sys
    import os
    from robot.run import run
    from TestRunnerAgent import TestRunnerAgent
    from SuiteVisitorImportProxy import SuiteVisitorImportProxy

    # current dir is needed in sys.path
    sys.path.append('.')

    current_dir = os.getcwd()

    try:
        if os.path.isdir(data_source_paths[0]):
            os.chdir(data_source_paths[0])

        run(*data_source_paths,
            listener=TestRunnerAgent(port),
            prerunmodifier=SuiteVisitorImportProxy(*suite_names),
            suite=suite_names,
            variable=variable_mappings,
            runemptysuite=True,
            dryrun=True,
            output='NONE',
            report='NONE',
            log='NONE',
            console='NONE')
    finally:
        os.chdir(current_dir)
コード例 #4
0
    def _run_task(self):
        options = self.options['options'].copy()
        if 'test' in self.options:
            options['test'] = self.options['test']
        if 'include' in self.options:
            options['include_tag'] = self.options['include']
        if 'exclude' in self.options:
            options['exclude_tag'] = self.options['exclude']

        run(self.options['suites'],
            variable=self.options['vars'],
            **self.options['options'])
コード例 #5
0
def start_auto_discovering(port, data_source_path, support_gevent):
    from robot.run import run
    from TestRunnerAgent import TestRunnerAgent
    from SuiteVisitorImportProxy import SuiteVisitorImportProxy

    run(data_source_path,
        listener=TestRunnerAgent(port),
        prerunmodifier=SuiteVisitorImportProxy(support_gevent=support_gevent),
        runemptysuite=True,
        dryrun=True,
        output='NONE',
        report='NONE',
        log='NONE',
        console='NONE')
コード例 #6
0
ファイル: _errmon.py プロジェクト: AlisaGuseva/r2-d2-1
def main(exec_file, test, result_file):
    import logging
    logging.critical(argv)
    d = getcwd()
    chdir(dirname(abspath(exec_file)))
    exec_file = basename(exec_file)
    try:
        res = run(exec_file, output='NONE', report=result_file, log='NONE', test=test)
    finally:
        chdir(d)

    if res:
        exit(1)
    exit(0)
コード例 #7
0
def run_robot(options, test, data_source):
    sub_dir = os.path.join(options['outputdir'], test)
    os.makedirs(sub_dir)
    options['outputdir'] = sub_dir
    options['report'] = None
    options['test'] = test
    options['prerunmodifier'] = TeardownCleaner(4.5)
    process_reportportal_options(options)
    stdout = os.path.join(sub_dir, 'stdout.log')
    stderr = os.path.join(sub_dir, 'stderr.log')
    with open(stdout, 'w') as stdout, open(stderr, 'w') as stderr:
        ret_code = run(data_source, stdout=stdout, stderr=stderr, **options)
    logger.info('{pid}:\t[{status}] {long_name}'.format(
        pid=os.getpid(),
        status='PASS' if ret_code == 0 else "FAIL",
        long_name=test))
    return ret_code
コード例 #8
0
ファイル: _errmon.py プロジェクト: AlisaGuseva/r2-d2-1
def main(exec_file, test, result_file):
    import logging
    logging.critical(argv)
    d = getcwd()
    chdir(dirname(abspath(exec_file)))
    exec_file = basename(exec_file)
    try:
        res = run(exec_file,
                  output='NONE',
                  report=result_file,
                  log='NONE',
                  test=test)
    finally:
        chdir(d)

    if res:
        exit(1)
    exit(0)
コード例 #9
0
 def run_robot(self):
     """
     Run robot with parameters
     """
     #Add robot root directory to PYTHONPATH
     sys.path.append(self.robot_root_directory)
     if platform.system() == "Linux":
         output_dir = os.path.join("/tmp", str(int(time.time() * 1000)))
     elif platform.system() == "Windows":
         output_dir = os.path.join(r"c:\tmp", str(int(time.time() * 1000)))
     self.robot_run_options["outputdir"] = output_dir
     self.robot_run_options["variable"] = self.gen_robot_variable()
     if self.robot_testcase_names:
         self.robot_run_options["test"] = self.robot_testcase_names
     if self.include_tags:
         self.robot_run_options["include"] = self.include_tags
     self.robot_run_options["loglevel"] = self.robot_log_level
     res = run(*self.robot_scenarios, **self.robot_run_options)
     return res
コード例 #10
0
ファイル: run.py プロジェクト: saltbob/robot-executable
def main():
    run("robot/bot.robot", outputdir="./output")
コード例 #11
0
    def execute_robot_run(test_suites, dependencies, robot_args, debug=False):
        """
        Callback that is invoked when a request to execute a robot run is made

        :param test_suites: Dictionary of suites to execute
        :type test_suites: dict
        :param dependencies: Dictionary of files that the test suites are dependant on
        :type dependencies: dict
        :param robot_args: Dictionary of arguments to pass to robot.run()
        :type robot_args: dict
        :param debug: Run in debug mode. This changes the logging level and does not cleanup the workspace
        :type debug: bool

        :return: Dictionary containing test results and artifacts
        :rtype: dict
        """
        workspace_dir = None
        std_out_err = None
        old_cwd = None
        try:
            old_log_level = logger.level
            if debug:
                logger.setLevel(logging.DEBUG)

            # Save all suites & dependencies to disk
            workspace_dir = RobotFrameworkServer._create_workspace(test_suites, dependencies)

            # Change the CWD to the workspace
            old_cwd = os.getcwd()
            os.chdir(workspace_dir)
            sys.path.append(workspace_dir)

            # Execute the robot run
            std_out_err = StringIO()
            logger.debug('Beginning Robot Run.')
            logger.debug('Robot Run Args: ' + str(robot_args))
            ret_code = run('.',
                           stdout=std_out_err,
                           stderr=std_out_err,
                           outputdir=workspace_dir,
                           name='Root',
                           **robot_args)
            logger.debug('Robot Run finished')

            # Read the test artifacts from disk
            output_xml, log_html, report_html = RobotFrameworkServer._read_robot_artifacts_from_disk(workspace_dir)

            ret_val = {'std_out_err': xmlrpc_client.Binary(std_out_err.getvalue().encode('utf-8')),
                       'output_xml': xmlrpc_client.Binary(output_xml.encode('utf-8')),
                       'log_html': xmlrpc_client.Binary(log_html.encode('utf-8')),
                       'report_html': xmlrpc_client.Binary(report_html.encode('utf-8')),
                       'ret_code': ret_code}
        except Exception as e:
            # Log here because the RPC framework doesn't give the client a full stacktrace
            logging.error(e)
            raise
        finally:
            if old_cwd:
                os.chdir(old_cwd)

            if std_out_err:
                std_out_err.close()

            if workspace_dir and not debug:
                shutil.rmtree(workspace_dir)

        logger.debug('End of RPC function')
        # Revert the logger back to its original level
        logger.setLevel(old_log_level)
        return ret_val