Exemplo n.º 1
0
        def find_case_fullpath(node_id):
            nonlocal  temp_var
            query = "SELECT parent_id, text FROM `website_api_case_tree` WHERE id = %s"
            data = (node_id, )
            result = test_platform_db.select_one_record(query, data)

            if result[0] and result[1]:
                parent_id, text = result[1]
                temp_var = find_case_fullpath(parent_id) + '->' + text
                return temp_var
            elif result[0] and not result[1]:
                return temp_var
            else:
                logger.error('查询出错,退出程序')
                exit()
Exemplo n.º 2
0
 def query_element_selectors(self):
     try:
         result = test_platform_db.select_one_record(
             'SELECT selector1, selector2 FROM `website_page_element` WHERE  id = %s',
             (self.object_id, ))
         if result[0] and result[1]:
             record = result[1]
             return [True, record]
         elif result[0] and not result[1]:
             return [False, '未找到元素选择器']
         else:
             logger.error('查找元素选择器失败:%s' % result[1])
             return [False, '查找元素选择器失败:%s' % result[1]]
     except Exception as e:
         logger.error('%s' % e)
         return [False, '%s' % e]
Exemplo n.º 3
0
    def run(self, debug):
        try:
            if_plan_run_fail = False
            plan_id_list_for_failure = [] # 存放执行失败、未执行的测试计划的ID

            logger.info('======================正在同步更新与待运行测试计划关联的所有用例树节点信息======================')
            result = self.sync_case_tree_node_info_for_testplans()
            if not result[0]:
                logger.error('同步更新与待运行测试计划关联的所有用例树节点信息失败')
                return result
            else:
                logger.info('同步更新与待运行测试计划关联的所有用例树节点信息成功')

            for plan_id in self.plan_id_list:
                 logger.info('正在查询测试计划[ID:%s]相关信息' % plan_id)
                 result = test_platform_db.select_one_record('SELECT plan_name, browsers, valid_flag FROM `website_ui_test_plan` WHERE id = %s', (plan_id,))
                 if result[0] and result[1]:
                     plan_name, browsers, valid_flag = result[1]
                     browsers = browsers.rstrip(',').split(',')
                     if valid_flag == '启用':
                         logger.info('======================开始运行测试计划[名称:%s, ID:%s]======================' % (plan_name, plan_id))
                         test_plan = TestPlan(plan_id, plan_name, self.project_id, self.project_name, self.home_page, browsers)
                         result = test_plan.run(debug)
                         if not result[0]:
                             if_plan_run_fail = True
                             plan_id_list_for_failure.append(plan_id)
                     else:
                         logger.warn('测试计划已被禁用,跳过执行')
                         if_plan_run_fail = True
                         plan_id_list_for_failure.append(plan_id)
                         continue
                 elif result[0] and not result[1]:
                     logger.warn('运行失败:未查询到计划相关信息')
                     return [False, '运行失败:未查询到计划相关信息']
                 else:
                     return [False, '运行失败:%s' % result[1]]

            if if_plan_run_fail:
                return [False, '测试计划%s运行失败' % str(plan_id_list_for_failure)]
            else:
                return [True, '']
        except Exception as e:
            logger.error('%s' % e)
            return [False, '运行失败:%s' % e]
Exemplo n.º 4
0
    def run(self, debug):
        try:
            if_plan_run_fail = False
            plan_id_list_for_failure = [] # 存放执行失败、未执行的测试计划的ID及原因简介

            logger.info('======================正在同步更新与待运行测试计划关联的所有用例树节点信息======================')
            result = self.sync_case_tree_node_info_for_testplans()
            if not result[0]:
                logger.error('同步更新与待运行测试计划关联的所有用例树节点信息失败')
                return result
            else:
                logger.info('同步更新与待运行测试计划关联的所有用例树节点信息成功')

            for plan_id in self.plan_id_list:
                 logger.info('正在查询测试计划[ID:%s]相关信息' % plan_id)
                 result = test_platform_db.select_one_record('SELECT plan_name,valid_flag FROM `website_api_test_plan` WHERE id = %s', (plan_id,))
                 if result[0] and result[1]:
                     plan_name, valid_flag = result[1]
                     if valid_flag == '启用':
                         logger.info('======================开始运行测试计划[名称:%s, ID:%s]======================' % (plan_name, plan_id))
                         test_plan = TestPlan(plan_id, plan_name, self.project_id, self.project_name, self.protocol, self.host, self.port, self.global_headers)
                         result = test_plan.run(debug)
                         if not result[0]:
                             plan_id_list_for_failure.append('计划ID:%s,失败原因:%s   ' % (plan_id, result[1]))
                     else:
                         logger.warn('测试计划已被禁用,跳过执行')
                         plan_id_list_for_failure.append('计划ID:%s,失败原因:%s   ' % (plan_id, msg))
                         continue
                 elif result[0] and not result[1]:
                     logger.warn('运行失败:未查询到计划相关信息')
                     plan_id_list_for_failure.append('计划ID:%s,失败原因:%s   ' % (plan_id, msg))
                 else:
                     plan_id_list_for_failure.append('计划ID:%s,失败原因:%s   ' % (plan_id, result[1]))

            if plan_id_list_for_failure:
                return [False, '项目运行失败:%s' % ''.join(plan_id_list_for_failure)]
            else:
                return [True, '项目运行成功']
        except Exception as e:
            logger.error('%s' % e)
            return [False, '运行失败:%s' % e]
Exemplo n.º 5
0
    def sync_case_tree_node_info_for_testplans(self):
        temp_var = ''
        def find_case_fullpath(node_id):
            nonlocal  temp_var
            query = "SELECT parent_id, text FROM `website_api_case_tree` WHERE id = %s"
            data = (node_id, )
            result = test_platform_db.select_one_record(query, data)

            if result[0] and result[1]:
                parent_id, text = result[1]
                temp_var = find_case_fullpath(parent_id) + '->' + text
                return temp_var
            elif result[0] and not result[1]:
                return temp_var
            else:
                logger.error('查询出错,退出程序')
                exit()
        try:
            logger.info('待运行计划ID列表:%s' % self.plan_id_list)

            logger.info('正在查询与测试计划关联的用例树节点')
            if len(self.plan_id_list) == 1:
                plan_id_list = '(' + str(self.plan_id_list[0]) + ')'
            else:
                plan_id_list = str(tuple(self.plan_id_list))

            query = 'SELECT node_id FROM `website_api_case_tree_test_plan` WHERE plan_id IN ' + plan_id_list + ' GROUP BY node_id'
            data = ''
            result = test_platform_db.select_many_record(query, data)
            if result[0] and result[1]:
                records = result[1]

                result = [False, '没有找到测试计划关联的节点']
                for record in records:
                    logger.info('正在查找用例树节点信息')
                    # mysql 查询 count(NULL值) = 0
                    query = "SELECT t1.text, t1.parent_id, COUNT(t2.id) FROM `website_api_case_tree` AS t1 " \
                            "LEFT JOIN `website_api_case_tree` AS t2 ON t2.parent_id = t1.id WHERE t1.id = %s"
                    node_id = int(record[0])
                    data = (node_id,)
                    result = test_platform_db.select_one_record(query, data)

                    if result[0] and result[1]:
                        text, parent_id, sub_node_num = result[1]
                        sub_node_num = sub_node_num
                        node_path = (find_case_fullpath(parent_id) + '').lstrip('->')
                        logger.info('正在更新测试计划用例树节点关联表记录')
                        query = "UPDATE website_api_case_tree_test_plan SET node_path='%s', sub_node_num=%s WHERE plan_id IN %s AND node_id = %s"
                        data = (node_path, sub_node_num, plan_id_list, node_id)
                        result = test_platform_db.execute_update(query, data)
                        if not result[0]:
                            logger.error('更新测试计划用例树节点关联表记录失败:%s' % result[1])
                            return [False, result[1]]
                        else:
                            result = [True, '']
                    elif result[0] and not result[1]:
                        logger.warn('用例树节点 %s 不存在' % node_id)
                        continue
                    else:
                        logger.error('查询用例树节点[ID:%s]信息出错,退出程序' % node_id)
                        exit()
                    temp_var = ''
                return  result
            elif result[0] and not result[1]:
                logger.error('未查找到与测试计划关联的用例树节点')
                result = [False, '未查找到与测试计划关联的用例树节点']
            else:
                logger.error('查找与测试计划关联的用例树节点失败:%s' % result[1])
                result = [False,  '查找与测试计划关联的用例树节点失败:%s' % result[1]]
            return result
        except Exception as e:
            logger.error('%s' % e)
            result = [False, '同步更新与待运行测试计划关联的用例树节点信息失败:%s' % e]
            return result
Exemplo n.º 6
0
        running_plan_num = sys.argv[2]
        logger.info('当前运行计划编号为:%s' % running_plan_num)

        temp_var = sys.argv[3:4]
        if temp_var:
            if temp_var[0].lower() == 'debug':
                is_debug = True
        else:
            is_debug = False

        if run_mode.lower() == 'rop':
            logger.info('运行单项目,待执行的运行计划编码:%s' % running_plan_num)
            logger.info('正在查询运行计划相关信息')
            try:
                result = test_platform_db.select_one_record(
                    'SELECT running_plan_name,project_id, project_name, plan_name, plan_id, valid_flag '
                    'FROM `website_running_plan` WHERE running_plan_num =%s',
                    (running_plan_num, ))
                if result[0] and result[1]:
                    running_plan_name, project_id, project_name, plan_name, plan_id_list, valid_flag = result[
                        1]
                    plan_id_list = plan_id_list.split(',')  # 转字符串表示的list为列表
                    logger.info('待运行项目:名称:%s,ID:%s,关联的测试计划有:%s' %
                                (project_name, project_id, plan_name))
                    if valid_flag == '启用':
                        running_plan = RunningPlan(running_plan_num,
                                                   running_plan_name,
                                                   project_id, project_name,
                                                   plan_name, plan_id_list)
                        logger.info(
                            '======================开始执行运行计划[名称:%s]======================'
                            % running_plan_name)
Exemplo n.º 7
0
    def run(self, project_id, id):
        try:
            logger.info('正在查询项目[ID:%s]相关信息' % project_id)
            result = test_platform_db.select_one_record(
                'SELECT protocol, host, port, environment_id, valid_flag '
                'FROM `website_api_project_setting` WHERE id = %s',
                (project_id, ))
            if result[0] and result[1]:
                protocol, host, port, environment_id, valid_flag = result[1]

                logger.info('正在查询与项目关联的数据库信息')
                result = test_platform_db.select_many_record(
                    "SELECT db_type, db_alias, db_name, db_host, db_port, db_user, db_passwd "
                    "FROM `website_database_setting` "
                    "WHERE  locate('API%s', project_id) != 0 AND environment_id= '%s'"
                    % (project_id, environment_id))
                if result[0] and result[1]:
                    for record in result[1]:
                        db_type, db_alias, db_name, db_host, db_port, db_user, db_passwd = record
                        if db_type == 'MySQL':
                            mydb = MyDB(db_name=db_name,
                                        db_host=db_host,
                                        port=db_port,
                                        user=db_user,
                                        password=db_passwd,
                                        charset='utf8')
                            db_related_to_project_dic[db_alias] = mydb
                        elif db_type == 'Redis':
                            if not db_passwd.strip():
                                db_passwd = None
                            if db_name.strip() == '':
                                db_name = '0'
                            myredis = RedisClient(host=db_host,
                                                  port=db_port,
                                                  password=db_passwd,
                                                  db=db_name,
                                                  charset='utf-8')
                            redis_related_to_project_dic[db_alias] = myredis

                elif not result[0]:
                    logger.error('查询项目相关的数据库配置信息出错:%s' % result[1])
                    return [False, result[1]]

                logger.info('正在查询与项目关联的全局变量')
                result = test_platform_db.select_many_record(
                    "SELECT `name`, `value` "
                    "FROM `website_global_variable_setting` "
                    "WHERE  project_type='API项目' AND locate('%s', project_id) != 0 AND locate('%s', env_id) != 0 "
                    % (project_id, environment_id))
                if result[0] and result[1]:
                    for record in result[1]:
                        name, value = record
                        name = name
                        global_variable_dic[name] = value
                elif not result[0]:
                    logger.error('查询项目相关的全局变量配置信息出错:%s' % result[1])
                    return [False, result[1]]

                try:
                    if 'global_headers' in global_variable_dic.keys():
                        global_headers = global_variable_dic['global_headers']
                        # 防止用户输入了中文冒号,替换为英文冒号,不然经过global_headers.encode("utf-8").decode("latin1")这样编码转换,
                        # 会把"key":中的中文冒号解码为非英文冒号,导致执行json loads函数时会报错;
                        # 另外,请求头从数据库读取,可能涉及到换行符,需要去掉
                        global_headers = global_headers.replace(':',
                                                                ':').replace(
                                                                    '\t', '')
                        global_headers = json.loads(
                            global_headers, object_pairs_hook=OrderedDict)
                    else:
                        global_headers = {}
                except Exception as e:
                    logger.error('%s' % e)
                    return [False, '%s' % e]

                logger.info('正在查询输入ID标识的用例(套件)相关信息')
                query = 'SELECT id, text FROM `website_api_case_tree` WHERE project_id = %s AND id = %s' % (
                    project_id, id)
                result = test_platform_db.select_one_record(query)

                if result[0] and result[1]:
                    record = result[1]
                    case_id, case_name = record
                    execution_num = str(int(time.time()))  # 执行编号

                    query = 'SELECT id, text FROM `website_api_case_tree` WHERE project_id = %s AND parent_id = %s  ' \
                            'AND id NOT IN (SELECT parent_id FROM `website_api_case_tree` WHERE project_id=%s)' \
                            'ORDER BY `order` ASC' % (project_id, id, project_id)
                    result = test_platform_db.select_many_record(query)
                    if result[0] and result[1]:
                        logger.info('输入ID标识的是测试套件')
                        records = result[1]
                        for record in records:
                            case_id, case_name = record
                            test_case = TestCase(execution_num, 0, case_id,
                                                 '--', case_name, protocol,
                                                 host, port, global_headers)
                            logger.info(
                                '======================开始运行测试用例[名称:%s, ID:%s]======================'
                                % (case_name, case_id))
                            result = test_case.run(True)
                            if not result[0]:
                                return [
                                    False,
                                    '用例(ID:%s 名称:%s)运行出错:%s' %
                                    (case_id, case_name, result[2])
                                ]

                    elif result[0] and not result[1]:
                        logger.info('输入ID标识的是测试用例,开始执行用例')
                        test_case = TestCase(execution_num, 0, case_id, '--',
                                             case_name, protocol, host, port,
                                             global_headers)
                        logger.info(
                            '======================开始运行测试用例[名称:%s, ID:%s]======================'
                            % (case_name, case_id))
                        result = test_case.run(True)
                        if not result[0]:
                            return [
                                False,
                                '用例(ID:%s 名称:%s)运行出错:%s' %
                                (case_id, case_name, result[2])
                            ]
                    else:
                        logger.error('查询出错:%s' % result[1])
                        return [False, result[1]]
                elif result[0] and not result[1]:
                    reason = '未查找到相关信息,请检查配置的项目ID(%s),用例(套件)标识ID(%s)是否正确'
                    logger.warn(reason)
                    return [False, reason]
                else:
                    logger.error('查找相关信息失败:%s' % result[1])
                    return [False, '查找相关信息失败:%s' % result[1]]

            elif result[0] and not result[1]:
                logger.error('未查询到项目相关的信息')
                return [False, '未查询到项目相关的信息']
            else:
                logger.error('查询项目相关信息失败:%s' % result[1])
                return [False, '查询项目相关信息失败:%s' % result[1]]
        except Exception as e:
            logger.error('%s' % e)
            return [False, '%s' % e]
        finally:
            logger.info('正在释放资源')
            logger.info('正在断开与项目关联的数据库连接')
            # 关闭数据库
            for key, db in db_related_to_project_dic.copy().items():
                db.close()
                del db_related_to_project_dic[key]

            logger.info('正在清理与项目关联的全局变量')
            global_variable_dic.clear()
Exemplo n.º 8
0
    def run(self, debug):
        try:
            logger.info('正在查询项目[ID:%s,名称:%s]相关信息' %
                        (self.project_id, self.project_name))
            result = test_platform_db.select_one_record(
                'SELECT home_page, environment_id, valid_flag '
                'FROM `website_ui_project_setting` WHERE id = %s',
                (self.project_id, ))

            if result[0] and result[1]:
                home_page, environment_id, valid_flag = result[1]
                if valid_flag == '启用':
                    logger.info('正在查询与项目关联的数据库信息')
                    result = test_platform_db.select_many_record(
                        "SELECT db_type, db_alias, db_name, db_host, db_port, db_user, db_passwd "
                        "FROM `website_database_setting` "
                        "WHERE  locate('UI%s', project_id) != 0  AND environment_id= '%s'"
                        % (self.project_id, environment_id))
                    if result[0] and result[1]:
                        for record in result[1]:
                            db_type, db_alias, db_name, db_host, db_port, db_user, db_passwd = record
                            if db_type == 'MySQL':
                                mydb = MyDB(db_name=db_name,
                                            db_host=db_host,
                                            port=db_port,
                                            user=db_user,
                                            password=db_passwd,
                                            charset='utf8')
                                db_related_to_project_dic[db_alias] = mydb
                    elif not result[0]:
                        logger.error('查询项目相关的数据库配置信息出错:%s' % result[1])
                        return [False, '运行失败', result[1]]

                    logger.info('正在查询与项目关联的全局变量')
                    result = test_platform_db.select_many_record(
                        "SELECT `name`, `value` "
                        "FROM `website_global_variable_setting` "
                        "WHERE  project_type='UI项目' AND locate('%s', project_id) != 0 AND locate('%s', env_id) != 0 ",
                        (self.project_id, environment_id))
                    if result[0] and result[1]:
                        for record in result[1]:
                            name, value = record
                            name = name
                            global_variable_dic[name] = value
                    elif not result[0]:
                        logger.error('查询项目相关的全局变量配置信息出错:%s' % result[1])
                        return [False, '运行失败', result[1]]

                    try:
                        test_project = TestProject(self.project_id,
                                                   self.project_name,
                                                   home_page,
                                                   self.plan_id_list)
                        logger.info(
                            '======================开始运行测试项目[名称:%s, ID:%s]======================'
                            % (self.project_name, self.project_id))
                        result = test_project.run(debug)

                        if not result[0]:
                            result = [False, '运行失败', result[1]]
                        else:
                            result = [True, '运行成功', '']
                    except Exception as e:
                        logger.error('%s' % e)
                        result = [False, '运行失败', '%s' % e]
                else:
                    logger.warn('项目已被禁用,结束运行')
                    result = [False, '运行失败', '项目已被禁用,结束运行']
            elif result[0] and not result[1]:
                logger.error('未查询到项目相关的信息')
                result = [False, '运行失败', '未查询到项目相关的信息']
            else:
                logger.error('查询项目相关信息失败:%s' % result[1])
                result = [False, '运行失败', '查询项目相关信息失败:%s' % result[1]]
        except Exception as e:
            logger.error('%s' % e)
            result = [False, '运行失败', '%s' % e]
        finally:
            logger.info('正在释放资源')
            logger.info('正在断开与项目关联的数据库连接')
            # 关闭数据库
            for key, db in db_related_to_project_dic.copy().items():
                db.close()
                del db_related_to_project_dic[key]

            logger.info('正在清理与项目关联的全局变量')
            global_variable_dic.clear()
            return result
Exemplo n.º 9
0
    def run(self, debug):
        try:
            logger.info('正在查询项目[ID:%s,名称:%s]相关信息' %
                        (self.project_id, self.project_name))
            result = test_platform_db.select_one_record(
                'SELECT protocol, host, port, environment_id, valid_flag '
                'FROM `website_api_project_setting` WHERE id = %s',
                (self.project_id, ))
            if result[0] and result[1]:
                protocol, host, port, environment_id, valid_flag = result[1]
                if valid_flag == '启用':
                    logger.info('正在查询与项目关联的数据库信息')
                    result = test_platform_db.select_many_record(
                        "SELECT db_type, db_alias, db_name, db_host, db_port, db_user, db_passwd "
                        "FROM `website_database_setting` "
                        "WHERE locate('API%s', project_id) != 0 AND environment_id= '%s'"
                        % (self.project_id, environment_id))
                    if result[0] and result[1]:
                        for record in result[1]:
                            db_type, db_alias, db_name, db_host, db_port, db_user, db_passwd = record
                            if db_type == 'MySQL':
                                mydb = MyDB(db_name=db_name,
                                            db_host=db_host,
                                            port=db_port,
                                            user=db_user,
                                            password=db_passwd,
                                            charset='utf8')
                                db_related_to_project_dic[db_alias] = mydb
                            elif db_type == 'Redis':
                                if not db_passwd.strip():
                                    db_passwd = None
                                if db_name.strip() == '':
                                    db_name = '0'
                                myredis = RedisClient(host=db_host,
                                                      port=db_port,
                                                      password=db_passwd,
                                                      db=db_name,
                                                      charset='utf-8')
                                redis_related_to_project_dic[
                                    db_alias] = myredis
                    elif not result[0]:
                        logger.error('查询项目相关的数据库配置信息出错:%s' % result[1])
                        return [False, '运行失败', result[1]]

                    logger.info('正在查询与项目关联的全局变量')
                    result = test_platform_db.select_many_record(
                        "SELECT `name`, `value` "
                        "FROM `website_global_variable_setting` "
                        "WHERE  project_type='API项目' AND locate('%s', project_id) != 0 AND locate('%s', env_id) != 0 ",
                        (self.project_id, environment_id))
                    if result[0] and result[1]:
                        for record in result[1]:
                            name, value = record
                            name = name
                            global_variable_dic[name] = value
                    elif not result[0]:
                        logger.error('查询项目相关的全局变量配置信息出错:%s' % result[1])
                        return [False, '运行失败', result[1]]

                    try:
                        if 'global_headers' in global_variable_dic.keys():
                            global_headers = global_variable_dic[
                                'global_headers']
                            # 防止用户输入了中文冒号,替换为英文冒号,不然经过global_headers.encode("utf-8").decode("latin1")这样编码转换,
                            # 会把"key":中的中文冒号解码为非英文冒号,导致执行json loads函数时会报错;
                            # 另外,请求头从数据库读取,可能涉及到换行符,需要去掉
                            global_headers = global_headers.replace(
                                ':', ':').replace('\t', '')
                            global_headers = json.loads(
                                global_headers, object_pairs_hook=OrderedDict)

                        else:
                            global_headers = {}

                        test_project = TestProject(self.project_id,
                                                   self.project_name, protocol,
                                                   host, port, global_headers,
                                                   self.plan_id_list)
                        logger.info(
                            '======================开始运行测试项目[名称:%s, ID:%s]======================'
                            % (self.project_name, self.project_id))
                        result = test_project.run(debug)

                        if not result[0]:
                            result = [False, '运行失败', result[1]]
                        else:
                            result = [True, '运行成功', '']
                    except Exception as e:
                        logger.error('%s' % e)
                        result = [False, '运行失败', '%s' % e]
                else:
                    logger.warn('项目已被禁用,结束运行')
                    result = [False, '运行失败', '项目已被禁用,结束运行']
            elif result[0] and not result[1]:
                logger.error('未查询到项目相关的信息')
                result = [False, '运行失败', '未查询到项目相关的信息']
            else:
                logger.error('查询项目相关信息失败:%s' % result[1])
                result = [False, '运行失败', '查询项目相关信息失败:%s' % result[1]]
        except Exception as e:
            logger.error('%s' % e)
            result = [False, '运行失败', '%s' % e]
        finally:
            logger.info('正在释放资源')
            logger.info('正在断开与项目关联的数据库连接')
            # 关闭数据库
            for key, db in db_related_to_project_dic.copy().items():
                db.close()
                del db_related_to_project_dic[key]

            logger.info('正在清理与项目关联的全局变量')
            global_variable_dic.clear()
            return result
Exemplo n.º 10
0
    def run(self, project_id, id, browser):
        try:
            logger.info('正在查询项目[ID:%s]相关信息' % project_id)
            result = test_platform_db.select_one_record(
                'SELECT home_page, environment_id, valid_flag '
                'FROM `website_ui_project_setting` WHERE id = %s',
                (project_id, ))
            if result[0] and result[1]:
                home_page, environment_id, valid_flag = result[1]

                logger.info('正在查询与项目关联的数据库信息')
                result = test_platform_db.select_many_record(
                    "SELECT db_type, db_alias, db_name, db_host, db_port, db_user, db_passwd "
                    "FROM `website_database_setting` "
                    "WHERE  locate('UI%s', project_id) != 0  AND environment_id= '%s'"
                    % (project_id, environment_id))

                if result[0] and result[1]:
                    for record in result[1]:
                        db_type, db_alias, db_name, db_host, db_port, db_user, db_passwd = record
                        if db_type == 'MySQL':
                            mydb = MyDB(db_name=db_name,
                                        db_host=db_host,
                                        port=db_port,
                                        user=db_user,
                                        password=db_passwd,
                                        charset='utf8')
                            db_related_to_project_dic[db_alias] = mydb
                elif not result[0]:
                    logger.error('查询项目相关的数据库配置信息出错:%s' % result[1])
                    return [False, result[1]]

                logger.info('正在查询与项目关联的全局变量')
                result = test_platform_db.select_many_record(
                    "SELECT `name`, `value` "
                    "FROM `website_global_variable_setting` "
                    "WHERE  project_type='UI项目' AND locate('%s', project_id) != 0 AND locate('%s', env_id) != 0 "
                    % (self.project_id, environment_id))

                if result[0] and result[1]:
                    for record in result[1]:
                        name, value = record
                        name = name
                        global_variable_dic[name] = value
                elif not result[0]:
                    logger.error('查询项目相关的全局变量配置信息出错:%s' % result[1])
                    return [False, result[1]]

                host_port = re.findall(
                    '[https|http]+://[^/]+', home_page
                )  # 获取http地址 形如 http://www.baidu.com, http://www.baidu.com:8080
                if host_port:
                    host_port = host_port[0]
                else:
                    return [False, '项目主页填写错误']

                logger.info('正在查询输入ID标识的用例(套件)相关信息')
                query = 'SELECT id, text FROM `website_ui_case_tree` WHERE project_id = %s AND id = %s' % (
                    project_id, id)
                result = test_platform_db.select_one_record(query)

                logger.info('正在获取浏览器驱动')
                result_get = selenium_util.set_driver(browser)
                if not result_get[0]:
                    logger.error('获取浏览器驱动出错,退出')
                    exit()
                browser_driver = selenium_util.get_driver()

                logger.info('正在打开项目主页:%s' % home_page)
                selenium_util.maximize_window()
                selenium_util.get(home_page)
                selenium_util.implicitly_wait(20)
                try:
                    if result[0] and result[1]:
                        record = result[1]
                        case_id, case_name = record
                        execution_num = str(int(time.time()))  # 执行编号

                        query = 'SELECT id, text FROM `website_ui_case_tree` WHERE project_id = %s AND parent_id = %s  ' \
                                'AND id NOT IN (SELECT parent_id FROM `website_ui_case_tree` WHERE project_id=%s)' \
                                'ORDER BY `order` ASC' % (project_id, id, project_id)
                        result = test_platform_db.select_many_record(query)

                        if result[0] and result[1]:
                            logger.info('输入ID标识的是测试套件')
                            records = result[1]

                            for record in records:
                                case_id, case_name = record
                                test_case = TestCase(execution_num, 0, case_id,
                                                     '--', case_name,
                                                     host_port)
                                logger.info(
                                    '======================开始运行测试用例[名称:%s, ID:%s]======================'
                                    % (case_name, case_id))
                                result = test_case.run(True)
                                if not result[0]:
                                    return [
                                        False,
                                        '用例(ID:%s 名称:%s)运行出错:%s' %
                                        (case_id, case_name, result[2])
                                    ]
                        elif result[0] and not result[1]:
                            logger.info('输入ID标识的是测试用例,开始执行用例')
                            test_case = TestCase(execution_num, 0, case_id,
                                                 '--', case_name, host_port)
                            logger.info(
                                '======================开始运行测试用例[名称:%s, ID:%s]======================'
                                % (case_name, case_id))
                            result = test_case.run(True)
                            if not result[0]:
                                return [
                                    False,
                                    '用例(ID:%s 名称:%s)运行出错:%s' %
                                    (case_id, case_name, result[2])
                                ]
                        else:
                            logger.error('查询出错:%s' % result[1])
                            return [False, result[1]]
                    elif result[0] and not result[1]:
                        reason = '未查找到相关信息,请检查配置的项目ID(%s),用例(套件)标识ID(%s)是否正确'
                        logger.warn(reason)
                        return [False, reason]
                    else:
                        logger.error('查找相关信息失败:%s' % result[1])
                        return [False, '查找相关信息失败:%s' % result[1]]
                except Exception as e:
                    logger.error('运行出错:%s' % e)
                finally:
                    browser_driver.quit()
            elif result[0] and not result[1]:
                logger.error('未查询到项目相关的信息')
                return [False, '未查询到项目相关的信息']
            else:
                logger.error('查询项目相关信息失败:%s' % result[1])
                return [False, '查询项目相关信息失败:%s' % result[1]]
        except Exception as e:
            logger.error('%s' % e)
            return [False, '%s' % e]
        finally:
            logger.info('正在释放资源')
            logger.info('正在断开与项目关联的数据库连接')
            # 关闭数据库
            for key, db in db_related_to_project_dic.copy().items():
                db.close()
                del db_related_to_project_dic[key]

            logger.info('正在清理与项目关联的全局变量')
            global_variable_dic.clear()