LR翻頁腳本並在每頁實現業務操做

性能需求:在列表中刪除後有記錄,或對列表中的每條記錄進行操做(如點擊每條記錄的「單號」進入訂單詳情頁面,或在列表中對每條記錄進行「啓用」、「中止」操做)html

 

舉例:Vuser腳本模擬用戶在訂單列表中點擊每條記錄的「單號」進入訂單詳情頁面進行處理,處理後該記錄的狀態會發生變化,此時,若是又有另外的虛擬用戶進入訂單列表對同一條訂單記錄進行一樣一操做時,頁面會提示(該記錄已處理)致使後面的腳本關聯失敗,運行場景也會報錯,那麼,就須要在LR腳本中除了作參數化和關聯外,還須要實現翻頁腳本(假設列表每頁顯示10條記錄),並在每頁中作文本檢查點(「訂單號」),對列表全部的記錄進行遍歷的操做。web

 

這裏是在本地環境中實現列表翻頁腳本,並在每頁作文本檢查點,spring

系統列表界面,如圖:ssh

 

 

實現代碼,以下:性能

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;
}
相關文章
相關標籤/搜索