一、概述
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“,长度为十四的数字为我们需要关联的另一个字段。(因涉及安全原因数据库查询结果,不能予以展示)
" ParamName=ridList ",
" LB= r id=\" ",
" RB= \" ",
" Ordinal=ALL ",
SEARCH_FILTERS,
" Scope=All ",
" RequestUrl=********************** ", LAST);
创建关于主键字段的关联,相对比较复杂。在此确定它的左边界为:,1000,右边界为:,1。关联函数如下如下:
" ParamName=party_id ",
" LB=,1000 ",
" RB=,1 ",
" Ordinal=ALL ",
SEARCH_FILTERS,
" Scope=All ",
" RequestUrl=********************** ",LAST);
在此推荐一个LR提供随机获取数组元素的函数:
总所周知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 中任意字符串的字符数 |
char* strlick( char *argv, const char delimiters , int number)
{
int i;
int j = 0;
int p = 0;
char buf[ 64] = { 0};
if(number < 1)
{
return " the number can't < 1 ";
}
for(i = 0;argv[i] != 0;i++)
{
buf[j] = argv[i];
if(argv[i] == delimiters)
{
buf[j] = 0;
if(p == number) return buf;
j = 0;
p++;
continue;
}
j++;
}
return " can't find ";
}
char* strputty( char *argv, const char delimiters , int number, int length)
{
int count = 0;
char buf[ 64] = { 0};
int i ;
for(i = 0;argv[i] != 0;i++)
{
if(argv[i] == delimiters)
{
if(count == number)
{
strncpy(buf,argv + i + 1,length);
return buf;
}
count++;
continue;
}
}
return " can't find ";
}
(4)、替换关联字段
品味性能之道<二>:性能工程师可以具备的专业素养
品味性能之道<三>:方法论
品味性能之道<四>:管理重于技术
品味性能之道<五>:SQL分析工具
品味性能之道<六>:图形化SQL分析工具
品味性能之道<七>:索引基础
品味性能之道<八>:Loadrunner关联技巧与字符处理
品味性能之道<九>:利用Loadrunner编写socket性能测试脚本简述
品味性能之道<十>:Oracle Hint
品味性能之道<十一>:JAVA中switch和if性能比较
深入理解Loadrunner中的Browser Emulation
使用Loadrunner对IBM MQ进行性能测试
怎么做性能测试--响应时间