测试回顾版-第三讲:Loadrunner脚本 VS C语言
2009-02-23 23:57
344 查看
就目前的了解。Loadrunner的脚本语言其实和C没什么区别。他内部的好多机制都是C实现的。
不过是一种“类C”。
(至于说什么javavuser等我不熟悉,所以我的理解就是类C,也只是让大家熟悉“类C”编程)
所以我从几个方面分析
1:定义常量变量和C一样
2:LR函数的参数使用与C有点不一样,在LR中,C的变量和LR的参数是不一样的。
任何C的变量都不能被LR的函数直接调用。
应该用lr_eval_string来取值。
3:什么循环语句,选择语句都和C一样
4:一些函数的定义和C不一样。虽然名字一样,参数有不同
5:输入输出也有些不同。
所以重点要突破的地方就是理清参数和变量直接的关系。和多熟悉一LR些函数,其他就是C语言的知识了。
lr它有自己管理的变量,也叫参数,这种参数只能通过reg或者lr_save_方式定义,或者通过文件定义.
1:定义常量和变量
所有变量在C必须声明,才可以使用
浮点型
字符型
%d是用来表示一个整型值
%f浮点型。(不常见)。
同样,%ç对应字符值。
在LoadRunner中lr_output_message相当于C中的printf的。输出将被印在执行日志中Vugen窗口。
1.分支构造
a.if
b.switch
2.循环构造
a.for
b.while
c.do
逻辑运算
·break-退出形式循环或开关。Thisappliesonlytofor/whileloops.这仅适用于为/while循环。TobreakoutofaLoadRunneriteration,useexit(-1);打破了LoadRunner的迭代,使用exit(-1);
continue--skip1iterationofloop.继续-跳到1迭代循环。Thisappliesonlytofor/while.这仅适用于为/时。TocontinuetothenextiterationinLoadRunneriterations,usereturn0.要继续到下一个迭代的LoadRunner的重复,请使用返回0。
字符串处理
strcpyisusedtocopyonestringintoanother.
strcatisusedtoaddonestringtotheendofanother.
strcmpcomparestwostringsandreturns0ifbothstringsareidentical.
atoiconvertsanASCIIstringtoaninteger.
itoaconvertsanintegertoanasciistringforagivenbase.Syntax:
随机数
LoadRunner运行原理浅析
多维数组
文件处理
LoadRunnerdoesnotsupporttheFILEdatatype.Sowecandeclarethefileasanintegertype.
intMyFile;
intMyFile;
MyFile=(int)fopen(“C://temp//loans.txt”,”w”);//InLoadRunner
intMyFile;
intLoanNumber;
MyFile=fopen(“C://temp//loans.txt”,”r”);
fscanf(MyFile,”%d”,&LoanNumber);
intMyFile;
charName[]=“JohnDoe”;
MyFile=fopen(“C://temp//loans.txt”,”w”);//notethat“w”isusedtowrite
fscanf(MyFile,”%s”,Name);//notethatweareprintingastringhere
函数
引用文件
#include"as_web.h".as_web.hi
Actions()
{
intMyFile;
charName[]="JohnDoe";
MyFile=fopen("C://temp//names.txt","w");
//notethat"w"isusedtowrite
fprintf(MyFile,"%s",Name);
//notethatweareprintingastringhere
fclose(MyFile);
return0;
}
不过是一种“类C”。
(至于说什么javavuser等我不熟悉,所以我的理解就是类C,也只是让大家熟悉“类C”编程)
所以我从几个方面分析
1:定义常量变量和C一样
2:LR函数的参数使用与C有点不一样,在LR中,C的变量和LR的参数是不一样的。
任何C的变量都不能被LR的函数直接调用。
应该用lr_eval_string来取值。
3:什么循环语句,选择语句都和C一样
4:一些函数的定义和C不一样。虽然名字一样,参数有不同
5:输入输出也有些不同。
所以重点要突破的地方就是理清参数和变量直接的关系。和多熟悉一LR些函数,其他就是C语言的知识了。
lr它有自己管理的变量,也叫参数,这种参数只能通过reg或者lr_save_方式定义,或者通过文件定义.
1:定义常量和变量
所有变量在C必须声明,才可以使用
浮点型
字符型
%d是用来表示一个整型值
%f浮点型。(不常见)。
同样,%ç对应字符值。
在LoadRunner中lr_output_message相当于C中的printf的。输出将被印在执行日志中Vugen窗口。
inta=5;
floatx=3.14;
charc=‘A’;
lr_output_message(“Thevaluesare:a=%d,x=%f,c=%c”,a,x,c);
1.分支构造
a.if
b.switch
2.循环构造
a.for
b.while
c.do
逻辑运算
Symbol | Meaning |
< | LESSTHAN |
<= | LESSTHANOREQUALTO |
> | GREATERTHAN |
>= | GREATERTHANOREQUALTO |
== | EQUALTO |
&& | AND |
|| | OR |
! | NOT |
continue--skip1iterationofloop.继续-跳到1迭代循环。Thisappliesonlytofor/while.这仅适用于为/时。TocontinuetothenextiterationinLoadRunneriterations,usereturn0.要继续到下一个迭代的LoadRunner的重复,请使用返回0。
//Globalvariablecount
intcount=0;
//Globalvariablecount
intcount=0;
Actions()
{
//Incrementcount
//
count++;
//Ifcountisequalto10,exitthescript
//
if(count==10)
exit(-1);
//Ifcountiseven,skipthecurrentiteration
//andcontinuewiththenextiteration
//
if(count%2==0)
return0;
lr_output_message(">>>>>>>>>>>>>>>>>>>>>>%d",count);
return0;
字符串处理
strcpyisusedtocopyonestringintoanother.
strcatisusedtoaddonestringtotheendofanother.
strcmpcomparestwostringsandreturns0ifbothstringsareidentical.
atoiconvertsanASCIIstringtoaninteger.
itoaconvertsanintegertoanasciistringforagivenbase.Syntax:
随机数
Actions()
{
inti;
//srand(time(NULL));
for(i=0;i<10;i++)
lr_output_message(">>>>>>>>>>RandomNumber:%d",rand());
}
Actions()
{
charMyString1[20]="";
charMyString2[20]="";
charMyString3[20]="Mercury2";
charCstring[10]="12345";
intCint;
//MyString1isempty
//
lr_output_message(">>>>>>>>>>MyString1=%s",MyString1);
//copy"Mercury1"intoMyString1
//
strcpy(MyString1,"Mercury1");
//NowMyString1contains"Mercury1"
//
lr_output_message(">>>>>>>>>>MyString1=%s",MyString1);
//CopyMyString3intoMyString2
//
lr_output_message(">>>>>>>>>>MyString2=%s",MyString2);
strcpy(MyString2,MyString3);
lr_output_message(">>>>>>>>>>MyString2=%s",MyString2);
//CatenateMyString2toMyString1
//
strcat(MyString1,MyString2);
lr_output_message(">>>>>>>>>>MyString1=%s",MyString1);
//CstringisconvertedtointegerCint
//
lr_output_message(">>>>>>>>>>Cstring=%s",Cstring);
Cint=atoi(Cstring);
lr_output_message(">>>>>>>>>>Cint=%d",Cint);
//Cintisconvertedtostring
Cint=100;
itoa(Cint,Cstring,10);
lr_output_message(">>>>>>>>>>Cstring=%s",Cstring);
return0;
}
多维数组
文件处理
LoadRunnerdoesnotsupporttheFILEdatatype.Sowecandeclarethefileasanintegertype.
intMyFile;
intMyFile;
MyFile=(int)fopen(“C://temp//loans.txt”,”w”);//InLoadRunner
intMyFile;
intLoanNumber;
MyFile=fopen(“C://temp//loans.txt”,”r”);
fscanf(MyFile,”%d”,&LoanNumber);
intMyFile;
charName[]=“JohnDoe”;
MyFile=fopen(“C://temp//loans.txt”,”w”);//notethat“w”isusedtowrite
fscanf(MyFile,”%s”,Name);//notethatweareprintingastringhere
函数
引用文件
#include"as_web.h".as_web.hi
MiscellaneousFunctions
Actions()
{
system("delc://temp//temp.txt");
return0;
}
{
intMyFile;
charName[]="JohnDoe";
MyFile=fopen("C://temp//names.txt","w");
//notethat"w"isusedtowrite
fprintf(MyFile,"%s",Name);
//notethatweareprintingastringhere
fclose(MyFile);
return0;
}
相关文章推荐
- 测试回顾版-第十一讲:Loadrunner8.1自带订票系统脚本实战1
- 测试回顾版-Loadrunner脚本编程(1)-VuGen脚本文件的开发过程
- 【软件性能测试-LoadRunner实战技能 3】== LR所使用的脚本语言初解
- LoadRunner 测试脚本C语言常用函数
- 脚本——使用LoadRunner进行HTTP接口测试
- 利用LoadRunner编写socket性能测试脚本
- “测试实践丛书”系列之“LoadRunner Vuser脚本开发”
- LoadRunner创建测试脚本(转)
- loadrunner使用java协议制作服务器接口测试脚本
- 利用LoadRunner编写socket性能测试脚本
- 做loadrunner下载测试时用的到脚本
- 使用LoadRunner 编写JAVA 测试脚本
- Loadrunner之HTTP接口测试脚本实例
- 测试回顾版-Loadrunner入门级-小强作品(6-10)
- 测试回顾版-Loadrunner脚本编程(4)-数据类型操作和字符串操作
- loadrunner简单使用——HTTP,WebService,Socket压力测试脚本编写
- LoadRunner系列之—-01 接口压力测试脚本
- Loadrunner录制脚本选择语言
- 软件测试工具LoadRunner中运行QTP脚本
- 软件测试自动化之测试脚本语言杂谈