Loadrunner JSESSIONID 问题解决

本文介绍了如何使用LoadRunner解决JSESSIONID验证问题,通过web_set_user函数设置登录信息。同时,针对有固定规律的验证码,通过源代码分析找出计算验证码的规律,并提供了相关代码实现。
 


以前一直没有解决的问题,利用LoadRunner测试一个应用的时候,需要验证域用户,所以即使录制成功,每次回放的时候都提示错误,用户名和密码不对,对此耿耿于怀了很久。今天居然解决了。解决方法就是一个简单的函数调用: web_set_user,此函数的解释和用法如下:
The web_set_user function is a Service function that specifies a login string and password for a Web server or proxy(代理(权, 人); 代理投票; 代用品) server. It can be called more than once if several proxy servers require authentication. web_set_user overrides(不顾;无视;蔑视) the run-time proxy authentication settings for user name and password.
When you log onto a server that requires user and password validation(确认), VuGen records a web_set_user statement containing the login details. However, there are some more stringent(严厉的, 迫切的, 银根紧的), authentication methods for which VuGen is unable to insert web_set_user statements. See User Authentication for more detail. In such cases, you can add web_set_user into your script manually.
When you run the script, LoadRunner automatically submits the user authorization along with every subsequent request to that server. At the end of the script, LoadRunner resets the authorization.
This function is supported for all Web Vusers, and for WAP Vusers running in HTTP mode only. It is not supported for WAP Vusers running in Wireless Session Protocol (WSP) replay mode.
Example 3
The following example was inserted manually by the user into the script as the Web server “mansfield” uses NTLM authentication. VuGen cannot record NTLM or Digest authentication. Note that for NTLM authentication the domain name “mansfield” followed by a double backslash must be prepended to the user name:
web_set_user(”mansfield\\freddy”, “XYZ”, “mansfield:80″);
原来一直没有想到域的设置,结果一直不行,现在可以了。
另外一个问题跟之前这个有关系,那就是验证码的问题,之前曾经看过段念(关河大侠)的关于验证码的是三个解决方案,这里是第四种解决方案。对于一些比较简单有规律的验证码可以搞定。对于复杂的比如有干扰的,或者没有规律的则参考关大侠的其他解决方案。
这个应用经过源代码分析,发现每次客户端请求过来的验证码都可以取到,格式如下固定,是四个数字的组合。经过多次尝试发现如下规律:
验证码如下: 52|52|52|51|46|47|49|55|
对应界面的验证码是: 6039
规律是第2,5,8,9位的值减去46对应的即是验证码。
有了这个规律,就可以通过关联提前取得服务器的验证码,然后通过简单的计算,得到结果。详细代码如下:

#include “web_api.h”
Action()
{
// char* str = “52|52|52|51|46|47|49|55|”;
char result[64];
int num1;
int num2;
int num3;
int num4;
int temp1;
int temp2;
int temp3;
int temp4;
web_set_user(”XXXXDomain\\szXXXX”,
lr_decrypt(”46246a2633f042c67758b9ddc2b863038aa063c03d7e”),
“XXXX.XXXX.com.cn:8080″);
web_reg_save_param(”check”, “LB=Image=”, “RB=\\”, LAST);
web_url(”Register”,
“URL=http://XXXX.XXXX.com.cn:8080/xx/main/Register”,
“Resource=0″,
“RecContentType=text/html”,
“Referer=”,
“Snapshot=t1.inf”,
“Mode=HTML”,
LAST);
lr_think_time( 6 );
sscanf(lr_eval_string(”{check}”), “%d|%d|%d|%d|%d|%d|%d|%d”, &temp1, &num1, &temp2, &temp3, &num2, &temp4, &num3, &num4);
num1 -= 46;
num2 -= 46;
num3 -= 46;
num4 -= 46;
sprintf(result, “%d%d%d%d”, num1, num2, num3, num4);
lr_log_message(”getvalue : %s”, result);
web_submit_form(”Register;jsessionid=6726009A7D21963602B166D91C883413″,
“Snapshot=t2.inf”,
ITEMDATA,
“Name=Register.reason”, “Value= “, ENDITEM,
“Name=set_attach”, “Value=result”, ENDITEM,
LAST);
return 0;
}
本文来源于天行健,君子以自强不息 http://www.rickyzhu.com , 原文地址: http://www.rickyzhu.com/173_case-three-of-loadrunner.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值