51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 686|回复: 7
打印 上一主题 下一主题

[求助] robot 使用if+replace string无法执行,求教

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2023-10-8 06:09:06 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
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都可以就是放一起执行报错。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2023-10-9 05:24:28 | 显示全部楼层
去掉变量中间符号还是不行,    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}
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2023-10-9 06:01:09 | 显示全部楼层
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'.

运行时候总是会报这些 哪位大神知道咋回事不?
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-11 02:12 , Processed in 0.066160 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表