以前一直没有解决的问题,利用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(”46246a2633f042c67758b9dd
“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=6726009A7D21963602B166D9
“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
本文介绍了如何使用LoadRunner解决JSESSIONID验证问题,通过web_set_user函数设置登录信息。同时,针对有固定规律的验证码,通过源代码分析找出计算验证码的规律,并提供了相关代码实现。
1万+

被折叠的 条评论
为什么被折叠?



