Example #1
0
    def target(*a, **kw):
        listener = allure_robotframework(logger_path=allure_dir)

        with open(stdout_file, 'w+') as stdout:
            options = {"listener": listener, "outputdir": output_dir, "stdout": stdout}
            options.update(kw)
            run(*a, **options)
 def test_original_signal_handlers_are_restored(self):
     my_sigterm = lambda signum, frame: None
     signal.signal(signal.SIGTERM, my_sigterm)
     run(join(ROOT, 'atest', 'testdata', 'misc', 'pass_and_fail.txt'),
         stdout=StringIO(), output=None, log=None, report=None)
     assert_equals(signal.getsignal(signal.SIGINT), self.orig_sigint)
     assert_equals(signal.getsignal(signal.SIGTERM), my_sigterm)
Example #3
0
def run_suites(test_dir, suites, out_dir="./outputs", **options):
    # TODO: add logic

    try:
        for f in os.listdir(out_dir):
            os.remove('/'.join((out_dir, f)))
    except OSError:
        pass
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    for s in suites:
        longname = s.longname
        varfile = []
        varfile.append('resources/libraries/python/topology.py')

        # TODO: check testcases Tags

        with open('{}/{}.out'.format(out_dir, longname), 'w') as out, \
             open('{}/{}.log'.format(out_dir, longname), 'w') as debug:
            robot.run(test_dir,
                      suite=[longname],
                      output='{}/{}.xml'.format(out_dir, longname),
                      debugfile=debug,
                      log=None,
                      report=None,
                      stdout=out,
                      variablefile=varfile,
                      **options)
    def run_robot(path, **kw):

        # ToDo: fix it (_core not works correctly with multiprocessing)
        # import six
        # import allure_commons
        # if six.PY2:
        #     reload(allure_commons._core)
        # else:
        #     import importlib
        #     importlib.reload(allure_commons._core)
        #
        #

        from allure_robotframework import allure_robotframework

        listener = allure_robotframework(logger_path=tmp_path)
        stdout_file = os.path.abspath(
            os.path.join(tmp_path, "..", "stdout.txt"))
        output_path = os.path.abspath(os.path.join(tmp_path, ".."))

        with open(stdout_file, 'w+') as stdout:
            options = {
                "listener": listener,
                "outputdir": output_path,
                "stdout": stdout,
                "extension": "rst"
            }
            options.update(kw)
            run(path, **options)
Example #5
0
def run_suite_option(suite_name):
    """Run Specified Test Suite and creates the results structure

    Args:
        suite_name: name of the suite that will be executed
    """

    # Get suite details
    suite = common.Suite(suite_name, MAIN_SUITE)
    # Create results directory if does not exist
    results_dir = common.check_results_dir(SUITE_DIR)
    # Create output directory to store execution results
    output_dir = common.create_output_dir(results_dir, suite.name)
    # Create a link pointing to the latest run
    common.link_latest_run(SUITE_DIR, output_dir)
    # Updating config.ini LOG_PATH variable with output_dir
    config_path = os.path.join(SUITE_DIR, 'Config', 'config.ini')
    update_config_ini(config_ini=config_path, LOG_PATH=output_dir)
    # Select tags to be used, empty if not set to execute all
    if ARGS.tags:
        include_tags = ARGS.tags
    else:
        include_tags = ''
    # Run sxt-test-suite using robot framework
    robot.run(suite.path,
              outputdir=output_dir,
              debugfile=LOG_NAME,
              variable='LOGS_DIR:{}'.format(output_dir),
              include=include_tags)
Example #6
0
def run_robot(targets, report_file, iteration_limit, duration_limit):
    listener = TaurusListener(report_file)
    listener.prepare()
    stdout = StringIO()
    stderr = StringIO()
    start_time = int(time.time())
    iteration = 0
    try:
        while True:
            run(
                *targets,
                listener=listener,  # pass Taurus listener
                output=None,
                log=None,
                report=None,  # mute default reporting
                stdout=stdout,
                stderr=stderr)  # capture stdout/stderr
            iteration += 1
            if 0 < duration_limit < int(time.time()) - start_time:
                break
            if iteration >= iteration_limit:
                break
    finally:
        listener.post_process()

    sys.stdout.write("Robot stdout:\n" + stdout.getvalue() + "\n")
    sys.stderr.write("Robot stderr:\n" + stderr.getvalue() + "\n")

    if listener.get_test_count() == 0:
        raise ValueError("Nothing to test. No tests were found.")
Example #7
0
async def start_robot(data):
    print('start_robot event called')
    with open(join(log_dir, 'robot.log'), 'w') as log_file:
        template_path = join(template_dir, data['template_name'])
        print('Robot {0} will be executed.'.format(template_path))
        robot.run(template_path, stdout=log_file, outputdir=log_dir)
        print('Execution done')
Example #8
0
def run_robot(targets, report_file, iteration_limit, duration_limit, variablefile, include):
    listener = TaurusListener(report_file)
    listener.prepare()
    stdout = StringIO()
    stderr = StringIO()
    start_time = int(time.time())
    iteration = 0
    try:
        while True:
            kwargs = {
                'listener': listener,  # pass Taurus listener
                'output': None, 'log': None, 'report': None,  # mute default reporting
                'stdout': stdout, 'stderr': stderr,  # capture stdout/stderr
            }
            if variablefile is not None:
                kwargs['variablefile'] = variablefile
            if include is not None:
                kwargs['include'] = include
            run(*targets, **kwargs)
            iteration += 1
            if 0 < duration_limit < int(time.time()) - start_time:
                break
            if iteration >= iteration_limit:
                break
    finally:
        listener.post_process()

    sys.stdout.write("Robot stdout:\n" + stdout.getvalue() + "\n")
    sys.stderr.write("Robot stderr:\n" + stderr.getvalue() + "\n")

    if listener.get_test_count() == 0:
        raise ValueError("Nothing to test. No tests were found.")
Example #9
0
def execute_robot_run(request_id, test_suite, testcase, variables_file_path):
    output_dir = os.getenv(
        'OPEN_CLI_HOME') + '/data/executions/' + request_id + '/logs'

    with open('run.txt', 'w') as output:
        if (variables_file_path):
            run(test_suite,
                report=None,
                log=None,
                test=testcase,
                variablefile=variables_file_path,
                stdout=output,
                stderr=output,
                outputdir=output_dir)
        else:
            run(test_suite,
                report=None,
                log=None,
                test=testcase,
                stdout=output,
                stderr=output,
                outputdir=output_dir)

    if os.path.exists('run.txt'):
        with open('run.txt', 'r') as log:
            print(log.read())
        os.remove('run.txt')
Example #10
0
def run_suites(test_dir, suites, out_dir="./outputs", **options):
    # TODO: add logic

    try:
        for f in os.listdir(out_dir):
            os.remove('/'.join((out_dir, f)))
    except OSError:
        pass
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    for s in suites:
        longname = s.longname
        varfile=[]
        varfile.append('resources/libraries/python/topology.py')

        # TODO: check testcases Tags

        with open('{}/{}.out'.format(out_dir, longname), 'w') as out, \
             open('{}/{}.log'.format(out_dir, longname), 'w') as debug:
            robot.run(test_dir,
                      suite=[longname],
                      output='{}/{}.xml'.format(out_dir, longname),
                      debugfile=debug,
                      log=None,
                      report=None,
                      stdout=out,
                      variablefile=varfile,
                      **options)
Example #11
0
def main():
    #Push required data in builtins
    from optparse import OptionParser
    
    parser = OptionParser()
    parser.add_option("-t", "--test", dest="testlist", help="Specify file path of TestList to be executed", metavar="path-to-file")
    parser.add_option("-b", "--browser", action="store", dest="browser")
    parser.add_option("-i", "--includetag", dest="testincludetags", default=False, help="Run tests of given tag only")
    parser.add_option("-e", "--excludetag", dest="testexcludetags", default=False, help="Exclude tests of given tag")
    parser.add_option("-r", "--rungiventests", dest="rungiventests", default=False, help="Execute only given test case from suite")
    parser.add_option("-m", "--randomize",action="store_true", dest="runrandomize", default=False, help="Randomizes the test execution order")
    parser.add_option("-f", "--exitonfailure",action="store_true", dest="exitonfailure", default=False, help="Exit suite if test failed")
    parser.add_option("-s", "--runsuite", action="store", dest="runsuitesetup", help="Run suite setup")
    parser.add_option("-g", "--debugfile", action="store_true", dest="debugfile", default=False, help="Create debug log file")
    parser.add_option("-u", "--baseurl", action="store", dest="baseurl")
    
    parser.add_option("-n", "--TestName", action="store", dest="test_name")
    parser.add_option("-M", "--MetaData", action="store", dest="metadata")
#     parser.add_option("-a", "--abortonfailure", action="store_true", dest="abortonfailure", default=False, help="Abort suite on first test failure ")
    s,remainder = parser.parse_args()
    global tr
    tr = os.getcwd()

    from robot import pythonpathsetter
    pythonpathsetter.add_path(tr)
    robot.run(s.testlist)
Example #12
0
def run_robot(targets, report_file, iteration_limit, duration_limit, variablefile):
    listener = TaurusListener(report_file)
    listener.prepare()
    stdout = StringIO()
    stderr = StringIO()
    start_time = int(time.time())
    iteration = 0
    try:
        while True:
            kwargs = {
                'listener': listener,  # pass Taurus listener
                'output': None, 'log': None, 'report': None,  # mute default reporting
                'stdout': stdout, 'stderr': stderr,  # capture stdout/stderr
            }
            if variablefile is not None:
                kwargs['variablefile'] = variablefile
            run(*targets, **kwargs)
            iteration += 1
            if 0 < duration_limit < int(time.time()) - start_time:
                break
            if iteration >= iteration_limit:
                break
    finally:
        listener.post_process()

    sys.stdout.write("Robot stdout:\n" + stdout.getvalue() + "\n")
    sys.stderr.write("Robot stderr:\n" + stderr.getvalue() + "\n")

    if listener.get_test_count() == 0:
        raise ValueError("Nothing to test. No tests were found.")
Example #13
0
def runCase(run_id, case_id, build_id, environment_id, environment_name='cdh',\
    varfile='/var/dt/tf/etc/environments/cdh.py', testcasename='REST API Ping',\
    product_version='3.2.0',build_name='3.2.0'):
    """runs a test case, given these parameters:
    run_id,case_id,build_id,environment_id,environment_name='<as it appears in
    testopia>',varfile='<full path to file>',testcasename
    """
    #print product_version
    lockfile = '/var/dt/tf/tmp/locks/' + environment_name + '.lock'
    HookInit = HookFW(lockfile, 5, 600)
    logdir = '/var/dt/tf/logs/' + str(run_id) + '/' + str(case_id)
    stdoutfile = logdir + '/stdout.txt'
    listenerfile = '/var/dt/tf/lib/integration/PythonListener.py:'
    listenerargs = str(run_id) + ":" + str(case_id) + ":" + str(build_id) + \
    ":" + str(environment_id)
    prodvar = 'dt_version="' + product_version.strip() + '"\n'
    #print prodvar
    buildvar = 'dt_build_name ="' + build_name.strip() + '"\n'
    lstrnr = listenerfile + listenerargs
    if HookInit.lockLoop():
        print("Locked it , %s" % time.ctime())
        os.makedirs(logdir)
        shutil.copy(varfile, logdir)
        Vfile = logdir + '/' + os.path.basename(varfile)
        with open(Vfile, "a") as varfhandle:
            varfhandle.write('\n' + prodvar + buildvar)
            varfhandle.close()

        with open(stdoutfile, 'w') as stdout:
            run('/var/dt/tf/Tests', test=testcasename, variablefile=varfile,\
            vel='DEBUG', outputdir=logdir, report='report.html',\
            log='log.html', listener=lstrnr, stdout=stdout)
#            variable=prodvar)
    os.remove(lockfile)
    print("Released lock, %s" % time.ctime())
 def test_importer_caches_are_cleared_between_runs(self):
     data = join(ROOT, 'atest', 'testdata', 'core', 'import_settings.txt')
     run(data, outputdir=TEMP, stdout=StringIO(), stderr=StringIO())
     lib = self._import_library()
     res = self._import_resource()
     run(data, outputdir=TEMP, stdout=StringIO(), stderr=StringIO())
     assert_true(lib is not self._import_library())
     assert_true(res is not self._import_resource())
 def test_clear_namespace_between_runs(self):
     data = join(ROOT, 'atest', 'testdata', 'variables', 'commandline_variables.html')
     rc = run(data, outputdir=TEMP, stdout=StringIO(), stderr=StringIO(),
              test=['NormalText'], variable=['NormalText:Hello'])
     assert_equals(rc, 0)
     rc = run(data, outputdir=TEMP, stdout=StringIO(), stderr=StringIO(),
              test=['NormalText'])
     assert_equals(rc, 1)
 def run_and_analyse_multiple_robottests(self, list_of_testfilename):
     list_of_output_xml_files = []
     for testfilename in list_of_testfilename:
         outputfile = tempfile.mkstemp(suffix='.xml')[1]
         robot.run(testfilename, report='NONE', log='NONE', output=outputfile)
         list_of_output_xml_files.append(outputfile)
     keywords = robot_profiler.analyse_output_xml(list_of_output_xml_files)
     return keywords
Example #17
0
 def test_clear_namespace_between_runs(self):
     data = join(ROOT, 'atest', 'testdata', 'variables', 'commandline_variables.html')
     rc = run(data, outputdir=TEMP, stdout=StringIO(), stderr=StringIO(),
              test=['NormalText'], variable=['NormalText:Hello'])
     assert_equals(rc, 0)
     rc = run(data, outputdir=TEMP, stdout=StringIO(), stderr=StringIO(),
              test=['NormalText'])
     assert_equals(rc, 1)
Example #18
0
def solve_suite_names(outs_dir, datasources, options):
    opts = _options_for_dryrun(options, outs_dir)
    run(*datasources, **opts)
    output = os.path.join(outs_dir, opts['output'])
    suite_names = get_suite_names(output)
    if os.path.isfile(output):
        os.remove(output)
    return sorted(set(suite_names))
Example #19
0
def create_new_flight(template):
    """ create new flight with robot """
    print("create new flight ...")
    with open('stdout.txt', 'w') as stdout:
        robot.run('robot_files/tests/',
                  include=[template],
                  log=None,
                  stdout=stdout)
Example #20
0
def run_robot(root):
    args = {
        'variable': ['ROOTDIR:' + root],
        'variablefile': root + '/' + "env.py",
        'suite': 'robot_tests',
        'noncritical': 'noncritical'
    }
    robot.run(root, **args)
Example #21
0
 def test_importer_caches_are_cleared_between_runs(self):
     data = join(ROOT, 'atest', 'testdata', 'core', 'import_settings.txt')
     run(data, outputdir=TEMP, stdout=StringIO(), stderr=StringIO())
     lib = self._import_library()
     res = self._import_resource()
     run(data, outputdir=TEMP, stdout=StringIO(), stderr=StringIO())
     assert_true(lib is not self._import_library())
     assert_true(res is not self._import_resource())
Example #22
0
def solve_suite_names(outs_dir, datasources, options):
    opts = _options_for_dryrun(options, outs_dir)
    run(*datasources, **opts)
    output = os.path.join(outs_dir, opts['output'])
    suite_names = get_suite_names(output)
    if os.path.isfile(output):
        os.remove(output)
    return suite_names
Example #23
0
def solve_suite_names(outs_dir, datasources, options, pabot_args):
    if 'suitesfrom' in pabot_args:
        return _suites_from_outputxml(pabot_args['suitesfrom'])
    opts = _options_for_dryrun(options, outs_dir)
    with _with_modified_robot():
        run(*datasources, **opts)
    output = os.path.join(outs_dir, opts['output'])
    suite_names = get_suite_names(output)
    return sorted(set(suite_names))
Example #24
0
def _run_tests_and_process_output(robot_file):
    results = join(CURDIR, "results")
    output = join(results, "output.xml")
    if exists(results):
        rmtree(results)
    run(join(CURDIR, robot_file), output=output, log=None, report=None, loglevel="DEBUG")
    process_output(output)
    rebot(output, outputdir=results)
    return output
Example #25
0
def solve_suite_names(outs_dir, datasources, options, pabot_args):
    if 'suitesfrom' in pabot_args:
        return _suites_from_outputxml(pabot_args['suitesfrom'])
    opts = _options_for_dryrun(options, outs_dir)
    with _with_modified_robot():
        run(*datasources, **opts)
    output = os.path.join(outs_dir, opts['output'])
    suite_names = get_suite_names(output)
    return sorted(set(suite_names))
Example #26
0
def run_robot(nightly='False', build_id=''):
    """This method used to run the robot framework both test and Contiouns integartion setup """
    if not nightly:
        now = str(datetime.datetime.now())
        test_run_folder = "Robot_Logs" + datetime.datetime.now().strftime(
            "%Y%m%d-%H%M%S")

        complete_dir_path = os.path.join(os.getcwd(),
                                         "logs" + os.sep + test_run_folder)
        os.environ["RESULTS_PATH"] = "%s" % test_run_folder

        if not os.path.isdir(complete_dir_path):
            os.mkdir(complete_dir_path)
        else:
            pass
        #Export the result directory for the test suite
        os.environ["RESULTS_PATH"] = test_run_folder

    else:
        complete_dir_path = os.path.join(os.getcwd(),
                                         "logs" + os.sep + build_id)
        os.environ["RESULTS_PATH"] = "%s" % build_id
        if not os.path.isdir(complete_dir_path):
            os.mkdir(complete_dir_path)
        else:
            pass

#Form complete path to store html rport
    if nightly:

        complete_report_path = os.path.join(complete_dir_path, "report.html")
        #Form complete path to store log report
        complete_log_path = os.path.join(complete_dir_path, "log.html")
        complete_xml_path = os.path.join(complete_dir_path, "output.xml")

    else:
        complete_report_path = os.path.join(
            complete_dir_path, "Functional_" +
            datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + ".html")
        #Form complete path to store log report
        complete_log_path = os.path.join(
            complete_dir_path, "Functional_log" +
            datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + ".html")

    if not nightly:
        #start the suite
        run("resource/Gluster.robot",
            report=complete_report_path,
            log=complete_log_path)
    else:
        run(
            # "resource/Login/LoginToWizr.robot",
            # "resource/camera/createDelete_Camera.robot",
            "resource/Gluster.robot",
            report=complete_report_path,
            log=complete_log_path,
            output=complete_xml_path)
def run_robot(nightly='False', build_id=''):
    import os
    """This method used to run the robot framework both test and Contiouns integartion setup """

    if not nightly:
        now = str(datetime.datetime.now())
        test_run_folder = "Robot_Logs" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")

        complete_dir_path = os.path.join(os.getcwd(), "logs" + os.sep + test_run_folder)
        os.environ["RESULTS_PATH"] = "%s" % test_run_folder

        if not os.path.isdir(complete_dir_path):
            os.mkdir(complete_dir_path)
        else:
            pass
        # Export the result directory for the test suite
        os.environ["RESULTS_PATH"] = test_run_folder


    else:
        complete_dir_path = os.path.join(os.getcwd(), "logs" + os.sep + build_id)
        os.environ["RESULTS_PATH"] = "%s" % build_id
        if not os.path.isdir(complete_dir_path):
            os.mkdir(complete_dir_path)
        else:
            pass

    # Form complete path to store html rport
    if nightly:

        complete_report_path = os.path.join(complete_dir_path, "report.html")
        # Form complete path to store log report
        complete_log_path = os.path.join(complete_dir_path, "log.html")
        complete_xml_path = os.path.join(complete_dir_path, "output.xml")

    else:
        complete_report_path = os.path.join(complete_dir_path,
                                            "Functional_" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + ".html")
        # Form complete path to store log report
        complete_log_path = os.path.join(complete_dir_path,
                                         "Functional_log" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + ".html")

    if not nightly:
        # start the suite

        run(
            "/home/vagrant/uniclair_automation/resource/Uniclair_login_logout.robot",
            report=complete_report_path, log=complete_log_path)
    else:
        import subprocess
        import os
        run("/home/vagrant/uniclair_automation/resource/Uniclair_login_logout.robot",
            report=complete_report_path, log=complete_log_path, output=complete_xml_path)
        # run(
        #     "resource/HomePage_IVtree.robot",
        #     report=complete_report_path, log=complete_log_path, output=complete_xml_path)complete_xml_path
        return
Example #28
0
def run_test(testfile):
    """
      Execute defined test cases using as parameter received testfile.
      @param testfile Test's file path.
    """
    global tmpOutputDir, noReport, DRY_RUN
    logging.debug("Testing {0}".format(testfile))
    if testfile.endswith(".robot"):
        robotstart = testfile.find(".robot")
        testname = testfile[:robotstart]
        profile = "../../config/profiles/Sample_Profile.py"
        iterations = "iterations:1"
        if tmpOutputDir is None:
            tmpOutputDir = OUTPUTDIR
        kwargs = {
            "outputdir": tmpOutputDir,
            "loglevel": args.logLevel,
            "variablefile": profile,
            "variable": [iterations]
        }
        if args.include:
            kwargs["include"] = args.include
        if args.exclude:
            kwargs["exclude"] = args.exclude
        if args.configFile:
            kwargs["variable"].append("PLATCONFIG:" + args.configFile)
            kwargs["outputdir"] = tmpOutputDir
        if os.path.isdir(testname):
            logging.debug(
                "Found configuration directory for {0}".format(testname))
            for cfg in os.listdir(testname):
                cfgIndex = cfg.find(".cfg")
                if cfgIndex > 0:
                    cfgname = cfg[:cfgIndex]
                    Newtestname = testname + "_" + cfgname
                    if noReport:
                        kwargs["output"] = Newtestname + ".xml"
                    logging.info("Running test {0} using config: {1}".format(
                        testfile, testname + "/" + cfg))
                    kwargs["report"] = Newtestname + "_report.html"
                    kwargs["variable"].append("testcase_cfg:" + testname +
                                              "/" + cfg)
                    if DRY_RUN is False:
                        run(testfile, **kwargs)
                    else:
                        pass
        else:
            logging.info("Run test {0}".format(testfile))
            if DRY_RUN is False:
                logging.debug("Output to {0}, {1}".format(
                    tmpOutputDir, noReport))
                if noReport:
                    kwargs["output"] = testname + ".xml"
                run(testfile, **kwargs)
    else:
        logging.error("{0} Not a robot file".format(testfile))
Example #29
0
 def test_original_signal_handlers_are_restored(self):
     my_sigterm = lambda signum, frame: None
     signal.signal(signal.SIGTERM, my_sigterm)
     run(join(ROOT, 'atest', 'testdata', 'misc', 'pass_and_fail.txt'),
         stdout=StringIO(),
         output=None,
         log=None,
         report=None)
     assert_equals(signal.getsignal(signal.SIGINT), self.orig_sigint)
     assert_equals(signal.getsignal(signal.SIGTERM), my_sigterm)
Example #30
0
def worker_shop(context=None,
                masterip='localhost',
                port='',
                project_name='',
                other_variables=''):
    """worker will say hi with task controller"""
    tests = os.path.join(project_name, 'cases')
    results_path = os.path.join(project_name, 'results')
    #worker_ip = get_ip()
    listener = 'robotx.core.distlistener.MultiListener:%s:%s' \
               % (masterip, port)
    #identity = unicode(worker_ip)
    identity = u"%04x-%04x" % (randint(0, 0x10000), randint(0, 0x10000))
    context = context or zmq.Context.instance()
    # socket for running task
    worker = context.socket(zmq.REQ)
    # We use a string identity for ease here
    #zhelpers.set_id(worker)
    worker.setsockopt_string(zmq.IDENTITY, identity)
    worker.connect("tcp://%s:%s" % (masterip, port))
    # socket for control input
    controller = context.socket(zmq.SUB)
    cport = str(int(port) - 1)
    controller.connect("tcp://%s:%s" % (masterip, cport))
    controller.setsockopt(zmq.SUBSCRIBE, b"")
    # Process messages from maskter and controller
    poller = zmq.Poller()
    poller.register(worker, zmq.POLLIN)
    poller.register(controller, zmq.POLLIN)
    while True:
        # Tell the router we're ready for work
        worker.send('Ready')
        socks = dict(poller.poll())
        if socks.get(worker) == zmq.POLLIN:
            # Get workload from router, until finished
            tag = worker.recv()
            #print '\nthe tag name is: %s\n' % tag
            with open('/tmp/stdout.txt', 'w') as stdout:
                run(
                    tests,
                    loglevel='TRACE',
                    include=tag,
                    #exclude=['notready'],
                    noncritical=['noncritical'],
                    outputdir=results_path,
                    output=tag,
                    variable=other_variables,
                    tagstatexclude='ID_*',
                    listener=listener,
                    stdout=stdout,
                    runemptysuite=True)
        # Any waiting controller command acts as 'KILL'
        if socks.get(controller) == zmq.POLLIN:
            break
Example #31
0
 def run_and_analyse_multiple_robottests(self, list_of_testfilename):
     list_of_output_xml_files = []
     for testfilename in list_of_testfilename:
         outputfile = tempfile.mkstemp(suffix='.xml')[1]
         robot.run(testfilename,
                   report='NONE',
                   log='NONE',
                   output=outputfile)
         list_of_output_xml_files.append(outputfile)
     keywords = robot_profiler.analyse_output_xml(list_of_output_xml_files)
     return keywords
Example #32
0
def _run_tests_and_statuschecker(test_file):
    curdir = dirname(abspath(__file__))
    results = join(curdir, 'results')
    output = join(results, 'output.xml')
    if exists(results):
        rmtree(results)
    run(join(curdir, test_file), output=output, log=None, report=None,
        loglevel='DEBUG')
    call(['python', join(dirname(curdir), 'robotstatuschecker.py'), output])
    rebot(output, outputdir=results)
    return output
def run_robot(app, doctree, docname):

    # Tests can be switched off with a global setting:
    if not app.config.sphinxcontrib_robotframework_enabled:
        return

    # Set up a variable for "the current working directory":
    robot_dir = os.path.dirname(os.path.join(app.srcdir, docname))

    # Tests can be made conditional by listing artifacts created by the
    # tests. When artifacts are listed, tests are only run as long as those
    # artifacts don't exist:
    creates_paths = [os.path.join(robot_dir, x)
                     for x in getattr(doctree, '_robot_creates', [])]
    missing_paths = [path for path in creates_paths
                     if not os.path.isfile(path)]
    if creates_paths and not missing_paths:
        return

    # Tests are only run when they are found:
    if not hasattr(doctree, '_robot_source'):
        return

    # Build a test suite:
    robot_file = tempfile.NamedTemporaryFile(dir=robot_dir, suffix='.robot')
    robot_file.write(doctree._robot_source.encode('utf-8'))
    robot_file.flush()  # flush buffer into file

    # Run the test suite:
    options = {
        'outputdir': robot_dir,
        'output': 'NONE',
        'log': 'NONE',
        'report': 'NONE',
        'variable': [
            '%s:%s' % key_value for key_value in
            app.config.sphinxcontrib_robotframework_variables.items()
        ]
    }
    robot.run(robot_file.name, **options)

    # Close the test suite (and delete it, because it's a tempfile):
    robot_file.close()

    # Re-process images to include robot generated images:
    if os.path.sep in docname:
        # Because process_images is not designed to be called more than once,
        # calling it with docnames with sub-directories needs a bit cleanup:
        removable = os.path.dirname(docname) + os.path.sep
        for node in doctree.traverse(docutils.nodes.image):
            if node['uri'].startswith(removable):
                node['uri'] = node['uri'][len(removable):]
    app.env.process_images(docname, doctree)
Example #34
0
def run_tests():
    test_path = os.path.curdir
    tmp_path = tempfile.gettempdir()
    output_dir = os.path.join(tmp_path, "robotx_test_result")
    os.mkdir(output_dir)
    output_file = os.path.join(output_dir, "output.xml")
    log_file = os.path.join(output_dir, "log.html")
    report_file = os.path.join(output_dir, "report.html")

    suites = ["test_cmd_*"]

    run(test_path, suite=suites, outputdir=output_dir, output=output_file, log=log_file, report=report_file)
Example #35
0
def main():
    output = '../Logs/unicorn'

    robot.run(TEST_TO_RUN, \
     loglevel='INFO', \
     exitonfailure=True, \
     noncritical="non-critical", \
     log=output+"_log", \
     output=output, \
     report=output+"_report", \
     timestampoutputs=False, \
     exclude="manual_test")
Example #36
0
def _run_tests_and_process_output(robot_file):
    results = join(CURDIR, "results")
    output = join(results, "output.xml")
    if exists(results):
        rmtree(results)
    if RF3:
        run(join(CURDIR, robot_file), output=output, log=None, report=None, loglevel="DEBUG", exclude="rf3unsupported")
    else: 
        run(join(CURDIR, robot_file), output=output, log=None, report=None, loglevel="DEBUG")
    process_output(output)
    rebot(output, outputdir=results)
    return output
Example #37
0
def index(request):

    if request.method == 'POST' and 'benu1' in request.POST:

        # import function to run
        #   from .robot_libs import benu1

        # call function
        robot.run('robot_libs/benu1.robot', outputdir='robot_libs/log')
    #return HttpResponse('Hello')
    # return user to required page
    #return HttpResponseRedirect(reverse(app_name:view_name)
    return render(request, "index.html")
Example #38
0
def _run_tests_and_process_output(robot_file):
    results = join(CURDIR, 'results')
    output = join(results, 'output.xml')
    if exists(results):
        rmtree(results)
    run(join(CURDIR, robot_file),
        output=output,
        log=None,
        report=None,
        loglevel='DEBUG')
    process_output(output)
    rebot(output, outputdir=results)
    return output
def _api_run_test(datasources, serial, test, browser='chrome'):
    print('test: {}'.format(test))
    print('pythonpath: {}'.format(default_pythonpath))
    print('datasources: {}'.format(datasources))
    fldr = './results/{}/tests/{}'.format(serial, test)
    run(datasources,
        test=test,
        variable=[
            'browser:{}'.format(browser), 'region:QA',
            'remote_url:http://90tvmcjnkd:4444/wd/hub'
        ],
        outputdir=fldr)
    return test
Example #40
0
 def get(self):
     print("Robot parameters received.....")
     fw_models = self.get_arguments("fw_model")
     print(fw_models)
     para_dict = {}
     para_dict['equipment_type'] = fw_models
     yml = ROBOT_YAML()
     with open("parameters.yaml", "w") as fh_para:
         yml.dump(para_dict, fh_para)
     try:
         run(robot_path, variablefile='parameters.yaml')
     except KeyboardInterrupt:
         print("You have pressed CTRL+C!!!!!")
         sys.exit(0)
Example #41
0
def test_template(schema_base, temp_dir):
    schema_file = os.path.join(VENDOR_DIRECTORY, f"{schema_base}.xsd")
    schema = xmlschema.XMLSchema(schema_file)
    result_file = os.path.join(temp_dir, "results.xml")
    robot.run("test",
              listener=JunitListener(result_file, schema_base),
              critical="working",
              noncritical="notworking",
              console="none",
              log="NONE",
              report="NONE",
              output="NONE",
              loglevel="NONE")
    schema.validate(result_file)
Example #42
0
def worker_shop(context=None, masterip='localhost', port='', project_name='',
                other_variables=''):
    """worker will say hi with task controller"""
    tests = os.path.join(project_name, 'cases')
    results_path = os.path.join(project_name, 'results')
    #worker_ip = get_ip()
    listener = 'robotx.core.distlistener.MultiListener:%s:%s' \
               % (masterip, port)
    #identity = unicode(worker_ip)
    identity = u"%04x-%04x" % (randint(0, 0x10000), randint(0, 0x10000))
    context = context or zmq.Context.instance()
    # socket for running task
    worker = context.socket(zmq.REQ)
    # We use a string identity for ease here
    #zhelpers.set_id(worker)
    worker.setsockopt_string(zmq.IDENTITY, identity)
    worker.connect("tcp://%s:%s" % (masterip, port))
    # socket for control input
    controller = context.socket(zmq.SUB)
    cport = str(int(port) - 1)
    controller.connect("tcp://%s:%s" % (masterip, cport))
    controller.setsockopt(zmq.SUBSCRIBE, b"")
    # Process messages from maskter and controller
    poller = zmq.Poller()
    poller.register(worker, zmq.POLLIN)
    poller.register(controller, zmq.POLLIN)
    while True:
        # Tell the router we're ready for work
        worker.send('Ready')
        socks = dict(poller.poll())
        if socks.get(worker) == zmq.POLLIN:
            # Get workload from router, until finished
            tag = worker.recv()
            #print '\nthe tag name is: %s\n' % tag
            with open('/tmp/stdout.txt', 'w') as stdout:
                run(tests,
                    loglevel='TRACE',
                    include=tag,
                    #exclude=['notready'],
                    noncritical=['noncritical'],
                    outputdir=results_path,
                    output=tag,
                    variable=other_variables,
                    tagstatexclude='ID_*',
                    listener=listener,
                    stdout=stdout,
                    runemptysuite=True)
        # Any waiting controller command acts as 'KILL'
        if socks.get(controller) == zmq.POLLIN:
            break
Example #43
0
def launch_robot_test(output, variables, excluded_tags, included_tags):
    #excluded_tags = ["flash_sw", "dac_test"]
    #included_tags = ["flash_sw"]

    robot.run(TEST_TO_RUN, \
     loglevel='INFO', \
     exitonfailure=True, \
     noncritical="non-critical", \
     log=output+"_log", \
     variable=variables, \
     output=output, \
     report=output+"_report", \
     timestampoutputs=False, \
     include=included_tags, \
     exclude=excluded_tags)
 def test_custom_stdout_and_stderr_with_minimal_implementation(self):
     output = StreamWithOnlyWriteAndFlush()
     assert_equals(run(self.warn, output='NONE', stdout=output, stderr=output), 0)
     self._assert_output(output, [('[ WARN ]', 4), ('[ ERROR ]', 1),
                                  ('Warnings And Errors', 3), ('Output:', 1),
                                  ('Log:', 0), ('Report:', 0)])
     self._assert_outputs()
Example #45
0
 def run(self, args, opts):
     """Sub command 'check' runner"""
     if not opts.cases:
         raise UsageError("case path must be set with -c or --cases!")
     print " Syntax Checking ".center(70, '*')
     print '...'
     log_level = 'TRACE'
     cases_path = opts.cases
     tmp_path = tempfile.gettempdir()
     xml_result = os.path.join(tmp_path, "check_result.xml")
     output_file = os.path.join(tmp_path, "stdout.txt")
     with open(output_file, 'w') as stdout:
         dryrun_result = run(cases_path,
                             dryrun=True,
                             loglevel=log_level,
                             log='NONE',
                             report='NONE',
                             output=xml_result,
                             stdout=stdout)
     detail_result = ExecutionResult(xml_result)
     if opts.is_tcms:
         if not opts.plan_id:
             raise UsageError("plan id must be set with -p or --planid!")
         plan_id = opts.plan_id
         tcms = TCMS()
         ids = tcms.get_plan_case_ids(plan_id)
         detail_result.visit(ResultChecker(ids, plan_id))
     elif dryrun_result == 0:
         print 'Contratulations, no syntax error'
     else:
         detail_result.visit(DryRunChecker())
     print '\n( No news is good news:) )'
     print 'checing result is in the file: %s' % output_file
     print ' DONE '.center(70, '*')
Example #46
0
    def _run_inner(self, fixture, hotspot, test_cases_names, options):
        file_name = os.path.splitext(os.path.basename(self.path))[0]
        suite_name = RobotTestSuite._create_suite_name(file_name, hotspot)

        variables = ['SKIP_RUNNING_SERVER:True', 'DIRECTORY:{}'.format(self.remote_server_directory), 'PORT_NUMBER:{}'.format(options.remote_server_port)]
        if hotspot:
            variables.append('HOTSPOT_ACTION:' + hotspot)
        if options.debug_mode:
            variables.append('CONFIGURATION:Debug')

        test_cases = [(test_name, '{0}.{1}'.format(suite_name, test_name)) for test_name in test_cases_names]
        if fixture:
            test_cases = [x for x in test_cases if fnmatch.fnmatch(x[1], fixture)]
            if len(test_cases) == 0:
                return True
            deps = set()
            for test_name in (t[0] for t in test_cases):
                deps.update(self._get_dependencies(test_name))
            if not self._run_dependencies(deps, options):
                return False

        metadata = 'HotSpot_Action:{0}'.format(hotspot if hotspot else '-')
        log_file = os.path.join(options.results_directory, '{0}{1}.xml'.format(file_name, '_' + hotspot if hotspot else ''))
        RobotTestSuite.log_files.append(log_file)
        return robot.run(self.path, runemptysuite=True, output=log_file, log=None, report=None, metadata=metadata, name=suite_name, variable=variables, noncritical=['non-critical', 'skipped'], exclude=options.exclude, test=[t[1] for t in test_cases]) == 0
Example #47
0
    def run_test(self, test_path, **options):

        self.options = options
        status = None

        # sets temp dir if outputdir not provided
        if 'outputdir' not in self.options:
            self.options['outputdir'] = self._get_outputdir(test_path)

        # removes output dir if exists
        if os.path.exists(self.options['outputdir']):
            shutil.rmtree(self.options['outputdir'])
        os.makedirs(self.options['outputdir'])

        # logs console output to file on ALM execution
        if self.alm:
            log_path = os.path.join(self.options['outputdir'], 'console.log')
            self.console_log = open(log_path, 'a')
            sys.__stdout__ = sys.__stderr__ = sys.stdout = self.console_log

        # runs robot tests
        try:
            status = robot.run(test_path, **self.options)
            if self.alm:
                self.alm['TDOutput'].Print(
                    'Test Execution Path: %s' % (test_path))
                self.alm['TDOutput'].Print(
                    'Robot Run Completed with %s status' % (status))
        except Exception, err:
            if self.alm:
                self.alm['TDOutput'].Print(
                    'Error while Robot Run: %s' % (str(err)))
            else:
                print str(err)
 def test_listener_gets_notification_about_log_report_and_output(self):
     listener = join(ROOT, 'utest', 'resources', 'Listener.py')
     assert_equals(run(self.data, output=OUTPUT_PATH, report=REPORT_PATH,
                       log=LOG_PATH, listener=listener), 1)
     self._assert_outputs(stdout=[('[output {0}]'.format(OUTPUT_PATH), 1),
                                  ('[report {0}]'.format(REPORT_PATH), 1),
                                  ('[log {0}]'.format(LOG_PATH), 1),
                                  ('[listener close]', 1)])
Example #49
0
def initialize_robot():
    '''
        Call this function first to import the robot code and
        start it up
    '''

    import robot
    return robot.run()
Example #50
0
def generate_suite_names_with_dryrun(outs_dir, datasources, options):
    opts = _options_for_dryrun(options, outs_dir)
    with _with_modified_robot():
        run(*datasources, **opts)
    output = os.path.join(outs_dir, opts['output'])
    suite_names = get_suite_names(output)
    if not suite_names:
        stdout_value = opts['stdout'].getvalue()
        if stdout_value:
            print("[STDOUT] from suite search:")
            print(stdout_value)
            print("[STDOUT] end")
        stderr_value = opts['stderr'].getvalue()
        if stderr_value:
            print("[STDERR] from suite search:")
            print(stderr_value)
            print("[STDERR] end")
    return list(sorted(set(suite_names)))
 def test_pre_rebot_modifier_as_instance(self):
     class Modifier(SuiteVisitor):
         def __init__(self):
             self.tests = []
         def visit_test(self, test):
             self.tests.append(test.name)
     modifier = Modifier()
     assert_equals(run(self.data, outputdir=TEMP, log=LOG_PATH, prerebotmodifier=modifier), 1)
     assert_equals(modifier.tests, ['Pass', 'Fail'])
     self._assert_outputs([('Pass       ', 1), ('Fail :: FAIL', 1)])
 def test_listener_gets_notification_about_log_report_and_output(self):
     listener = join(ROOT, "utest", "resources", "Listener.py")
     assert_equals(run(self.data, output=OUTPUT_PATH, report=REPORT_PATH, log=LOG_PATH, listener=listener), 1)
     self._assert_outputs(
         stdout=[
             ("[output {0}]".format(OUTPUT_PATH), 1),
             ("[report {0}]".format(REPORT_PATH), 1),
             ("[log {0}]".format(LOG_PATH), 1),
             ("[listener close]", 1),
         ]
     )
Example #53
0
def solve_suite_names(outs_dir, datasources, options, pabot_args):
    if 'suitesfrom' in pabot_args:
        return _suites_from_outputxml(pabot_args['suitesfrom'])
    opts = _options_for_dryrun(options, outs_dir)
    with _with_modified_robot():
        run(*datasources, **opts)
    output = os.path.join(outs_dir, opts['output'])
    suite_names = get_suite_names(output)
    if not suite_names:
        stdout_value = opts['stdout'].getvalue()
        if stdout_value:
            print("[STDOUT] from suite search:")
            print(stdout_value)
            print("[STDOUT] end")
        stderr_value = opts['stderr'].getvalue()
        if stderr_value:
            print("[STDERR] from suite search:")
            print(stderr_value)
            print("[STDERR] end")
    return sorted(set(suite_names))
Example #54
0
def worker_shop(context=None, masterip='localhost', port='', tests=''):
    """worker will say hi with task controller"""
    #worker_ip = get_ip()
    listener='listenerdemo.MultiListener:%s:%s' % (masterip, port)
    #identity = unicode(worker_ip)
    identity = u"%04x-%04x" % (randint(0, 0x10000), randint(0, 0x10000))
    context = context or zmq.Context.instance()
    # socket for running task
    worker = context.socket(zmq.REQ)
    # We use a string identity for ease here
    #zhelpers.set_id(worker)
    worker.setsockopt_string(zmq.IDENTITY, identity)
    worker.connect("tcp://%s:%s" % (masterip, port))
    # socket for control input
    controller = context.socket(zmq.SUB)
    cport = str(int(port) - 1)
    controller.connect("tcp://%s:%s" % (masterip, cport))
    controller.setsockopt(zmq.SUBSCRIBE, b"")
    # Process messages from maskter and controller
    poller = zmq.Poller()
    poller.register(worker, zmq.POLLIN)
    poller.register(controller, zmq.POLLIN)
    while True:
        # Tell the router we're ready for work
        worker.send('Ready')
        socks = dict(poller.poll())
        if socks.get(worker) == zmq.POLLIN:
            # Get workload from router, until finished
            tag = worker.recv()
            #print '\nthe tag name is: %s\n' % tag
            with open('stdout.txt', 'w') as stdout:
                run(tests,
                    loglevel='TRACE',
                    listener=listener,
                    output=tag,
                    stdout=stdout,
                    include=tag)
        # Any waiting controller command acts as 'KILL'
        if socks.get(controller) == zmq.POLLIN:
            break
 def run_tests(self):
     data = join(ROOT, "atest", "testdata", "misc", "pass_and_fail.robot")
     assert_equals(
         run(
             data,
             timestampoutputs=True,
             outputdir=TEMP,
             output="output-ts.xml",
             report="report-ts.html",
             log="log-ts",
         ),
         1,
     )
    def run_robot(path, **kw):

        # ToDo: fix it (_core not works correctly with multiprocessing)
        # import six
        # import allure_commons
        # if six.PY2:
        #     reload(allure_commons._core)
        # else:
        #     import importlib
        #     importlib.reload(allure_commons._core)
        #
        #

        from allure_robotframework import allure_robotframework

        listener = allure_robotframework(logger_path=tmp_path)
        stdout_file = os.path.abspath(os.path.join(tmp_path, "..", "stdout.txt"))
        output_path = os.path.abspath(os.path.join(tmp_path, ".."))

        with open(stdout_file, 'w+') as stdout:
            options = {"listener": listener, "outputdir": output_path, "stdout": stdout, "extension": "rst"}
            options.update(kw)
            run(path, **options)
    def run_pybot(self, tcfile=None):
        logger.debug(" ... in generic_testloader.run_pybot running [%s] ... " % tcfile)
        if tcfile == None:
            raise UnboundLocalError("Test case file name not defined!")
        import os
        from robot import run

        rc = run(
            tcfile,
            loglevel=os.getenv("ROBOT_SYSLOG_LEVEL"),
            outputdir=os.getenv("ROBOT_REPORTDIR"),
            debugfile=os.getenv("ROBOT_DEBUGFILE"),
        )
        assert rc == 0
        return rc
Example #58
0
 def test(self):
     """
     Create the Robot command and execute it.
     """
     suite_name, test_name = self._filename.split(':')[1].split('.')
     log_stdout = output.LoggingFile(loggers=[self.log], level=logging.INFO)
     log_stderr = output.LoggingFile(loggers=[self.log], level=logging.ERROR)
     result = run(self.filename,
                  suite=suite_name,
                  test=test_name,
                  outputdir=self.outputdir,
                  stdout=log_stdout,
                  stderr=log_stderr)
     if result:
         self.fail('Robot execution returned a '
                   'non-0 exit code (%s)' % result)
def run_robot(app, exception):
    # Get robot variables from environment
    env_robot_variables = get_robot_variables()
    env_robot_keys = [var.split(':')[0] for var in env_robot_variables]

    robot_dir = app.config.sphinxcontrib_robotframework_dir
    
    # Run the test suite:
    options = {
        'outputdir': robot_dir,
        'variable': env_robot_variables + [
            '%s:%s' % (key, value) for key, value
            in app.config.sphinxcontrib_robotframework_variables.items()
            if not key in env_robot_keys
        ]
    }

    if app.config.sphinxcontrib_robotframework_name:
        options['name'] = app.config.sphinxcontrib_robotframework_name

    result = robot.run(robot_dir, **options)
Example #60
0
    def run(self, *args):
        res = None
        #try:
        pybot_args = "".join(args[0])
        res = run(pybot_args)
        print(res)
        if self.auto_mode:
            if res != 0:
                GPIO.output(self.red_led, GPIO.HIGH)
            else:
                GPIO.output(self.green_led, GPIO.HIGH)
            time.sleep(15)
        else:
            if res != 0:
                GPIO.output(self.red_led, GPIO.HIGH)
            else:
                GPIO.output(self.green_led, GPIO.HIGH)
            input("Press enter to confirm that you've seen the result, disable this message with setting auto_mode=True")

        GPIO.output(self.red_led, GPIO.LOW)
        GPIO.output(self.green_led, GPIO.LOW)
        GPIO.cleanup()