数据池(DATAPOOL)专题
数据池在rational测试中是使用率很高,同时它也充分体现了自动化测试的优势。通过使用数据池,可以通过简单的脚本完成大量数据的测试,缩短测试时间、提高测试效率和测试质量。下面将介绍数据池的概念、创建以及在GUI、VU脚本中的应用。数据池(DATAPOOL)用于存储测试数据,在脚本中插入数据池命令并增加相关的控制命令后,在脚本回放时就可以自动从数据池中取出数据,完成多组测试数据的测试。
(一)数据池(DATAPOOL)创建
1、启动Rational TestManager;
2、Tools>Manage>Datapool,点击New…,输入数据池名称点“确定”;
3、在打开的Data Type Specification中添加字段定义;
字段定义说明:
Name:字段名称
Type:数据类型
Sequence:次序,包括Random(随机)、Sequential(连续)、Unique(唯一)
Repeat:数据重复次数
Length:数据长度
Decimals:小数位数
Interval:间隔,相邻两个数据的间隔数
Mininum:最小值
Maxinum:最大值
Seed:Sequence设为Random时,Seed输入不同的数据,生成不同的随机数
4、在设置好字段后,在No. of records to genarete:中输入要生成的记录数,然后点击Genarete Data 即可生成数据,或者点击SAVE按钮,关闭当前窗口,然后点击manage datapools>edit>edit datapool data,直接手工输入数据;
5、这样就完成了数据池的创建,还可以执行数据池的编辑、改名、删除、导入、导出等操作;
6、数据池有数据生成能力,但是不具备数据的计算能力。这种情况下可以利用其他工具(如EXCEL)生成数据,并保存为csv(逗号分割文件)格式,然后在manage datapools中导入;
(二)、
1、数据池在GUI脚本中的应用
这是计算器测试的例子,在GUI中使用数据池需要手工编码,robot不能自动生成,在手工编码时可以参考Robot的在线帮助。
'$Include "sqautil.sbh"
Sub Main
Dim Result As Integer
dim x as integer
dim num1 as string
dim num2 as string
dim sum as string
'Initially Recorded: 2003-7-188:51:18
'Script Name: 计算器-2
StartApplication "C:\WINNT\system32\calc.exe"
dp=SQADatapoolOpen("jsq")
'打开数据池,jsp为数据池的名称,这个数据池是预先按照上述规范做好的
for x=1 to 5
Call SQADatapoolFetch(dp)
'从数据池中读取记录
Call SQADatapoolValue(dp,1,num1)
Call SQADatapoolValue(dp,2,num2)
Call SQADatapoolValue(dp,3,sum)
'将从数据池中读取的数据赋予相应变量
Window SetContext, "Caption=计算器", ""
InputKeys num1 &"{+}"& num2 &"{ENTER}"
Result = LabelVP (CompareNumeric, "Text="& sum &".", "VP=Alphanumeric;Value="& sum &".")
next
Call SQADatapoolClose(dp)
'关闭数据池
Window CloseWin, "", ""
End Sub
2、数据池在VU脚本中的应用
VU脚本中的数据池可以通过录制自动产生,如果不能自动产生可以手工编码加入。
以下录制在Google上搜索的脚本,数据池时录制时自动产生的:
#include <VU.h>
{
push Timeout_scale = 200; /* Set timeouts to 200% of maximum response time */
push Think_def = "LR";
Min_tmout = 120000; /* Set minimum Timeout_val to 2 minutes */
push Timeout_val = Min_tmout;
DP1 = datapool_open("googlw");
datapool_fetch(DP1);
push Think_avg = 0;
www_google_com = http_request ["googlw001"] "www.google.com:80",
HTTP_CONN_DIRECT,
"GET / HTTP/1.1\r\n"
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicat"
"ion/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, ap"
"plication/x-shockwave-flash, */*\r\n"
"Accept-Language: zh-cn\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR"
" 1.1.4322)\r\n"
"Host: www.google.com\r\n"
"Connection: Keep-Alive\r\n"
"Cookie: PREF=ID=6011af2d9ae9ecc9:TB=2:TM=1079509149:LM=1079509149:S=Bbt"
"iwXYs9ldWNF0T\r\n"
"\r\n";
set Server_connection = www_google_com;
http_header_recv ["googlw002"]302; /* Moved Temporarily */
http_nrecv ["googlw003"]100 %% ; /* Internally Generated */
{
string SgenRes_001[];
SgenRes_001 = http_find_values("RedirectPrefix", HTTP_REDIRECT_PREFIX, 2);
CHECK_FIND_RESULT(SgenRes_001,"RedirectPrefix","/intl/zh-CN/")
}
set Think_avg = 190;
/* Keep-Alive request over connection www_google_com */
http_request ["googlw004"]
"GET " + SgenRes_001 + " HTTP/1.1\r\n"
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicat"
"ion/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, ap"
"plication/x-shockwave-flash, */*\r\n"
"Accept-Language: zh-cn\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR"
" 1.1.4322)\r\n"
"Host: www.google.com\r\n"
"Connection: Keep-Alive\r\n"
"Cookie: PREF=ID=6011af2d9ae9ecc9:TB=2:TM=1079509149:LM=1079509149:S=Bbt"
"iwXYs9ldWNF0T\r\n"
"\r\n";
{ string SgenURI_003; }
SgenURI_003 = _reference_URI; /* Save "Referer:" string */
http_header_recv ["googlw005"]200; /* OK */
http_nrecv ["googlw006"]100 %% ; /* 1407 bytes */
{
string SgenRes_002[];
SgenRes_002 = http_find_values("hl", HTTP_HREF_DATA, 1);
CHECK_FIND_RESULT(SgenRes_002,"hl","zh-CN")
}
{
string SgenRes_003[];
SgenRes_003 = http_find_values("ie", HTTP_HREF_DATA, 1);
CHECK_FIND_RESULT(SgenRes_003,"ie","UTF-8")
}
{
string SgenRes_004[];
SgenRes_004 = http_find_values("oe", HTTP_HREF_DATA, 1);
CHECK_FIND_RESULT(SgenRes_004,"oe","UTF-8")
}
{
string SgenRes_005[];
SgenRes_005 = http_find_values("lr", HTTP_FORM_DATA, 3);
CHECK_FIND_RESULT(SgenRes_005,"lr","lang_zh-CN")
}
set Think_avg = 6228;
/* Keep-Alive request over connection www_google_com */
http_request ["googlw007"]
"GET /search?q="
+ http_url_encode(datapool_value(DP1, "q"))+
"&ie="
+ SgenRes_003 +
"&oe="
+ SgenRes_004 +
"&hl="
+ SgenRes_002 +
"&btnG="
+ http_url_encode(datapool_value(DP1, "btnG"))+
"&lr="
+ SgenRes_005 +
" HTTP/1.1\r\n"
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicat"
"ion/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, ap"
"plication/x-shockwave-flash, */*\r\n"
"Referer: " + SgenURI_003 + "\r\n"
/* "Referer: http://www.google.com/intl/zh-CN/" */
"Accept-Language: zh-cn\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR"
" 1.1.4322)\r\n"
"Host: www.google.com\r\n"
"Connection: Keep-Alive\r\n"
"Cookie: PREF=ID=6011af2d9ae9ecc9:TB=2:TM=1079509149:LM=1079509149:S=Bbt"
"iwXYs9ldWNF0T\r\n"
"\r\n";
{ string SgenURI_004; }
SgenURI_004 = _reference_URI; /* Save "Referer:" string */
http_header_recv ["googlw008"]200; /* OK */
http_nrecv ["googlw009"]3145; /* 3145/4855 bytes */
http_nrecv ["googlw010"]1630; /* 4775/4855 bytes */
http_nrecv ["googlw011"]100 %% ; /* Last 80 of 4855 bytes */
http_disconnect(www_google_com);
pop ;
}
DATAPOOL_CONFIG "googlw" OVERRIDE DP_NOWRAP DP_SEQUENTIAL DP_SHARED
{
EXCLUDE, "btnG", "string", "Google鎼滅储";
EXCLUDE, "q", "string", "软件测试";
}
以下是全部手工编写的使用数据池的VU脚本:
#include <VU.h>
{
push Timeout_scale = 200; /* Set timeouts to 200% of maximum response time */
push Think_def = "LR";
Min_tmout = 120000; /* Set minimum Timeout_val to 2 minutes */
push Timeout_val = Min_tmout;
DP1 = datapool_open("test"); //打开数据池
ser=sqlconnect("server","sa","8888","192.168.1.12","sqlserver");
set Server_connection = ser;
push Think_avg = 0;
for (i=0; i<10; i++)
{
datapool_fetch(DP1); //移动指针到下一记录
sqlexec ["sql_1000"] "TestDB..test " +datapool_value(DP1, "q");
}
sqldisconnect (ser);
datapool_close (DP1); //关闭数据池
}
DATAPOOL_CONFIG "test"DP_SEQUENTIAL DP_SHARED DP_WRAP
{
INCLUDE, "q", "string", "8";
}
GUI中的数据池只能手工编码修改,VU中的数据池可以通过edit――datapool infoermation进行配置。此菜单在GUI脚本下为灰色不可操作。
再问data_pool!
:(烦请楼主解答:
一旦我在我的脚本里加入datapool_value(DP1,"User Name");
就会产生编译通不过的现象!为什么?难道是我的引用方式有误?
我是这样引用的:
</requestString><body xmlns:SOAPSDK5=\"http://tempuri.org/\"><Body&g"
"t;<User Name="+datapool_value(DP1,"User Name")+" LanguageId="" Password="&"
"quot; NewPassword=""/></Body>\r\n"
难道是http协议规定的变量引用方式不是这样的?
[ Last edited by jackie_G on 2004-5-12 at 10:33 ] 错误信息是什么?
字符串引用的问题
例如:SQL = "Select * from a where column = 'name' "
这里把name 编程变量
SQL = "Select * from a where column = ' "+ Var +" ' "
上边的错误在于
语法存在错误,把
datapool_value(DP1,"User Name")
前后加号多加个双引号就可以了
[ Last edited by pcl2004_27 on 2004-5-14 at 03:23 ] 谢谢两位的解答,我搞定了!谢谢!!! 云,怎么都是笑脸
;)
:)
,)
")
测试以下 哪个是笑脸
很精采的文章!
请问jsp数据池里的字段是定义了两个还是三个啊?还有是整型还是字符串型的?看了这个帖才开始跟着做数据池,什么都不懂,望赐教! 有点复杂,呵
谢谢了!
这个我学习的第一步,谢谢海龙大哥了 很棒啊.谢谢. 是很不错啊我也正在学datapool呢? 顶一下
! 那么请问如果是C/S结构的系统,用socket协议录制的VU脚本,就不能用datapool了吗?我遇到了这个问题 可以,需要手工编码 我用socket录制出来的都是一些这样的脚本:
sock_nrecv ["4004"] 16;
sock_send
"`03da0000240000000300000000000000080000000a000000730065007200760065007200"
"7300740061007400`";
怎么能够读懂呢,搞不清哪是数据,哪是界面的 socket的数据结构一般都是公司自己定义的,想要读懂,请向开发人员索取数据结果定义。
然后根据定义,读代码。 study.... 斑竹什么时候讲讲RFT中的DataPool啊。
求助:如果是利用Robot的datapool的数据打印报表应该怎么测试
如果是利用Robot的datapool的数据打印报表应该怎么测试,字段很多,应该怎么调用数据呢!麻烦楼主回答一下!谢谢!字段包括空的的现象!
页:
[1]
2