一、概述
Loadrunner作为HP出品的性能测试工具,拥有太多奇妙魔法甜点供予性能测试人员享用,其中吃起来比较有嚼劲的那就是关联了。当然在关联之后我们还需要一些简单的字符处理,用以生成我们所需要的切糕、煎饼果子等。
Session在 网络应用中称为“会话”,借助它可提供客户端与服务系统之 间必要的交互。因为HTTP协议本身是无状态的,所以经常需要 通过Session来解决服务端和浏览器的保持状态的解决方案。用户 向服务器发送第一个请求时,服务器为其建立一个Session,并为 此Session创建一个标识,用户随后的所有请求都应包括这个标识 号。服务器会校对这个标识号以判断请求属于哪个Session。会话 保持有效,默认状况下,直到浏览器关闭,会话才结束。
Session中存储的内容包括用户信息:昵称、用户ID、登录状 态等。
我们的服务器通过SESSIONID确认了,谁是谁?但是在我们所录制的脚本里面,每次发送的协议包还一直是我们所录制的内容,此时就引发了如下报错信息:
Error -26612: HTTP Status-Code=500 (Internal Server Error) for
- 数据新增修改删除,违反唯一索引(未关联页面隐藏的表关键字段)
- 发送回服务器的字段所用字符集,不能被服务器正确解析
- SESSIONID不被服务器认可
- 开启浏览器F12开发人员工具,分析页面request与response
- 如果还是难以发现其中症结,就从svn下载源码,自己搭建开发环境,回放脚本发送协议,源码中断点排查
- 当没有源码的情况下,我们还可以考虑反编译war文件,利用Eclipse及其强大的插件,断点排查
(1)、明确关联字段
<r id="value":这里的“value”作为服务器确认字段唯一操作ID,它是我们需要关联的字段。
在确定我们的主键为PARTY_ID之后,我们通过查询数据库得知,前五位为”10000“,长度为十四的数字为我们需要关联的另一个字段。(因涉及安全原因数据库查询结果,不能予以展示)
web_reg_save_param_ex(
"ParamName=ridList",
"LB= r id=\"",
"RB= \"",
"Ordinal=ALL",
SEARCH_FILTERS,
"Scope=All",
"RequestUrl=**********************", LAST);
创建关于主键字段的关联,相对比较复杂。在此确定它的左边界为:,1000,右边界为:,1。关联函数如下如下:
web_reg_save_param_ex(
"ParamName=party_id",
"LB=,1000",
"RB=,1",
"Ordinal=ALL",
SEARCH_FILTERS,
"Scope=All",
"RequestUrl=**********************",LAST);
lr_eval_string("{ridList_1}");
在此推荐一个LR提供随机获取数组元素的函数:
lr_paramarr_random("ridList");
总所周知Loadrunner是以c语言为基础设计的脚本,我们常常需要对关联函数所生成的字符进行一些简单的操作,在此分享一些c语言字符操作函数及语法知识。
函数名 | 英文描述 | 乌龙翻译(看不明白,就别看了) |
strset |
Fills a string with a specific character.
char *strset( char *string1, int character );
string1 The string to which to add the characher. character The character(s) to add.
|
一二三四五,来一起变身,凸凸凸凸凸 |
strchr |
Returns the pointer to the first occurrence of a character in a string.
char *strchr( const char *string, int c );
string The string that is searched.
c The character that is searched for in the string.
|
买猪肉,从第一块脊骨那儿斩断,只要后面的,多了不要 |
strrchr |
Finds the last occurrence of a character in a string.
char *strrchr( const char *string, int c );
string The string that is searched.
c The character that is searched for in the string.
|
又买猪肉,从最后一块脊骨那儿斩断,只买后面的
胃口不好,少吃点,话说最后一块脊骨后面,是啥呢?
|
strcpy |
Copies one string to another.
char *strcpy( char *dest, const char *source );
dest The destination string into which source is copied.
source The string that is sopied.
|
克隆其实很简单,复制一个字符串到另一个字符串中 |
strncpy |
Copies the first n characters of one string to another.
char *strncpy( char *dest, const char *source, size_t n );
dest The destination string to which n characters are copied.
source The source string from which n characters are copied.
n The number of characters copied.
|
买了一头猪,看中了大前蹄前面一节儿,切好了装我兜里,包括大前蹄哟 |
strdup |
Duplicates a string.
char *strdup( const char *string );
string The string that is duplicated.
|
复制一个字符串 |
strlen |
Returns the length of a string.
size_t strlen( const char *string );
string The string whose is returned.
|
“鞭长莫及” |
strwr |
Converts a string to lower case.
char *strlwr( char *string );
string The string whose characters are converted to lower case.
|
好吧,中文可没小写版,别乱用哟 |
strupr
|
Converts a string to upper case.
char *strupr( char *string );
string The string whose characters are converted to upper case.
|
好吧,中文可没大写版,别乱用哟 |
strcmp |
Compares two strings to determine the alphabetic order.
int strcmp( const char *string1, const char *string2 );
string1 The frist string that is compared.
string2 The second string that is compared.
|
大小写敏感
|
stricmp |
Performs a case-insensitive comparison of two strings.
int stricmp( const char *string1, const char *string2 );
string1 The firest string for comparison.
string2 The second string for comparison.
|
大小写不敏感
|
strncmp |
Compares the first n characters of two strings.
int strncmp( const char *string1, const char *string2, size_t n );
string1 The firest string for comparison.
string2 The second string for comparison.
n The number of characters in each string that are compared.
|
大小写敏感
|
strnicmp
|
Performs a case-insensitive comparison of n strings.
int strnicmp( const char *string1, const char *string2, size_t num);
string1 The firest string for comparison.
string2 The second string for comparison.
num The number of characters to compare.
|
大小写不敏感
|
strcat |
Concatenates two strings.
char *strcat( char *to, const char *from );
to The string at the end of which the from string is concatenated.
from The string concatenated to the end of the to string.
|
String"B"接到String"2"后面,化生String"2B"
|
strncat | Concatenates n characters from one string to another.
char *strncat( char *to_string, const char *from_string, size_t n );
to_string The string to which n charachters are concatenated.
from_string The string from whice n charachters are concatenated.
n The number of characters to be concatenated.
|
String"BBBB"接到String"2"后面,只接一位,化生String"2B" |
strstr |
Returns the first occurrence of one string in another.
char *strstr( const char *string1, const char *string2 );
string1 The string that is searched.
string2 The string that is searched for in the first string.
|
查找一个字符串 |
strtok |
Returns a token from a string delimited by specified characters.
char *strtok( char *string, const char *delimiters );
string The string to scan.
delimiters The string consisting of the character or characters that delimit tokens in the first string.
|
老板,来一整根龙骨,按每个骨节切开,依着原来的顺序打包给我 |
strspn |
Returns the length of the leading characters in a string that are contained in a specified string.
size_t *strspn( const char *string, const char *skipset );
string Null -terminated string to be scanned.
skipset Null -terminated string containing character set.
|
strspn返回string起始部分匹配skipset 中任意字符串的字符数 |
以上代码相关内容不感兴趣的同学,其实可以跳过滴。
//argv为源字符串,delimiters为切分分隔符,number为所需获取分隔符数
char* strlick(char *argv,const char delimiters ,int number)
{
int i;
int j = ;
int p = ;
char buf[] = {};
if(number < )
{
return "the number can't < 1";
}
for(i = ;argv[i] != ;i++)
{
buf[j] = argv[i];
if(argv[i] == delimiters)
{
buf[j] = ;
if(p == number) return buf;
j = ;
p++;
continue;
}
j++;
}
return "can't find";
}
//argv为源字符串,delimiters为切分分隔符, number为所需获取分隔符数 ,length为所需截取字符长度
char* strputty(char *argv,const char delimiters ,int number,int length)
{
int count = ;
char buf[] = {};
int i ;
for(i = ;argv[i] != ;i++)
{
if(argv[i] == delimiters)
{
if(count == number)
{
strncpy(buf,argv + i +,length);
return buf;
}
count++;
continue;
}
}
return "can't find";
}
(4)、替换关联字段