Ejemplo n.º 1
0
 def run_case(self):
     rows = excel_data.get_rows()
     for i in range(rows):
         # i是从0开始的,excel中第一行内容的行号是i=2
         data = excel_data.get_rows_value(i + 2)
         #['imooc_001', '登录', 'yes', 'create_user', '/login/', 'post', '{"username":"******"}', 'yes', 'message', None]
         is_run = data[2]
         except_method = data[10]
         except_result = data[11]
         if is_run == "yes":
             url = data[5]
             method = data[6]
             data1 = data[7]
             res = request.run_main(method, url, data1)
             #int和str无法比较,需要强转一下
             code = str(res['errorCode'])
             desc = res['errorDesc']
             #如果预期结果方式为mec:message+errorcode
             if except_method == "mec":
                 config_message = handle_result(url, code)
                 if desc == config_message:
                     excel_data.excel_write_data(i + 2, 12, "通过")
                     print("case通过")
                 else:
                     excel_data.excel_write_data(i + 2, 12, "失败")
                     excel_data.excel_write_data(i + 2, 13, json.dumps(res))
                     print("case失败")
             if except_method == "errorcode":
                 if except_result == code:
                     excel_data.excel_write_data(i + 2, 12, "通过")
                     print("case通过")
                 else:
                     excel_data.excel_write_data(i + 2, 12, "失败")
                     excel_data.excel_write_data(i + 2, 13, json.dumps(res))
                     print("case失败")
             # 如果预期结果方式为json格式
             if except_method == "json":
                 if code == 1000:
                     status_str = "sucess"
                 else:
                     status_str = "error"
                 except_result_json = get_result_json(url, status_str)
                 # print(res,'-------',except_result_json)
                 result = handle_result_json(res, except_result_json)
                 if result:
                     excel_data.excel_write_data(i + 2, 12, "通过")
                     print("case通过")
                 else:
                     excel_data.excel_write_data(i + 2, 12, "失败")
                     excel_data.excel_write_data(i + 2, 13, json.dumps(res))
                     print("case失败")
Ejemplo n.º 2
0
    def test_main_case(self, data):
        cookie = None
        get_cookie = None
        header = None
        depend_data = None
        is_run = data[2]
        case_id = data[0]
        i = excel_data.get_rows_number(case_id)
        if is_run == 'yes':
            is_depend = data[3]
            data1 = json.loads(data[7])
            try:
                if is_depend:
                    #获取依赖数据
                    depend_key = data[4]

                    depend_data = get_data(is_depend)
                    #print(depend_data)
                    data1[depend_key] = depend_data
                method = data[6]
                url = data[5]

                is_header = data[9]
                expect_method = data[10]
                expect_result = data[11]

                cookie_method = data[8]
                if cookie_method == 'yes':
                    cookie = get_cookie_value('app')
                if cookie_method == 'write':
                    ''' 
                        必须是获取到cookie
                        '''
                    get_cookie = {"is_cookie": "app"}
                if is_header == 'yes':
                    header = get_header()

                res = request.run_main(method, url, data1, cookie, get_cookie,
                                       header)
                #print(code)
                code = str(res['errorCode'])
                #print(res['errorCode'])
                message = res['errorDesc']
                #message+errorcode

                if expect_method == 'mec':
                    config_message = handle_result(url, code)
                    '''
                            if message == config_message:
                                excel_data.excel_write_data(i,13,"通过")
                            else:
                                excel_data.excel_write_data(i,13,"失败")
                                excel_data.excel_write_data(i,14,json.dumps(res))
                        '''
                    try:
                        self.assertEqual(message, config_message)
                        excel_data.excel_write_data(i, 13, "通过")
                    except Exception:
                        excel_data.excel_write_data(i, 13, "失败")
                        excel_data.excel_write_data(i, 14, json.dumps(res))
                        raise Exception

                if expect_method == 'errorcode':
                    '''
                        if expect_result == code:
                            excel_data.excel_write_data(i,13,"通过")
                        else:
                            excel_data.excel_write_data(i,13,"失败")
                            excel_data.excel_write_data(i,14,json.dumps(res))
                        '''
                    try:
                        self.assertEqual(expect_result, code)
                        excel_data.excel_write_data(i, 13, "通过")
                    except Exception as e:
                        excel_data.excel_write_data(i, 13, "失败")
                        excel_data.excel_write_data(i, 14, json.dumps(res))
                        raise e
                if expect_method == 'json':
                    if code == 1000:
                        status_str = 'sucess'
                    else:
                        status_str = 'error'
                    expect_result = get_result_json(url, status_str)
                    result = handle_result_json(res, expect_result)
                    '''
                        if result:
                            excel_data.excel_write_data(i,13,"通过")
                        else:
                            excel_data.excel_write_data(i,13,"失败")
                            excel_data.excel_write_data(i,14,json.dumps(res))
                        '''
                    try:
                        self.assertTrue(result)
                        excel_data.excel_write_data(i, 13, "通过")
                    except Exception as e:
                        excel_data.excel_write_data(i, 13, "失败")
                        excel_data.excel_write_data(i, 14, json.dumps(res))
                        raise e
            except Exception as e:
                excel_data.excel_write_data(i, 13, "失败")
                raise e
Ejemplo n.º 3
0
    def run_case(self):
        rows = excel.get_rows()
        Is_Run_index, \
            Precondition_index, \
            Depend_key_index, \
            Url_index, \
            Method_index, \
            Data_index, \
            Expected_Method_index, \
            Expected_Result_index, \
            Execute_Result_index, \
            ResponseResult_index = self.init_excel_index()
        for i in range(rows):
            data = excel.get_rows_value(i + 2)
            is_run = data[Is_Run_index]
            # 判断是否需要执行case
            if is_run == 'yes':

                # 判断是否有前置条件
                if data[Precondition_index]:
                    # 如果存在前置条件,及获取依赖字段的值
                    cell_data, rule_data = depend_data(data[Precondition_index], 'A',
                                                       11)
                    print(cell_data)
                    print(type(cell_data))
                    print(rule_data)
                    dependData = get_depend_data(cell_data, rule_data)
                    logger.debug("依赖数据:" + dependData)
                    # 替换掉依赖字段对应的依赖数据
                    parm = eval(data[Data_index])
                    parm[data[Depend_key_index]] = dependData
                    print(parm)

                # 执行请求,获得返回结果
                time_str = time.strftime("%Y%m%d", time.localtime())
                if data[Data_index]:
                    request_data = json.loads(data[Data_index])
                    if request_data['game_date'] == "":
                        request_data['game_date'] = time_str
                    data[Data_index] = request_data

                res = request.run_main(data[Method_index], data[Url_index],
                                       data[Data_index])
                # 获取errorcode和errorMsg,存在两种字段,既需要分开处理
                try:
                    result_code = res['errorCode']
                except KeyError:
                    result_code = res['error_code']
                try:
                    result_msg = res['errorMsg']
                except KeyError:
                    result_msg = res['error_msg']
                # 判断预期结果验证方式
                if data[Expected_Method_index] == "errorMsg":
                    # 判断文件内errorMsg和返回值errorMsg是否一致
                    message = handle_result('Config/check_config.json',
                                            result_code, "config")
                    if type(message) is not list:
                        if message == str(result_msg):
                            logger.debug("测试通过---")
                            excel.excel_write_data(i + 2,
                                                   Execute_Result_index + 1,
                                                   "通过")
                            excel.excel_write_data(i + 2,
                                                   ResponseResult_index + 1,
                                                   str(res))
                        else:
                            logger.debug("测试失败---")
                            excel.excel_write_data(i + 2,
                                                   Execute_Result_index + 1,
                                                   "失败")
                            excel.excel_write_data(i + 2,
                                                   ResponseResult_index + 1,
                                                   str(res))
                    else:
                        for i_result_msg in message:
                            if i_result_msg == result_msg:
                                result = "通过"
                                break
                            else:
                                result = "失败"
                        excel.excel_write_data(i + 2, Execute_Result_index + 1,
                                               result)
                        excel.excel_write_data(i + 2, ResponseResult_index + 1,
                                               str(res))
                        logger.debug(result)
                elif data[Expected_Method_index] == "errorCode":
                    # 判断errorCode返回值和预期结果返回值是否一致
                    if data[Expected_Result_index] == str(result_code):
                        logger.debug("测试通过---")
                        excel.excel_write_data(i + 2, Execute_Result_index + 1,
                                               "通过")
                        excel.excel_write_data(i + 2, ResponseResult_index + 1,
                                               str(res))
                    else:
                        logger.debug("测试失败---")
                        excel.excel_write_data(i + 2, Execute_Result_index + 1,
                                               "失败")
                        excel.excel_write_data(i + 2, ResponseResult_index + 1,
                                               str(res))
                else:
                    # 判断返回值是否json格式
                    excel.excel_write_data(i + 2, ResponseResult_index + 1,
                                           str(res))

                # with open('code_config.json', 'w', encoding='utf-8') as f:
                #     res = json.dumps(res)
                #     f.write(res)
                logger.debug("-" * 100)
                logger.debug(res)
                logger.debug("-" * 100)
Ejemplo n.º 4
0
 def testrun_case(self, data):
     #rows = excel_data.get_rows()
     #for i in range(rows):
     cookie = None
     get_cookie = None
     header = None
     #data = excel_data.get_rows_value(i+2)
     is_run = data[2]
     if is_run == 'yes':
         method = data[5]
         url = data[4]
         data1 = data[6]
         is_header = data[8]
         excepect_method = data[9]
         excepect_result = data[10]
         codition = data[3]
         if codition:
             pass
         cookie_method = data[7]
         if cookie_method == 'yes':
             cookie = get_cookie_value('app')
         if cookie_method == 'write':
             '''
             必须是获取到cookie
             '''
             get_cookie = {"is_cookie": "app"}
         if is_header == 'yes':
             header = get_header()
         res = request.run_main(method, url, data1, cookie, get_cookie,
                                header)
         #print(res)
         code = str(res['errorCode'])
         message = res['errorDesc']
         if excepect_method == 'mec':
             config_message = handle_result(url, code)
             self.assertEqual(message, config_message)
             '''
             if message == config_message:
                 excel_data.excel_write_data(i+2,12,"通过")
             else:
                 excel_data.excel_write_data(i+2,12,"失败")
                 excel_data.excel_write_data(i+2,13,json.dumps(res))
             '''
         if excepect_method == 'errorcode':
             self.assertEqual(excepect_result, code)
             '''
             if excepect_result == code:
             
                 excel_data.excel_write_data(i+2,12,"通过")
             else:
                 excel_data.excel_write_data(i+2,12,"失败")
                 excel_data.excel_write_data(i+2,13,json.dumps(res))
             '''
         if excepect_method == 'json':
             if code == 1000:
                 status_str = 'sucess'
             else:
                 status_str = 'error'
             excepect_result = get_result_json(url, status_str)
             result = handle_result_json(res, excepect_result)
             self.assertTrue(result)
             '''
Ejemplo n.º 5
0
    def test_run_main(self, data):
        Case_Id, \
            Description, \
            Is_Run, \
            Precondition, \
            Depend_key, \
            Url, \
            Method, \
            Data, \
            Expected_Method, \
            Expected_Result, \
            Execute_Result, \
            ResponseResult = data

        # 判断是否需要执行case
        if Is_Run == 'yes':
            # 获得index数据i,既:行号
            i = excel.get_row_number(Case_Id, 'A')

            # 判断是否有前置条件
            if Precondition:
                # 如果存在前置条件,及获取依赖字段的值
                cell_data, rule_data = depend_data(Precondition, 'A', 11)
                dependData = get_depend_data(cell_data, rule_data)
                logger.debug("依赖数据:" + dependData)
                # 替换掉依赖字段对应的依赖数据
                Data = eval(Data)
                # logger.debug("Data类型" + type(Data))
                Data[Depend_key] = dependData
                # logger.debug("Data数据" + Data)
                Data = json.dumps(Data)

            # 执行请求,获得返回结果
            if Data:
                request_data = json.loads(Data)
                if request_data['game_date'] == "":
                    time_str = time.strftime("%Y%m%d", time.localtime())
                    request_data['game_date'] = time_str
                Data = request_data

            res = request.run_main(Method, Url, Data)
            # 获取errorcode和errorMsg,存在两种字段,既需要分开处理
            try:
                result_code = res['errorCode']
            except KeyError:
                result_code = res['error_code']
            try:
                result_msg = res['errorMsg']
            except KeyError:
                try:
                    result_msg = res['error_msg']
                except KeyError:
                    result_msg = None
            # 判断预期结果验证方式
            if Expected_Method == "errorMsg":
                # 判断文件内errorMsg和返回值errorMsg是否一致
                message = handle_result('Config/check_config.json',
                                        result_code, "config")
                if type(message) is not list:
                    try:
                        self.assertEqual(message, result_msg)
                        excel.excel_write_data(i, 11, "PASS")
                        excel.excel_write_data(i, 12, str(res))
                    except Exception as e:
                        logger.error("接口失败errorMsg:" + str(result_msg))
                        excel.excel_write_data(i, 11, "FAIL")
                        excel.excel_write_data(i, 12, str(res))
                        raise e
                else:
                    for i_result_msg in message:
                        if i_result_msg == result_msg:
                            result = True
                            break
                        else:
                            result = False
                    try:
                        self.assertTrue(result, True)
                        excel.excel_write_data(i, 11, "PASS")
                        excel.excel_write_data(i, 12, str(res))
                    except Exception as e:
                        logger.error("接口失败errorMsg:" + str(result_msg))
                        excel.excel_write_data(i, 11, "FAIL")
                        excel.excel_write_data(i, 12, str(res))
                        raise e
            elif Expected_Method == "errorCode":
                # 判断errorCode返回值和预期结果返回值是否一致
                try:
                    self.assertEqual(Expected_Result, str(result_code))
                    excel.excel_write_data(i, 11, "PASS")
                    excel.excel_write_data(i, 12, str(res))
                except Exception as e:
                    logger.error("接口失败errorCode:" + str(result_msg))
                    excel.excel_write_data(i, 11, "FAIL")
                    excel.excel_write_data(i, 12, str(res))
                    raise e
            elif Expected_Method == "keyWords":
                # 判断关键字数值是否与预期一致
                rule_data_result, operator, expectedresult = split_data_by_ExpectedResult(
                    Expected_Result)
                depend_data_result = get_depend_data(res, rule_data_result)
                result = get_result_check(depend_data_result, operator,
                                          expectedresult)
                try:
                    self.assertTrue(result)
                    excel.excel_write_data(i, 11, "PASS")
                    excel.excel_write_data(i, 12, str(depend_data_result))
                except Exception as e:
                    logger.error("接口预期结果{0}与实际结果{1}不符:".format(
                        expectedresult, depend_data_result))
                    excel.excel_write_data(i, 11, "FAIL")
                    excel.excel_write_data(
                        i, 12,
                        str("接口预期结果{0}与实际结果{1}不符:".format(
                            expectedresult, depend_data_result)))
                    raise e
Ejemplo n.º 6
0
    def run_case(self):
        rows = excel_data.get_rows()
        for i in range(rows):
            cookie=None
            get_cookie = None
            header = None
            depend_data = None
            data = excel_data.get_rows_value(i+2)
            is_run = data[2]
            if is_run == 'yes':
                is_depend = data[3]
                data1 = json.loads(data[7])
                if is_depend:
                    '''
                    获取依赖数据
                    '''
                    depend_key = data[4]
                    depend_data = get_data(is_depend)
                    #print(depend_data)
                    data1[depend_key] = depend_data

                method = data[6]
                url = data[5]
                
                is_header = data[9]
                excepect_method = data[10]
                excepect_result = data[11]
                cookie_method = data[8]
                if cookie_method == 'yes':
                    cookie = get_cookie_value('app')
                if cookie_method == 'write':
                    '''
                    必须是获取到cookie
                    '''
                    get_cookie={"is_cookie":"app"}
                if is_header == 'yes':
                    header = get_header()
                res = request.run_main(method,url,data1,cookie,get_cookie,header)
                #print(res)
                code = str(res['errorCode'])
                message = res['errorDesc']
                if excepect_method == 'mec': 
                    config_message = handle_result(url,code)
                    if message == config_message:
                        excel_data.excel_write_data(i+2,13,"通过")
                    else:
                        excel_data.excel_write_data(i+2,13,"失败")
                        excel_data.excel_write_data(i+2,14,json.dumps(res))
                if excepect_method == 'errorcode':
                    if excepect_result == code:
                        excel_data.excel_write_data(i+2,14,"通过")
                    else:
                        excel_data.excel_write_data(i+2,13,"失败")
                        excel_data.excel_write_data(i+2,14,json.dumps(res))
                if excepect_method == 'json':
                    if code == 1000:
                        status_str='sucess'
                    else:
                        status_str='error'
                    excepect_result = get_result_json(url,status_str)
                    result = handle_result_json(res,excepect_result)
                    if result:
                        excel_data.excel_write_data(i+2,13,"通过")
                    else:
                        excel_data.excel_write_data(i+2,13,"失败")
                        excel_data.excel_write_data(i+2,14,json.dumps(res))   
Ejemplo n.º 7
0
    def run_case(self):
        row = excel_data.get_row()

        for i in range(row):
            cookie = None
            get_cookie = None
            data = excel_data.get_row_value(i + 2)
            is_run = data[2]
            if is_run == 'yes':
                method = data[5]
                url = data[4]
                data1 = data[6]
                header = data[13]
                exthed_method = data[8]
                exthed_result = data[9]
                cookie_mother = data[7]
                if cookie_mother == "yes":
                    cookie = get_cookid_valus("app")

                if cookie_mother == "write":
                    get_cookie = {"is_cookie": "app"}
                if header == "yes":
                    is_header = get_header()
                res = request.run_main(method, url, data1, cookie, get_cookie,
                                       is_header)

                if exthed_method == 'mec':
                    code = "1003"
                    # message=res['errorCodeMes']
                    message = "用户名错误"
                    config_message = handle_result(url, code)
                    if message == config_message:
                        excel_data.excel_write_Data(i + 2, 11, "通过")
                        print("测试通过")
                    else:
                        excel_data.excel_write_Data(i + 2, 11, "失败")
                        excel_data.excel_write_Data(i + 2, 12, json.dumps(res))
                        print("测试失败")
                if exthed_method == 'errorcode':
                    code = "1006"
                    if exthed_result == code:
                        excel_data.excel_write_Data(i + 2, 11, "通过")
                        print("测试通过")
                    else:
                        excel_data.excel_write_Data(i + 2, 11, "失败")
                        excel_data.excel_write_Data(i + 2, 12, json.dumps(res))
                        print("测试失败")
                if exthed_method == "json":
                    code = res['errorCode']
                    # print("code=====",code)
                    if code == "10067":
                        status = "error"
                    else:
                        status = "succes"
                    excute_result = get_result_json(url, status)
                    result = handle_result_json(res, excute_result)
                    if result:
                        excel_data.excel_write_Data(i + 2, 11, "通过")
                    else:
                        excel_data.excel_write_Data(i + 2, 11, "失败")
                        excel_data.excel_write_Data(i + 2, 12, json.dumps(res))