LoadRunner開發http協議接口之form表單腳本

 

loadrunner傳form表單,用web_submit_data函數。html

Action()
{
//     lr_start_transaction("hp_homepage");
//         web_url("hp_homepage","url=http://127.0.0.1:1080/WebTours/",LAST);
//     lr_end_transaction("hp_homepage", LR_AUTO);

    //web_reg_save_param("userSession","LB=name=userSession value=","RB=>","Search=body",LAST);
    web_reg_save_param_ex("ParamName=userSession","LB=name=userSession value=","RB=>",SEARCH_FILTERS,"Scope=body",LAST);

    lr_start_transaction("hp_webtours");
        web_url("hp_webtours","url=http://127.0.0.1:1080/WebTours/nav.pl?in=home",LAST);    
    lr_end_transaction("hp_webtours", LR_AUTO);

    lr_error_message("userSession=%s",lr_eval_string("{userSession}"));

    web_reg_save_param("result","LB=<frame src=","RB=?intro=true","Search=body",LAST);
    //web_reg_save_param("result","LB=login.pl?intro=","RB= ","Search=body",LAST);
    //判斷事物的時候和true比較,if(strcmp(lr_eval_string("{result}"),"true")==0)

    lr_start_transaction("login");
        web_submit_data("login", 
        "Action=http://127.0.0.1:1080/WebTours/login.pl", 
        "Method=POST",
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t7.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=userSession","Value={userSession}",ENDITEM,
        "Name=username","Value=jojo",ENDITEM,
        "Name=password","Value=bean",ENDITEM,
        "Name=login.x","Value=41",ENDITEM,
        "Name=login.y","Value=8",ENDITEM,
        "Name=login","Value=Login",ENDITEM,
        "Name=JSFormSubmit","Value=off",ENDITEM,
        LAST ); 
        //系統自動判斷寫爲:lr_end_transaction("login", LR_AUTO);
        if(strcmp(lr_eval_string("{result}"),"login.pl")==0)//通常狀況下,get請求不須要檢查是否成功。
        {
            lr_end_transaction("login", LR_PASS);
            lr_error_message("log succes");
        }
        else{
            lr_error_message("log fail");
            lr_end_transaction("login", LR_FAIL);
            lr_error_message("log fail");
        }
    return 0;
}
相關文章
相關標籤/搜索