示例#1
0
    def run_testsuite(self, http):
        logger.info('正在获取套件[id=%s,name=%s]的测试用例...' % (self.testsuite_id, self.testsuite_name))
        testcases_id_list_for_testsuit = self.get_testcases_id_for_testsuite()

        for testcase_id in testcases_id_list_for_testsuit[:]:
            testcase_info = mytestlink.getTestCase(testcase_id)  # 获取测试用例基本信息

            # 构造测试用例对象
            testcase_name = testcase_info[0]['name']
            testcase_steps = testcase_info[0]['steps']
            testcase_isactive = int(testcase_info[0]['active'])
            testcase_obj = TestCase(testcase_id, testcase_name, testcase_steps, testcase_isactive, self.project_name)


            sql_insert = 'INSERT INTO '+testcase_report_tb +'(executed_history_id, testcase_id, testcase_name, testsuit, testplan, project, runresult, runtime)' \
                         ' VALUES'
            testplan = '无计划'
            data = "('{}','{}','{}','{}','{}','{}', 'Block','{}')".format(executed_history_id,testcase_id,testcase_name,self.testsuite_name,testplan,self.project_name,time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
            logger.info('记录测试用例到到测试用例报表')
            sql = str(sql_insert) + str(data)
            testdb.execute_insert(sql)

            logger.info('开始执行测试用例[id=%s,name=%s]' % (testcase_id, testcase_name))
            run_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())  # 记录运行时间
            testcase_run_result = testcase_obj.run_testcase(http, testplan)

            logger.info('正在更新用例执行结果')
            sql_update = 'UPDATE '+testcase_report_tb +' SET runresult=\"%s\", runtime=\"%s\"' \
                         ' WHERE executed_history_id = %s and testcase_id = %s' \
                         ' AND project=\'%s\' AND testplan=\'%s\'' % \
                           (testcase_run_result, run_time, executed_history_id, testcase_id, self.project_name, testplan)
            testdb.execute_update(sql_update)

        logger.info('测试套件[id=%s ,name=%s]已执行完' % (self.testsuite_id, self.testsuite_name))
示例#2
0
文件: testplan.py 项目: dovelx/python
    def run_testplan(self, http):
        logger.info('正在获取测试计划[project=%s,name=%s]的测试用例' % (self.testproject, self.testplan_name))
        testcases_for_testplan = mytestlink.getTestCasesForTestPlan(self.testplan_id)
        if [] == testcases_for_testplan:
            logger.warning('未获取到测试用例')
            return
        testcases_id_for_testplan = testcases_for_testplan.keys()
        logger.info('成功获取测试计划[project=%s,name=%s]的测试用例id:%s' % (self.testproject, self.testplan_name, testcases_id_for_testplan))

        if 0 == self.active_status:
            logger.warning('测试计划[project=%s,name=%s]处于不活动状态[active=0],不执行' % (self.testproject, self.testplan_name))
            return

        for testcase_id_str in testcases_id_for_testplan:
            testcase_id = int(testcase_id_str)
            testcase_info = mytestlink.getTestCase(testcase_id)  # 获取测试用例基本信息

            # 构造测试用例对象
            testcase_name = testcase_info[0]['name']
            testcase_steps = testcase_info[0]['steps']
            testcase_isactive = int(testcase_info[0]['active'])
            testsuite_id = int(testcase_info[0]['testsuite_id'])
            testsuite_info = mytestlink.getTestSuiteByID(testsuite_id)
            testsuite_name = testsuite_info['name']
            testcase_obj = TestCase(testcase_id, testcase_name, testcase_steps, testcase_isactive, self.testproject)

            sql_insert = 'INSERT INTO '+testcase_report_tb +'(executed_history_id, testcase_id, testcase_name, testsuit, testplan, project, runresult, runtime)' \
                         ' VALUES(%s, %s, %s, %s, %s, %s, %s, %s)'
            data = (executed_history_id, testcase_id, str(testcase_name), testsuite_name, self.testplan_name, self.testproject, 'Block', '')
            logger.info('记录测试用例到测试用例报表')
            testdb.execute_insert(sql_insert, data)

            logger.info('开始执行测试用例[id=%s,name=%s]' % (testcase_id, testcase_name))
            run_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())  # 记录运行时间
            testcase_run_result = testcase_obj.run_testcase(http, self.testplan_name)

            logger.info('正在更新用例执行结果')
            sql_update = 'UPDATE '+testcase_report_tb +' SET runresult=\"%s\", runtime=\"%s\"' \
                        ' WHERE executed_history_id = %s AND testcase_id = %s' \
                        ' AND project=\'%s\' AND testplan=\'%s\'' % \
                        (testcase_run_result, run_time, executed_history_id, testcase_id, self.testproject, self.testplan_name)
            testdb.execute_update(sql_update)

            bulid_info = mytestlink.getLatestBuildForTestPlan(self.testplan_id) # 固定取最新的版本
            bulid_version = bulid_info['name']

            logger.info('正在更新testlink上测试计划[testplan_id=%s, bulid_version=%s],对应用例[testcase_id=%s]的执行结果'
                        % (self.testplan_id, bulid_version, testcase_id))
            notes = '用例[id:%s]在测试计划[testplan_id:%s,testplan_name:%s,bulidversion:%s]中的执行结果' \
                    % (testcase_id, self.testplan_id,self.testplan_name, bulid_version)
            if 'Fail' == testcase_run_result or 'Error' == testcase_run_result:
                self.__execute_case_in_testlink(testcase_id, bulid_version, 'f', notes) # f - 失败
            elif 'Pass' == testcase_run_result:
                self.__execute_case_in_testlink(testcase_id, bulid_version, 'p', notes) # f - 成功
            else:
                pass # 如果未执行,啥都不做,str(self.testplan_id)

        logger.info('测试计划[project=%s ,testplan=%s]已执行完' % (self.testproject, self.testplan_name))
示例#3
0
    def run_testsuite(self, http):
        logger.info('正在获取套件[id=%s,name=%s]的测试用例...' %
                    (self.testsuite_id, self.testsuite_name))
        testcases_id_list_for_testsuit = self.get_testcases_id_for_testsuite()

        logger.info('获取到用例id列表:%s', testcases_id_list_for_testsuit)

        for testcase_id in testcases_id_list_for_testsuit[:]:
            testcase_info = mytestlink.getTestCase(testcase_id)  # 获取测试用例基本信息
            logger.info('获取测试用例信息 %s' % testcase_info)

            # 构造测试用例对象
            testcase_name = testcase_info[0]['name']
            preconditions = testcase_info[0]['preconditions']
            if preconditions.find('isglobal') != -1:
                logger.info('用例[id=%s, name=%s]为全局初始化用例,已跳过执行' %
                            (testcase_id, testcase_name))
                continue

            testcase_steps = testcase_info[0]['steps']
            testcase_isactive = int(testcase_info[0]['active'])
            testcase_obj = TestCase(testcase_id, testcase_name, testcase_steps,
                                    testcase_isactive, self.project_name)

            # 获取测试套件名称
            logger.info(testcase_id)
            full_path = mytestlink.getFullPath(int(testcase_id))
            full_path = full_path[testcase_id]
            testsuite_name = ''
            for suit in full_path[1:]:
                testsuite_name = testsuite_name + '-' + suit
            testsuite_name = testsuite_name.lstrip('-')

            sql_insert = 'INSERT INTO '+testcase_report_tb +'(executed_history_id, testcase_id, testcase_name, testsuit, testplan, project, runresult, runtime)' \
                         ' VALUES(%s, %s, %s, %s, %s, %s, %s, %s)'
            testplan = '无计划'
            data = (executed_history_id, testcase_id, testcase_name,
                    testsuite_name, testplan, self.project_name, 'Block',
                    '0000-00-00 00:00:00')
            logger.info('记录测试用例到测试用例报表')
            testdb.execute_insert(sql_insert, data)

            logger.info('开始执行测试用例[id=%s,name=%s]' %
                        (testcase_id, testcase_name))
            run_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                     time.localtime())  # 记录运行时间
            testcase_run_result = testcase_obj.run_testcase(http, testplan)

            logger.info('正在更新用例执行结果')
            sql_update = 'UPDATE '+testcase_report_tb +' SET runresult=\"%s\", runtime=\"%s\"' \
                         ' WHERE executed_history_id = %s and testcase_id = %s' \
                         ' AND project=\'%s\' AND testplan=\'%s\''
            data = (testcase_run_result[0], run_time, executed_history_id,
                    testcase_id, self.project_name, testplan)
            testdb.execute_update(sql_update, data)

        logger.info('测试套件[id=%s ,name=%s]已执行完' %
                    (self.testsuite_id, self.testsuite_name))
示例#4
0
def run_testcase_by_id(testcase_id, httpobj=None, testplan='无计划'):
    try:
        testcase_info = mytestlink.getTestCase(testcase_id)  # 获取测试用例基本信息
        logger.info('获取测试用例信息 %s' % testcase_info)
    except Exception as e:
        logger.error('获取用例信息失败 %s,,暂停执行该用例' % e)
        return ('Fail',[('global_funtion_module','获取用例信息失败 %s' % e)])
    # 获取用例所在套件和项目名称
    response = mytestlink.getFullPath([int(testcase_id)])
    response = response[str(testcase_id)]
    testsuite_name = ''
    for suit in response[1:]:
        testsuite_name = testsuite_name + '-' + suit
        testsuite_name = testsuite_name.lstrip('-')
    project_name = response[0]

    # 构造测试用例对象
    testcase_name = testcase_info[0]['name']
    testcase_steps = testcase_info[0]['steps']
    testcase_isactive = int(testcase_info[0]['active'])
    testsuite_id = int(testcase_info[0]['testsuite_id'])
    preconditions = testcase_info[0]['preconditions']
    tc_external_id = testcase_info[0]['full_tc_external_id']
    testcase_obj = TestCase(testcase_id, testcase_name, testcase_steps, testcase_isactive, project_name, testsuite_id, tc_external_id, preconditions)
    if httpobj:
        myhttp = httpobj
    else:
        myhttp = get_http_conf_of_project(project_name)
        if not myhttp:
            logger.critical('用例所在项目配置存在问题,停止执行该用例')
            return ('Block',[('golbal_function_module', '用例所在项目配置存在问题,停止执行该用例')])
    try:
        sql_insert = 'INSERT INTO '+testcase_report_tb +'(executed_history_id, testcase_id, testcase_name, testsuit, testplan, project, runresult, runtime, tc_external_id)' \
                                                        ' VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)'
        data = (executed_history_id, testcase_id, testcase_name, testsuite_name, testplan, project_name, 'Block','0000-00-00 00:00:00', tc_external_id)
        logger.info('记录测试用例到测试用例报表')
        testdb.execute_insert(sql_insert, data)

        logger.info('开始执行测试用例[id=%s,name=%s]' % (testcase_id, testcase_name))
        run_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())  # 记录运行时间
        case_executed_history_id = time.strftime('%Y%m%d%H%M%S', time.localtime())  # 流水记录编号
        testcase_run_result = testcase_obj.run_testcase(myhttp, testplan, case_executed_history_id)

        logger.info('正在更新用例执行结果')
        sql_update = 'UPDATE '+testcase_report_tb +' SET runresult=\"%s\", runtime=\"%s\",' \
                                                   ' case_exec_history_id=\"%s\"' \
                                                   ' WHERE executed_history_id = %s and testcase_id = %s' \
                                                   ' AND project=\'%s\' AND testplan=\'%s\''
        data = (testcase_run_result[0], run_time, str(case_executed_history_id), executed_history_id, testcase_id, project_name, testplan)
        testdb.execute_update(sql_update, data)

        logger.info('指定用例[%s]已执行完' % testcase_name)

        return testcase_run_result
    except Exception as e:
        logger.error('运行用例出错 %s' % e)
        return ('Fail',[('golbal_function_module', '%s' % e)])
示例#5
0
    def run_testsuite(self, http):
        logger.info('正在获取套件[id=%s,name=%s]的测试用例...' %
                    (self.testsuite_id, self.testsuite_name))
        testcases_id_list_for_testsuit = self.get_testcases_id_for_testsuite()

        for testcase_id in testcases_id_list_for_testsuit[:]:
            testcase_info = mytestlink.getTestCase(testcase_id)  # 获取测试用例基本信息
            #debug by david
            logger.info("测试用例信息%s" % testcase_info)
            # 构造测试用例对象

            testcase_name = testcase_info[0]['name']
            testcase_steps = testcase_info[0]['steps']
            #testcase_steps = testcase_steps[0]["actions"]
            testcase_isactive = int(testcase_info[0]['active'])
            #调试用by david
            #logger.info('输出用例信息 =====step===david========%s'%testcase_info)
            #处理测试用例的步骤
            #other_tools = OtherTools()
            #testcase_steps = other_tools.conver_date_from_testlink(testcase_steps)
            #示例testsuite_details = other_tools.conver_date_from_testlink(testsuite_info['details'])
            #logger.info('输出用例信息 ===处理后=====david========%s' % testcase_steps)

            testcase_obj = TestCase(testcase_id, testcase_name, testcase_steps,
                                    testcase_isactive, self.project_name)




            sql_insert = 'INSERT INTO '+testcase_report_tb +'(executed_history_id, testcase_id, testcase_name, testsuit, testplan, project, runresult, runtime)' \
                         ' VALUES(%s, %s, %s, %s, %s, %s, %s, %s)'
            testplan = '无计划'
            #MODIFY BY DAVID BLOCK TO PASS
            data = (executed_history_id, testcase_id, testcase_name,
                    self.testsuite_name, testplan, self.project_name, 'PASS',
                    '')
            logger.info('记录测试用例到到测试用例报表')
            testdb.execute_insert(sql_insert, data)

            logger.info('开始执行测试用例[id=%s,name=%s]' %
                        (testcase_id, testcase_name))
            run_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                     time.localtime())  # 记录运行时间
            testcase_run_result = testcase_obj.run_testcase(http, testplan)

            logger.info('正在更新用例执行结果')
            sql_update = 'UPDATE '+testcase_report_tb +' SET runresult=\"%s\", runtime=\"%s\"' \
                         ' WHERE executed_history_id = %s and testcase_id = %s' \
                         ' AND project=\'%s\' AND testplan=\'%s\'' % \
                           (testcase_run_result, run_time, executed_history_id, testcase_id, self.project_name, testplan)
            testdb.execute_update(sql_update)

        logger.info('测试套件[id=%s ,name=%s]已执行完' %
                    (self.testsuite_id, self.testsuite_name))
def run_testcase_by_id(testcase_id, testplan='无计划'):
    try:
        testcase_info = mytestlink.getTestCase(testcase_id)  # 获取测试用例基本信息
        logger.info('获取测试用例信息 %s' % testcase_info)
    except Exception as e:
        logger.error('获取用例信息失败 %s,,暂停执行该用例' % e)
        return ('Fail', [('global_funtion_module', '获取用例信息失败 %s' % e)])
    # 获取用例所在套件和项目名称
    response = mytestlink.getFullPath([int(testcase_id)])
    response = response[str(testcase_id)]
    testsuite_name = ''
    for suit in response[1:]:
        testsuite_name = testsuite_name + '-' + suit
        testsuite_name = testsuite_name.lstrip('-')
    project_name = response[0]

    # 构造测试用例对象
    testcase_name = testcase_info[0]['name']
    testcase_steps = testcase_info[0]['steps']
    testcase_isactive = int(testcase_info[0]['active'])
    testcase_obj = TestCase(testcase_id, testcase_name, testcase_steps,
                            testcase_isactive, project_name)

    testsuite_id = int(testcase_info[0]['testsuite_id'])
    logger.info('正在读取套件[id=%s]的协议,host,端口配置...' % (testsuite_id))

    testsuite_info = mytestlink.getTestSuiteByID(testsuite_id)
    testsuite_name = testsuite_info['name']
    testsuite_details = other_tools.conver_date_from_testlink(
        testsuite_info['details'])
    project = mytestlink.getFullPath(testsuite_id)
    project = project[str(testsuite_id)][0]
    testsuite_obj = TestSuite(testsuite_id, testsuite_name, testsuite_details,
                              project)
    testsuite_conf = testsuite_obj.get_testsuite_conf()  # 获取套件基本信息
    if '' == testsuite_conf:
        logger.error('测试套件[id=%s ,name=%s]未配置协议,host,端口信息,暂时无法执行' %
                     (testsuite_id, testsuite_name))
        return ('Fail', [('golbal_function_module',
                          '测试套件[id=%s ,name=%s]未配置协议,host,端口信息,暂时无法执行' %
                          (testsuite_id, testsuite_name))])

    try:
        details = json.loads(testsuite_conf)
        protocol = details['protocol']
        host = details['host']
        port = details['port']
    except Exception as e:
        logger.error('测试套件[id=%s ,name=%s]协议,host,端口信息配置错误,未执行:%s' %
                     (testsuite_id, testsuite_name, e))
        return ('Fail', [('golbal_function_module',
                          '测试套件[id=%s ,name=%s]协议,host,端口信息配置错误,未执行:%s' %
                          (testsuite_id, testsuite_name, e))])

    # 构造http对象
    myhttp = MyHttp(protocol, host, port)

    try:
        sql_insert = 'INSERT INTO '+testcase_report_tb +'(executed_history_id, testcase_id, testcase_name, testsuit, testplan, project, runresult, runtime)' \
                                                        ' VALUES(%s, %s, %s, %s, %s, %s, %s, %s)'
        data = (executed_history_id, testcase_id, testcase_name,
                testsuite_name, testplan, project_name, 'Block',
                '0000-00-00 00:00:00')
        logger.info('记录测试用例到测试用例报表')
        testdb.execute_insert(sql_insert, data)

        logger.info('开始执行测试用例[id=%s,name=%s]' % (testcase_id, testcase_name))
        run_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                 time.localtime())  # 记录运行时间
        testcase_run_result = testcase_obj.run_testcase(myhttp, testplan)

        logger.info('正在更新用例执行结果')
        sql_update = 'UPDATE '+testcase_report_tb +' SET runresult=\"%s\", runtime=\"%s\"' \
                                                   ' WHERE executed_history_id = %s and testcase_id = %s' \
                                                   ' AND project=\'%s\' AND testplan=\'%s\''
        data = (testcase_run_result[0], run_time, executed_history_id,
                testcase_id, project_name, testplan)
        testdb.execute_update(sql_update, data)

        logger.info('指定用例[%s]已执行完' % testcase_id)

        return testcase_run_result
    except Exception as e:
        logger.error('运行用例出错 %s' % e)
        return ('Fail', [('golbal_function_module', '%s' % e)])