首页 > 技术文章 > LR翻页脚本并在每页实现业务操作

luihengk 2015-08-11 15:28 原文

性能需求:在列表中删除后有记录,或对列表中的每条记录进行操作(如点击每条记录的“单号”进入订单详情页面,或在列表中对每条记录进行“启用”、“停止”操作)

 

举例:Vuser脚本模拟用户在订单列表中点击每条记录的“单号”进入订单详情页面进行处理,处理后该记录的状态会发生变化,此时,如果又有另外的虚拟用户进入订单列表对同一条订单记录进行同样一操作时,页面会提示(该记录已处理)导致后面的脚本关联失败,运行场景也会报错,那么,就需要在LR脚本中除了做参数化和关联外,还需要实现翻页脚本(假设列表每页显示10条记录),并在每页中做文本检查点(“订单号”),对列表所有的记录进行遍历的操作。

 

这里是在本地环境中实现列表翻页脚本,并在每页做文本检查点,

系统列表界面,如图:

 

 

实现代码,如下:

Action2()
{
    int i;
    int temp = 1;
    char str[205];
    
    lr_think_time(6);

    web_reg_find("Text=101036",
                 "SaveCount=modify_Count",
                 LAST);


    web_url("admin_list", 
        "URL=http://localhost:8088/spring-ssh/admin/admin_list", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://localhost:8088/spring-ssh/index", 
        "Snapshot=t3.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=../images/navigation.png", ENDITEM, 
        "Url=../images/index_out.png", ENDITEM, 
        "Url=../images/search.png", ENDITEM, 
        "Url=../images/body_bg.png", ENDITEM, 
        "Url=../images/fee_out.png", ENDITEM, 
        "Url=../images/role_out.png", ENDITEM, 
        "Url=../images/bill_out.png", ENDITEM, 
        "Url=../images/admin_out.png", ENDITEM, 
        "Url=../images/top_bg.png", ENDITEM, 
        "Url=../images/account_out.png", ENDITEM, 
        "Url=../images/information_out.png", ENDITEM, 
        "Url=../images/password_out.png", ENDITEM, 
        "Url=../images/btn_bg.png", ENDITEM, 
        "Url=../images/report_out.png", ENDITEM, 
        "Url=../images/modification.png", ENDITEM, 
        "Url=../images/warning.png", ENDITEM, 
        "Url=../images/service_out.png", ENDITEM, 
        "Url=../images/delete.png", ENDITEM, 
        "Url=../images/admin_on.png", ENDITEM, 
        LAST);

   //共有205页,遍历每一页面
    for(i=1;i<=205;i++){
        //如果在该页找到检查点,则退出循环
        if(atoi(lr_eval_string("{modify_Count}"))>0){

            lr_output_message("在第%d页面已找到检查点",temp);//1,2,3
            return -1;

        }else{

            //在每页做文本检查点
            web_reg_find("Text=101036",
                 "SaveCount=modify_Count",
            LAST);

temp = 1+i;
//将int类型转换为string类型,以10进制保存
itoa(temp,str,10);

    lr_save_string(str,"next");

   //点击下一页
    web_submit_data("admin_list", 
        "Action=http://localhost:8088/spring-ssh/admin/admin_list?page={next}", 
        "Method=POST", 
        "RecContentType=text/html", 
        "Referer=http://localhost:8088/spring-ssh/admin/admin_list", 
        "Snapshot=t4.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=privilegeId", "Value=0", ENDITEM, 
        "Name=roleName", "Value=", ENDITEM, 
        EXTRARES, 
        "Url=../images/body_bg.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/search.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/top_bg.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/role_out.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/index_out.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/navigation.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/fee_out.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/account_out.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/admin_out.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/bill_out.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/service_out.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/modification.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/delete.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/information_out.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/report_out.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/btn_bg.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/warning.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/password_out.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        "Url=../images/admin_on.png", "Referer=http://localhost:8088/spring-ssh/admin/admin_list?page={page}", ENDITEM, 
        LAST);

        }
        
    }

    return 0;
}

 

推荐阅读