Exemplo n.º 1
0
def execute_steps(step_list, data_repository, system_name, parallel, queue):
    """Executes the teststep(provided as a xml test case)"""
    default_error_action = data_repository['wt_def_on_error_action']
    default_error_value = data_repository['wt_def_on_error_value']

    goto_stepnum        = False
    kw_resultfile_list  = []
    step_status_list    = []
    step_impact_list    = []
    step_num            = 0

    if parallel is True:
        system_console_log = get_system_console_log(data_repository['wt_filename'],
                                                    data_repository['wt_logsdir'],
                                                    '{0}_consoleLogs'.format(system_name))
    while step_num < len(step_list):
        step = step_list[step_num]
        # execute steps
        step_num += 1

        if not goto_stepnum:
            try:
                result = step_driver.main(step, step_num, data_repository, system_name)
                step_status = result[0]
                kw_resultfile = result[1]
                step_impact = result[2]
                exec_type_onerror = result[3]
                # print "exec_type_onerror:", exec_type_onerror

            except Exception, e:
                print_error('unexpected error %s' % str(e))
                step_status = False
                kw_resultfile = None
                step_impact = Utils.testcase_Utils.get_impact_from_xmlfile(step)
                print_error('unexpected error {0}'.format(traceback.format_exc()))

        elif (goto_stepnum and goto_stepnum == str(step_num)):
                try:
                    result = step_driver.main(step, step_num, data_repository, system_name)
                    step_status = result[0]
                    kw_resultfile = result[1]
                    step_impact = result[2]
                    exec_type_onerror = result[3]
                    # print "exec_type_onerror:", exec_type_onerror

                except Exception,e:
                    print_error('unexpected error %s' % str(e))
                    step_status = False
                    kw_resultfile = None
                    step_impact = Utils.testcase_Utils.get_impact_from_xmlfile(step)
                    print_error('unexpected error {0}'.format(traceback.format_exc()))
 def _execute_current_step(self):
     """
     This function actually executes a given step and returns necessary details about that step.
     """
     try:
         result = step_driver.main(self.current_step,
                                   self.current_step_number,
                                   self.data_repository,
                                   self.system_name,
                                   skip_invoked=self.skip_invoked)
         step_status = result[0]
         kw_resultfile = result[1]
         step_impact = result[2]
     except Exception as e:
         print_error('unexpected error %s' % str(e))
         step_status = False
         kw_resultfile = None
         step_impact = Utils.testcase_Utils.get_impact_from_xmlfile(
             self.current_step)
         print_error('unexpected error {0}'.format(traceback.format_exc()))
     self.go_to_step_number = False
     self.step_status_list, self.step_impact_list = \
         common_execution_utils.compute_status(self.current_step,
                                               self.step_status_list,
                                               self.step_impact_list,
                                               step_status, step_impact)
     self.kw_resultfile_list.append(kw_resultfile)
     return step_status
    def _execute_step(self, system_executed, step_num, index, goto_stepnum):
        """
        """
        print_info("\n")
        result = (None, None, None, None)

        if not self.execute_endoftc:

            # once_per_tc
            if self.iter_type_list[index] == "once_per_tc":
                self._print_step_details(step_num, self.iter_type_list[index],
                                         system_executed)
                # if not already executed, execute now
                if self.executed_or_not_list[index] == "no":
                    result = step_driver.main(self.step_list[index], step_num,
                                              self.data_repository,
                                              system_executed)
                    self.executed_or_not_list[index] = "yes"
                # if already executed, skip now
                elif self.executed_or_not_list[index] == "yes":
                    pNote("step iter_type is 'once_per_testcase and has "
                          "already been executed, hence skipping'")
                    result = self._update_skip_results(self.step_list[index],
                                                       system_executed,
                                                       step_num)

            # if standard, execute it
            elif self.iter_type_list[index] == "standard":
                self._print_step_details(step_num, self.iter_type_list[index],
                                         system_executed)
                result = step_driver.main(self.step_list[index], step_num,
                                          self.data_repository,
                                          system_executed)

            # if end_of_tc, skip it
            elif all(
                [self.iter_type_list[index] == "end_of_tc", not goto_stepnum]):
                self._print_step_details(step_num, self.iter_type_list[index],
                                         system_executed)
                pNote("step iter_type={0} and will be executed at the end of "
                      "the testcase, hence skipping now".format(
                          self.iter_type_list[index]))
                result = self._update_skip_results(self.step_list[index],
                                                   system_executed, step_num)

            elif self.iter_type_list[index] == "end_of_tc" and goto_stepnum:
                pNote("Goto step is of iter_type='end_of_tc', will execute all"
                      " end_of_tc_steps from here and complete execution")
                self._print_step_details(step_num, self.iter_type_list[index],
                                         system_executed)
                result = step_driver.main(self.step_list[index], step_num,
                                          self.data_repository,
                                          system_executed)
                self.execute_endoftc = True
                self.stop_after_current_iteration = True

        elif self.execute_endoftc:
            self._print_step_details(step_num, self.iter_type_list[index],
                                     system_executed)

            # if end_of_tc, execute it.
            if self.iter_type_list[index] == "end_of_tc":
                result = step_driver.main(self.step_list[index], step_num,
                                          self.data_repository,
                                          system_executed)
            # if iter_type=once_per_tc or standard skip it.
            else:
                pNote("Now executing only end_of_tc steps hence skipping "
                      "step={0} with iter_type={1}".format(
                          step_num, self.iter_type_list[index]))
                result = self._update_skip_results(self.step_list[index],
                                                   system_executed, step_num)

        return result
def execute_steps(step_list, data_repository, system_name, parallel, queue):
    """
        Take in a list of steps
        iterate through each of them and decide if each should run (pre-run check)
        get status and report to term and log
    """
    default_error_action = data_repository['wt_def_on_error_action']
    default_error_value = data_repository['wt_def_on_error_value']

    goto_stepnum = False
    kw_resultfile_list = []
    step_status_list = []
    step_impact_list = []
    step_num = 0

    if parallel is True:
        system_console_log = get_system_console_log(
            data_repository['wt_filename'], data_repository['wt_logsdir'],
            '{0}_consoleLogs'.format(system_name))
    while step_num < len(step_list):
        step = step_list[step_num]
        # execute steps
        step_num += 1

        run_current_step = False
        # Decide whether or not to execute keyword
        # First decide if this step should be executed in this iteration
        if not goto_stepnum or goto_stepnum == str(step_num):
            # get Exectype information
            run_current_step, trigger_action = exec_type_driver.main(step)
            if not run_current_step:
                keyword = step.get('Keyword')
                kw_resultfile = step_driver.get_keyword_resultfile(
                    data_repository, system_name, step_num, keyword)
                Utils.config_Utils.set_resultfile(kw_resultfile)
                Utils.testcase_Utils.pKeyword(keyword, step.get('Driver'))
                Utils.testcase_Utils.reportStatus('Skip')
                kw_resultfile_list.append(kw_resultfile)
                data_repository['wt_junit_object'].update_count(
                    "skipped", "1", "tc", data_repository['wt_tc_timestamp'])
                data_repository['wt_junit_object'].update_count(
                    "keywords", "1", "tc", data_repository['wt_tc_timestamp'])
                kw_start_time = Utils.datetime_utils.get_current_timestamp()
                step_impact = Utils.testcase_Utils.get_impact_from_xmlfile(
                    step)
                impact_dict = {"IMPACT": "Impact", "NOIMPACT": "No Impact"}
                data_repository['wt_junit_object'].add_keyword_result(
                    data_repository['wt_tc_timestamp'], step_num, keyword,
                    "SKIPPED", kw_start_time, "0", "skipped",
                    impact_dict.get(step_impact.upper()), "N/A")
                data_repository['step_{}_result'.format(step_num)] = "SKIPPED"

                if trigger_action.upper() in ['ABORT', 'ABORT_AS_ERROR']:
                    break
                elif trigger_action.upper() in ['SKIP', 'NEXT']:
                    continue
                # when 'onError:goto' value is less than the current step num,
                # change the next iteration point to goto value
                elif trigger_action and int(trigger_action) < step_num:
                    step_num = int(trigger_action) - 1
                    trigger_action = False

                continue

        if not goto_stepnum:
            try:
                result = step_driver.main(step, step_num, data_repository,
                                          system_name)
                step_status = result[0]
                kw_resultfile = result[1]
                step_impact = result[2]

            except Exception, e:
                print_error('unexpected error %s' % str(e))
                step_status = False
                kw_resultfile = None
                step_impact = Utils.testcase_Utils.get_impact_from_xmlfile(
                    step)
                print_error('unexpected error {0}'.format(
                    traceback.format_exc()))

        elif goto_stepnum and goto_stepnum == str(step_num):
            try:
                result = step_driver.main(step, step_num, data_repository,
                                          system_name)
                step_status = result[0]
                kw_resultfile = result[1]
                step_impact = result[2]

            except Exception, e:
                print_error('unexpected error %s' % str(e))
                step_status = False
                kw_resultfile = None
                step_impact = Utils.testcase_Utils.get_impact_from_xmlfile(
                    step)
                print_error('unexpected error {0}'.format(
                    traceback.format_exc()))