LoadRunner關聯技術的應用

weixin_33976072發表於2018-07-23

使用LR註冊1個PHPWind網站會員

分析:

請求網站首頁的時候,伺服器會返回一個token(令牌)給客戶端(LoadRunner),該token的值是動態的,註冊會員需要使用該令牌,如果令牌不符的話,則不允許註冊。可以使用關聯技術將該token的內容儲存到變數裡面,變數名自定義(比如:token),然後使用該變數提交註冊請求。


10027900-b8d288af848fe7b4.png
image.png
<input type="hidden" name="csrf_token" value="b48bf20055cfe9d2"/>

設計LR指令碼

註冊一個會員的指令碼如下:

Action()
{
    
    web_reg_save_param("token",
        "LB=name=\"csrf_token\" value=\"",
        "RB=\"/>",
        "Ord=1",
        LAST);

    web_url("index.php", 
        "URL=http://192.168.0.153:8090/phpwind/index.php", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t19.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=themes/site/default/images/main_bg.png", ENDITEM, 
        "Url=themes/site/default/images/common/style_icon.png", ENDITEM, 
        "Url=themes/site/default/images/common/core_bg.png", ENDITEM, 
        "Url=themes/site/default/images/tips/gray_big.png", ENDITEM, 
        "Url=http://www.bing.com/favicon.ico", "Referer=", ENDITEM, 
        "Url=../favicon.ico", "Referer=", ENDITEM, 
        "Url=res/js/dev/pages/common/global.js?v=20161021", ENDITEM, 
        "Url=res/js/dev/jquery.js?v=20161021", ENDITEM, 
        "Url=res/js/dev/pages/bbs/postGuide.js?v=20161021", ENDITEM, 
        LAST);

    web_url("index.php_2", 
        "URL=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://192.168.0.153:8090/phpwind/index.php", 
        "Snapshot=t21.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=res/js/dev/util_libs/validate.js?v=20161021", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register", ENDITEM, 
        "Url=res/js/dev/util_libs/emailAutoMatch.js?v=20161021", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register", ENDITEM, 
        "Url=themes/site/default/images/register/arrow_reg.png", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register", ENDITEM, 
        "Url=themes/site/default/images/tips/small.png", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register", ENDITEM, 
        LAST);

    web_submit_data("index.php_12", 
        "Action=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register&a=dorun", 
        "Method=POST", 
        "RecContentType=text/html", 
        "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register", 
        "Snapshot=t31.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=username", "Value=jojo2", ENDITEM, 
        "Name=password", "Value=123456", ENDITEM, 
        "Name=repassword", "Value=123456", ENDITEM, 
        "Name=email", "Value=jojo2@qq.com", ENDITEM, 
        "Name=csrf_token", "Value={token}", ENDITEM, 
        EXTRARES, 
        "Url=themes/site/default/images/common/style_bg.png", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register&a=guide", ENDITEM, 
        "Url=themes/site/default/images/common/loading.gif", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register&a=guide", ENDITEM, 
        "Url=themes/site/default/images/common/header_dorp.png", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register&a=guide", ENDITEM, 
        "Url=themes/site/default/images/common/core_icon.png", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register&a=guide", ENDITEM, 
        LAST);

    return 0;
}

回放指令碼

伺服器返回註冊成功的頁面


10027900-a85ba15034567193.png
image.png

相關文章