Example #1
0
    def run_testproject(self, http):
        logger.info('正在获取测试项目[id:%s, name:%s]对应对应的测试计划名称列表' % (self.project_id, self.name))
        testplans_name_list = []
        testplans = mytestlink.getProjectTestPlans(self.project_id)
        for testplan in testplans:
            testplans_name_list.append(testplan['name'])
        logger.info('成功获取项目测试计划名称列表[list=%s]' % testplans_name_list)

        for testplan in testplans_name_list:
            testplan_info = mytestlink.getTestPlanByName(self.name, testplan)
            testplan_name = testplan_info[0]['name']
            testplan_id = int(testplan_info[0]['id'])
            active_status = int(testplan_info[0]['active'])
            notes = other_tools.conver_date_from_testlink(testplan_info[0]['notes'])
            testplan_obj = TestPlan(testplan_name, testplan_id, active_status, notes, self.name)

            logger.info('正在执行项目测试计划[project:%s,testplan:%s]' % (self.name, testplan))
            testplan_obj.run_testplan(http)
Example #2
0
    logger.info('正在读取运行模式配置')
    run_mode_conf = RunModeConfig('./config/runmodeconfig.conf')
    run_mode = int(run_mode_conf.get_run_mode())

    if 1 == run_mode:
        logger.info('按项目运行测试')
        project_mode = run_mode_conf.get_project_mode()
        testplans_name_list = []
        if 1 == project_mode:
            logger.info('运行所有项目')
            projects = mytestlink.getProjects()
            for project in projects:
                # 构造项目对象
                active_status = project['active']
                project_name = project['name']
                project_notes = other_tools.conver_date_from_testlink(
                    project['notes'])
                project_id = int(project['id'])
                project_obj = TestProject(active_status, project_name,
                                          project_notes, project_id)

                logger.info('正在读取测项目[id:%s, project:%s]的协议,host,端口配置...' %
                            (project_id, project_name))
                testproject_conf = project_notes

                logger.info('成功读取配置信息:%s' % testproject_conf)
                if '' == testproject_conf:
                    logger.error(
                        '测试项目[id:%s, project:%s]未配置协议,host,端口信息,暂时无法执行' %
                        (project_id, project_name))
                    continue
Example #3
0
    def run_testcase(self, http, testplan):
        if 0 == self.active_status:
            logger.warning('用例[name=%s]处于禁用状态[active=0],不执行' % self.testcase_name)
            return 'Block'

        protocol_all = http.get_protocol()
        host_all = http.get_host()
        port_all = http.get_port()

        for step in self.steps:
            # 构造测试步骤对象
            step_id = int(step['id'])
            step_number = int(step['step_number'])
            step_action = other_tools.conver_date_from_testlink(step['actions'])
            expected_results = other_tools.conver_date_from_testlink(step['expected_results'])

            logger.debug('step_action: %s' % step_action)

            sql_insert = 'INSERT INTO '+ case_step_report_tb +'(executed_history_id, testcase_id, testcase_name, testplan, project, step_id, step_num, protocol_method, protocol, host, port, ' \
                                                               'step_action, expected_results, runresult, reason, runtime)' \
                         ' VALUES'
            data = "('{}','{}','{}','{}','{}','{}','{}', '','{}','{}','{}','{}','{}', 'Block', '', '{}')".format(executed_history_id,self.testcase_id,self.testcase_name,testplan,self.testproject,step_id,step_number,protocol_all,host_all,port_all,step_action,expected_results,time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

            logger.info('记录测试步骤到测试步骤报告表')
            sql = str(sql_insert) + str(data)
            testdb.execute_insert(sql)


            try:
                expected_results = json.loads(expected_results)
                step_action = json.loads(step_action)
                step_obj = CaseStep(step_id, step_number, expected_results, step_action, self.testcase_id)
                protocol_method = step_action['method']
            except Exception as e:
                logger.error('步骤[%s]信息填写错误: %s,停止执行用例[id=%s, name=%s]' % (step_number, e, self.testcase_id, self.testcase_name))
                return 'Error'

            logger.info('开始执行步骤操作[第%s步]'% step_number)
            run_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())  # 记录运行时间
            step_run_result = step_obj.run_step(http)

            if step_run_result[0] == 'Error':
                fail_or_error_reason = step_run_result[1][0][1]
                fail_or_error_reason = fail_or_error_reason.replace('\n', '')
                fail_or_error_reason = fail_or_error_reason.replace('\"', '')
                fail_or_error_reason = fail_or_error_reason.replace('\'', '')
                logger.error('步骤[%s]执行出错,停止执行用例[id=%s, name=%s]' % (step_number, self.testcase_id, self.testcase_name))
                sql_update = 'UPDATE '+ case_step_report_tb +' SET runresult=\"%s\",reason=\"%s\", protocol_method=\"%s\", runtime=\"%s\"' \
                             ' WHERE executed_history_id = %s AND testcase_id = %s AND step_id = %s'\
                             ' AND project=\'%s\' AND testplan=\'%s\'' % \
                              (step_run_result[0], fail_or_error_reason, protocol_method, run_time, str(executed_history_id), self.testcase_id, step_id,
                                 self.testproject, testplan)
                logger.info('正在更新步骤执行结果')
                testdb.execute_update(sql_update)
                return 'Error'
            elif step_run_result[0] == 'Fail':
                fail_or_error_reason = step_run_result[1][0][1]
                fail_or_error_reason = fail_or_error_reason.replace('\n', '')
                fail_or_error_reason = fail_or_error_reason.replace('\"', '')
                fail_or_error_reason = fail_or_error_reason.replace('\'', '')
                logger.info('步骤[%s]执行失败,停止执行用例[id=%s, name=%s]' % (step_number, self.testcase_id, self.testcase_name))
                sql_update = 'UPDATE '+ case_step_report_tb +' SET runresult=\"%s\",reason=\"%s\", protocol_method=\"%s\", runtime=\"%s\"' \
                             ' WHERE executed_history_id = %s AND testcase_id = %s AND step_id = %s'\
                             ' AND project=\'%s\' AND testplan=\'%s\'' % \
                              (step_run_result[0], fail_or_error_reason, protocol_method, run_time, str(executed_history_id), self.testcase_id, step_id,
                                 self.testproject, testplan)
                testdb.execute_update(sql_update)
                return 'Fail'
            else:
                fail_or_error_reason = ''
                sql_update = 'UPDATE '+ case_step_report_tb +' SET runresult=\"%s\",reason=\"%s\", protocol_method=\"%s\", runtime=\"%s\"' \
                             ' WHERE executed_history_id = %s AND testcase_id = %s AND step_id = %s'\
                             ' AND project=\'%s\' AND testplan=\'%s\'' % \
                              (step_run_result[0], fail_or_error_reason, protocol_method, run_time, str(executed_history_id), self.testcase_id, step_id,
                                 self.testproject, testplan)
                logger.info('正在更新步骤执行结果')
                testdb.execute_update(sql_update)

        logger.info('测试用例[id=%s, name=%s]执行成功' % (self.testcase_id, self.testcase_name))
        return 'Pass'
Example #4
0
        logger.info('按套件运行测试')
        testsuits_id_list = run_mode_conf.get_testsuits()
        logger.info('已获取配置的套件id列表:%s' % testsuits_id_list)

        testsuits_id_list = eval(testsuits_id_list)
        for testsuite_id in testsuits_id_list:
            # 构造测试套件对象
            try:
                testsuite_info = mytestlink.getTestSuiteByID(testsuite_id)
            except Exception as e:
                logger.error('测试套件[id=%s]不存在,暂时无法执行' % testsuite_id)
                continue
            testsuite_name = testsuite_info['name']

            print("testsuitename=%s"%testsuite_name)
            testsuite_details = other_tools.conver_date_from_testlink(testsuite_info['details'])
            print ("testsuite_details=%s"%testsuite_details)
            project = mytestlink.getFullPath(testsuite_id)
            print("project1=%s"%project)
            project = project[str(testsuite_id)][0]
            print("project2=%s" % project)
            testsuite_obj = TestSuite(testsuite_id, testsuite_name, testsuite_details, project)
            print("testsuite_obj=%s"%testsuite_obj)
            logger.info('正在读取套件[id=%s,name=%s]的协议,host,端口配置...' % (testsuite_id, testsuite_name))
            testsuite_conf = testsuite_obj.get_testsuite_conf()  # 获取套件基本信息
            print ("testsuite_conf=%s"%testsuite_conf)
            if '' == testsuite_conf:
                logger.error('测试套件[id=%s ,name=%s]未配置协议,host,端口信息,暂时无法执行' % (testsuite_id, testsuite_name))
                continue

            try: