添加依赖数据报错

来源:10-8 项目实战之数据依赖调试及组装

qq_精慕门8524681

2020-04-02

老师,我试过了你和我说的办法,修改完毕excel依赖字段的内容,还是报这个错误,我想依赖的是下方标记的ajzh字段的数据,下方是我的excel表的截图和我的代码。
图片描述
图片描述

class RunMain:
def run_case(self):
rows = excel_data.get_row()
for i in range(rows):
cookie = None
depend_data = None
data = excel_data.get_row_value(i+2)
is_run = data[2]
is_depend = data[3]
param = data[7]

        if is_run == 'yes':
            if is_depend:
                depend_key = data[4]
                depend_data = get_data(is_depend)
                param[depend_key] = depend_data
                print(param)
            method = data[6]
            url = data[5]
            excepect_method = data[11]
            excepect_result = data[12]
            head = data[8]
            if head == 'yes':
                head = get_header()
            res = request.run_main(method=method,url=url,data=param,header=head,cookie=cookie)
            print(res)

            code = res['state']
            message = res['success']
            message = str(message)
            code = res['state']
            message = res['success']
            message = str(message)
            if excepect_method == "mec":
                config_message = handle_result(url, "state")
                config_message1 = handle_result(url, "success")
                if code == config_message and message == config_message1:
                    excel_data.excel_write_data(i + 2, 14, "通过")
                else:
                    excel_data.excel_write_data(i + 2, 14, "失败")
                    excel_data.excel_write_data(i + 2, 15, json.dumps(res))

            if excepect_method == "errorcode":
                if code == excepect_result:
                    excel_data.excel_write_data(i + 2, 14, "通过")
                else:
                    excel_data.excel_write_data(i + 2, 14, "失败")
                    excel_data.excel_write_data(i + 2, 15, json.dumps(res))

            if excepect_method == "json":
                if code == "1":
                    get_result = get_result_json(url, "data")
                    reslut = handle_result_json(res["data"], get_result)
                if reslut == True:
                    excel_data.excel_write_data(i + 2, 14, "通过")
                else:
                    excel_data.excel_write_data(i + 2, 14, "失败")
                    excel_data.excel_write_data(i + 2, 15, json.dumps(res))

if name == ‘main’:
run = RunMain()
print(run.run_case())

=====================================================================================

def split_data(data):
’’‘
拆分单元格数据
’’'
case_id = data.split(">")[0]
rule_data = data.split(">")[1]
return case_id,rule_data

def depend_data(data):
’’‘
获取依赖结果集
’’'
case_id = split_data(data)[0]
row_number = excel_data.get_rows_number(case_id)
data = excel_data.get_data_value(row_number,15)
return data

def get_depend_data(res_data,key):
’’‘
获取依赖字段
’’’

#res_data = json.loads(res_data)
json_exe = parse(key)
madle = json_exe.find(res_data)
return [math.value for math in madle][0]

def get_data(data):
’’‘
获取依赖数据
’’'
res_data = depend_data(data)
rule_data = split_data(data)[1]
return get_depend_data(res_data,rule_data)

写回答

1回答

Mushishi

2020-04-02

#res_data = json.loads(res_data)
json_exe = parse(key)
madle = json_exe.find(res_data)

for math in madle:

    print(math.value )

你去看你这个都没有值



return [math.value for math in madle][0]

0
2
Mushishi
回复
qq_精慕门8524681
你打印出来时啥啊。你后面返回的是一个[0] list去获取第一个,你这个获取不到
2020-04-04
共2条回复

Python接口自动化测试框架实战 从设计到开发

接口自动化测试框架的设计与开发,并教你如何开发桩服务

1720 学习 · 831 问题

查看课程