使用loadrunner11的AJAX,WEB协议录制百度搜索脚本

2011-07-12  张洪杰 

    最近看到一个帖子是讨论有关使用loadrunner录制百度搜索脚本,说利用百度搜时使用了AJAX技术,所有在录制的时候遇到小问题,因为好奇也抽空练习了下。用的工具是loadrunner11,分别采用了web协议和AJAX协议对脚本进行了录制,比较如下:
1.web协议
1)首先设置采用url方式进行录制脚本
2)设计场景:打开百度>输入:loadrunner>随机点击搜索list的某值
3)优化脚本
  •     用web_reg_save_param 函数获取搜索list的所有值
  •     用lr_paramarr_random 函数随机获取list值
  •     用lr_save_string 函数把随机的list值保存在临时变量tmp
  •     参数化
4)最后脚本
Action()
{

    //char *tmp[100];
    web_add_cookie("BAIDUID=6E2658B7F8D582D7EBD5C2978E6B9A2E:FG=1; DOMAIN=www.baidu.com");

    web_url("www.baidu.com",
        "URL=http://www.baidu.com/",
        "Resource=0",
        "RecContentType=text/html",
        "Referer=",
        "Snapshot=t1.inf",
        "Mode=HTTP",
        LAST);

    web_url("baidu_sylogo1.gif",
        "URL=http://www.baidu.com/img/baidu_sylogo1.gif",
        "Resource=1",
        "RecContentType=image/gif",
        "Referer=http://www.baidu.com/",
        "Snapshot=t2.inf",
        LAST);

    web_url("gs.gif",
        "URL=http://gimg.baidu.com/img/gs.gif",
        "Resource=1",
        "RecContentType=image/gif",
        "Referer=http://www.baidu.com/",
        "Snapshot=t5.inf",
        LAST);

    web_url("i2.png",
        "URL=http://www.baidu.com/img/i2.png",
        "Resource=1",
        "RecContentType=image/png",
        "Referer=http://www.baidu.com/",
        "Snapshot=t3.inf",
        LAST);

    web_url("arr.gif",
        "URL=http://www.baidu.com/img/arr.gif",
        "Resource=1",
        "RecContentType=image/gif",
        "Referer=http://www.baidu.com/",
        "Snapshot=t4.inf",
        LAST);
   
    web_url("hps-1.1.js",
        "URL=http://www.baidu.com/cache/hps/js/hps-1.1.js",
        "Resource=1",
        "RecContentType=application/javascript",
        "Referer=http://www.baidu.com/",
        "Snapshot=t6.inf",
        LAST);

    web_url("bdsug.js",
        "URL=http://www.baidu.com/js/bdsug.js?v=1.0.3.0",
        "Resource=1",
        "RecContentType=application/javascript",
        "Referer=http://www.baidu.com/",
        "Snapshot=t7.inf",
        LAST);

    web_url("favicon.ico",
        "URL=http://www.baidu.com/favicon.ico",
        "Resource=1",
        "RecContentType=image/x-icon",
        "Referer=",
        "Snapshot=t8.inf",
        LAST);

    web_reg_save_param("SearchID",
        "LB=\"",
        "RB=\",",
        "Ord=all",
        "Search=body",
        LAST);

    //lr_save_var();
    web_url("su_10",
        "URL=http://suggestion.baidu.com/su?wd={keyword}&p=3&cb=window.bdsug.sug&t=1310455791339",
        "Resource=1",
        "RecContentType=baiduapp/json",
        "Referer=http://www.baidu.com/",
        "Snapshot=t18.inf",
        LAST);

    //lr_save_string(lr_paramarr_random("SearchID"),*tmp);
    lr_save_string(lr_paramarr_random("SearchID"),"tmp");
    //lr_output_message("title is :%s",lr_paramarr_random("SearchID"));
    //lr_output_message("title is :%s",tmp);
    //web_concurrent_end(NULL);

    lr_think_time(12);

    web_url("s",
        "URL=http://www.baidu.com/s?wd={tmp}&rsp=4&f=3&inputT=6478",
        "Resource=0",
        "RecContentType=text/html",
        "Referer=http://www.baidu.com/",
        "Snapshot=t19.inf",
        "Mode=HTTP",
        LAST);


    return 0;
}
2.AJAX协议
相比web的脚本,AJAX协议脚本更简单易读,具体如下:
Action()
{
    web_add_cookie_ex("Cookie=BAIDUID=6E2658B7F8D582D7EBD5C2978E6B9A2E:FG=1; domain=baidu.com; path=/", ENDITEM,
        LAST);

    web_browser("www.baidu.com",
        DESCRIPTION,
        ACTION,
        "Navigate=http://www.baidu.com/",
        LAST);

    web_edit_field("wd",
        "Snapshot=t1.inf",
        DESCRIPTION,
        "Type=text",
        "Name=wd",
        ACTION,
        "FireEvent=onfocus",
        LAST);

    web_edit_field("wd_2",
        "Snapshot=t3.inf",
        DESCRIPTION,
        "Type=text",
        "Name=wd",
        ACTION,
        "SetValue=loadrunner",
        LAST);

    web_reg_find("Text=loadrunner","SaveCount=count1",LAST);

    web_button("INPUT",
        "Snapshot=t4.inf",
        DESCRIPTION,
        "Type=submit",
        "Tag=INPUT",
        "ID=su",
        ACTION,
        "UserAction=Click",
        LAST);

    return 0;
}

944°/9436 人阅读/1 条评论 发表评论

小窝  2011-07-14

同步至官方微博


登录 后发表评论