标题: robot 使用if+replace string无法执行,求教 [打印本页] 作者: 晓芳 时间: 2023-10-8 06:09 标题: robot 使用if+replace string无法执行,求教 open excel D:\\RF\\case.xls #打开本地文件
#计算行数
${rowcount} Get row count 注册接口
#循环读取Excel中请求数据
FOR ${row} IN RANGE 1 ${rowcount}-1
${req_data} read cell data by coordinates 注册接口 2 ${row}
${res}= should match regexp ${req_data} "#phone#" msg=匹配成功
${new-phone}= 判断数据库是否存在手机号
log to console ${new-phone}
run keyword if ${res}=="#phone#" log to console 成功
run keyword if ${res}=="#phone#" ${req_data1} replace string ${req_data} "#phone#" ${new-phone}
${json_dict} Evaluate json.loads($req_data) json
log to console ${json_dict}
${response}= POST On Session api /member/register json=${json_dict}
功能实现就是将请求数据中的#phone#替换成新生成的手机号
run keyword if ${res}=="#phone#" ${req_data1} replace string ${req_data} "#phone#" ${new-phone}这个就会报错:Resolving variable '${new-phone}' failed: Variable '${new}' not found.如果单独执行if 或者单独执行replace都可以就是放一起执行报错。作者: kallinr 时间: 2023-10-8 09:34
我靠,看不到作者: jingzizx 时间: 2023-10-8 10:02
数据没找到作者: qqq911 时间: 2023-10-8 10:09
${new-phone} 变量中间不要带符号作者: litingting0214 时间: 2023-10-8 11:15
不会啊作者: 海海豚 时间: 2023-10-8 11:18
${new-phone} 变量中间不要带符号作者: 晓芳 时间: 2023-10-9 05:24
去掉变量中间符号还是不行, open excel D:\\RF\\case.xls
#计算行数
${rowcount} Get row count 注册接口
#循环读取Excel中请求数据
FOR ${row} IN RANGE 1 ${rowcount}-1
${reqdata} read cell data by coordinates 注册接口 2 ${row}
${res}= should match regexp ${req_data} "#phone#" msg=匹配成功
${newphone}= 判断数据库是否存在手机号
log to console ${newphone}
run keyword if ${res}=="#phone#" log to console 成功
run keyword if ${res}=="#phone#" ${reqdata1} replace string ${reqdata} "#phone#" "${newphone}"
${json_dict} Evaluate json.loads($req_data) json
log to console ${json_dict}
${response}= POST On Session api /member/register json=${json_dict}
END
运行后报:20231009 05:19:43.426 : INFO : ${res} = "#phone#"
20231009 05:19:43.781 : INFO : Executing : Query | SELECT * FROM future.member WHERE mobile_phone=15808043259
20231009 05:19:43.954 : INFO : ${sql查询结果} = ()
20231009 05:19:43.956 : INFO : ${rowCount} = None
20231009 05:19:43.959 : INFO : Returning from the enclosing user keyword.
20231009 05:19:43.960 : INFO : ${newphone} = 15808043259
20231009 05:19:43.966 : FAIL :
Variable '${reqdata1}' not found. Did you mean:
${reqdata} 作者: 晓芳 时间: 2023-10-9 06:01
20231009 05:58:30.616 ERROR Adding keyword 'domain_name' to library 'FakerLibrary' failed: Type information given to non-existing argument 'levels'.
20231009 05:58:30.617 ERROR Adding keyword 'email' to library 'FakerLibrary' failed: Type information given to non-existing arguments 'domain' and 'safe'.
20231009 05:58:30.618 ERROR Adding keyword 'hostname' to library 'FakerLibrary' failed: Type information given to non-existing argument 'levels'.
20231009 05:58:30.622 ERROR Adding keyword 'slug' to library 'FakerLibrary' failed: Type information given to non-existing argument 'value'.