51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3924|回复: 3
打印 上一主题 下一主题

[原创] web_convert_param 函数应用

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2011-6-14 15:04:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
[原创] web_convert_param 函数应用
选取web 协议,用html方式录制baidu.com查询”linux技巧”,则在runtime-viewer回放看到查询关键词并非”linux技巧”而是URL编码结果。


改用url 模式录制,代码如后:
web_url("s",
"URL=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",

"Resource=0",

"RecContentType=text/html",

"Referer=http://www.baidu.com/",

"Snapshot=t4.inf",

"Mode=HTTP",

LAST);

web_url("c.gif",

"URL=http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9",

"Resource=0",

"RecContentType=text/html",

"Referer=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",

"Mode=HTTP",

LAST);

回放出错,经ethreal截包,确有:http 204错误。

Action.c(28): Error -26563: Non-empty response body is invalid with HTTP Status Code 204 (No Content) for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9"

[MsgId: MERR-26563]
Action.c(28): t=1560ms: 1-byte response body for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9" (RelFrameId=1)
Action.c(28):
\x00
Action.c(28): Warning -26652: Response body length (1) does not match the Content-Length header specification (0) for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9"

[MsgId: MWAR-26652]
Action.c(28): web_url("c.gif") highest severity level was "ERROR", 1 body bytes, 112 header bytes

[MsgId: MMSG-26388]。

为了参数化以及更正错误,正确的代码如后:
web_convert_param("encoderesult", "SourceString={keyword}","SourceEncoding=HTML",

"TargetEncoding=URL", LAST);

lr_log_message("encode=%s",lr_eval_string("{encoderesult}"));

web_url("s",

"URL=http://www.baidu.com/s?wd={encoderesult}&cl=3",

"Resource=0",

"RecContentType=text/html",

"Referer=http://www.baidu.com/",

"Snapshot=t4.inf",

"Mode=HTTP",

LAST);


lr_continue_on_error(LR_ON_ERROR_CONTINUE );

web_url("c.gif",

"URL=http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9",

"Resource=0",

"RecContentType=text/html",

"Referer=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",

"Mode=HTTP",

LAST);

选取web 协议,用html方式录制baidu.com查询”linux技巧”,则在runtime-viewer回放看到查询关键词并非”linux技巧”而是URL编码结果。


改用url 模式录制,代码如后:
web_url("s",
"URL=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",

"Resource=0",

"RecContentType=text/html",

"Referer=http://www.baidu.com/",

"Snapshot=t4.inf",

"Mode=HTTP",

LAST);

web_url("c.gif",

"URL=http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9",

"Resource=0",

"RecContentType=text/html",

"Referer=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",

"Mode=HTTP",

LAST);

回放出错,经ethreal截包,确有:http 204错误。

Action.c(28): Error -26563: Non-empty response body is invalid with HTTP Status Code 204 (No Content) for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9"

[MsgId: MERR-26563]
Action.c(28): t=1560ms: 1-byte response body for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9" (RelFrameId=1)
Action.c(28):
\x00
Action.c(28): Warning -26652: Response body length (1) does not match the Content-Length header specification (0) for "http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9"

[MsgId: MWAR-26652]
Action.c(28): web_url("c.gif") highest severity level was "ERROR", 1 body bytes, 112 header bytes

[MsgId: MMSG-26388]。

为了参数化以及更正错误,正确的代码如后:
web_convert_param("encoderesult", "SourceString={keyword}","SourceEncoding=HTML",

"TargetEncoding=URL", LAST);

lr_log_message("encode=%s",lr_eval_string("{encoderesult}"));

web_url("s",

"URL=http://www.baidu.com/s?wd={encoderesult}&cl=3",

"Resource=0",

"RecContentType=text/html",

"Referer=http://www.baidu.com/",

"Snapshot=t4.inf",

"Mode=HTTP",

LAST);


lr_continue_on_error(LR_ON_ERROR_CONTINUE );

web_url("c.gif",

"URL=http://c.baidu.com/c.gif?t=0&q=linux%BC%BC%C7%C9",

"Resource=0",

"RecContentType=text/html",

"Referer=http://www.baidu.com/s?wd=linux%BC%BC%C7%C9&cl=3",

"Mode=HTTP",

LAST);
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    奋斗
    2022-5-8 19:23
  • 签到天数: 137 天

    连续签到: 1 天

    [LV.7]测试师长

    2#
    发表于 2011-6-14 21:41:39 | 只看该作者
    直接用URL_BASE方式
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2022-5-8 19:23
  • 签到天数: 137 天

    连续签到: 1 天

    [LV.7]测试师长

    3#
    发表于 2011-6-14 21:41:41 | 只看该作者
    直接用URL_BASE方式
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    4#
    发表于 2011-6-15 09:49:06 | 只看该作者
    在最前面 可否对几个LR函数做下简单的描述呢?有的都没接触过 呵呵
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

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

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

    GMT+8, 2024-9-23 20:21 , Processed in 0.070438 second(s), 28 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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