我不在办公室就在星巴克,我不在星巴克就在去星巴克的路上

TC中Regions对象的使用介绍(转载)

上一篇 / 下一篇  2008-05-06 16:49:42 / 个人分类:TestComplete

 

在TC中,提供了一个Regions对象集合,专门管理图像对象,可以通过以下方法添加图像对象到Regions集合中:

//添加图像方式:软件测试专业网站:51Testing软件测试网:@T-K-T/@q `
//1.Add images from the Regions editor
X LIa6C0SE0//2.Add images from the Project Explorer软件测试专业网站:51Testing软件测试网1XMv_r,n-i9j&r!B
//3.Add images from the Image Viewer软件测试专业网站:51Testing软件测试网albFi(W;I
//4.Add images during recording
p+XH@"~ qE,X0//5.Add images from scrīpts

Regions对象封装了几个常用的方法,如Regions.AddPicture(添加图像)、Regions.GetPicture(获取图像)、Regions.FindRegion(查找图像)、Picture.Find(查找图像)等,具体使用如下:

//在脚本中添加图像
c7G3u#xdhK,Q:R0procedure AddImageFromscrīpt;
3}3`~ qA0begin软件测试专业网站:51Testing软件测试网&P%@z~`%|~
  //添加主窗体图像软件测试专业网站:51Testing软件测试网 R:O]F,kofM k[
  Regions.AddPicture(Aliases.TCSampleForm,'TCSampleForm');软件测试专业网站:51Testing软件测试网w`oF C/U2} T*Y"m
  //添加主窗体中操作数1的图像
F P5j0}2Pw4R0  Regions.AddPicture(Aliases.TCSampleOperand1,'TCSampleOperand1'); 
5gP g9j ?7[0end;

//回放脚本过程中截取图像与在Regions集合中的图像进行比较
/^D[4_W0procedure CompareImage_Playback;   软件测试专业网站:51Testing软件测试网+{I5Ed0zT.X}
begin
V7@N%h _7T{0NC0  if not Regions.Compare('TCSampleFormChangeName', Aliases.TCSampleForm) then软件测试专业网站:51Testing软件测试网J f(wr&R(O9B
    Log.Error('The compared regions are not identical.', Aliases.TCSampleForm.Name);  软件测试专业网站:51Testing软件测试网b:BTC%USGaw#W2}
end;

//Regions集合中两个图像进行比较软件测试专业网站:51Testing软件测试网8c#X8j1I_h]1t
procedure CompareImage_Regions; 
2J7bl8P[R#o0begin软件测试专业网站:51Testing软件测试网.C/Jw/Z%M[ v0A
  if not Regions.Compare('TCSampleFormChangeName', 'TCSampleForm') then
ny_L'g y.x-G{ ln0    Log.Error('The compared regions are not identical.', 'TCSampleForm');
yU*O w[(@0end;

//使用Picture对象比较两个图像  软件测试专业网站:51Testing软件测试网Mn6y*~]1B9R8Jl?
procedure CompareImage_Picture;
? P"V/Vo oD3}0var pict1,pict2 : olevariant;
+U;r([ CU ~2\ sY5ZY0begin  软件测试专业网站:51Testing软件测试网A`x"z @\QM H
  pict1 := Regions.GetPicture('TCSampleForm');软件测试专业网站:51Testing软件测试网 F)lY1pY\-cQ
  pict2 := Regions.GetPicture('TCSampleFormChangeName');
%EB dr"kTC$F0  if not pict1.Compare(pict2) then软件测试专业网站:51Testing软件测试网 J0w0N Ay3G3j
    Log.Error('The compared regions are not identical.');    
8k:c%`~M G~(xa0end;

//使用Regions对象的FindRegion方法查找图像 软件测试专业网站:51Testing软件测试网a.W k$Dv#unJ
procedure FindImage_Regions;软件测试专业网站:51Testing软件测试网([ u&x V#aFm5Z%J
var pict1,pict2 : olevariant;软件测试专业网站:51Testing软件测试网b2j!r*J3{'m
begin  
1T2CLM N j0  if (Regions.FindRegion('TCSampleOperand1','TCSampleForm') = nil) then软件测试专业网站:51Testing软件测试网[5FW.G,ZA
    Log.Warning('Picture not found.');    软件测试专业网站:51Testing软件测试网\u yz-~ {Rh
end;

//使用Picture对象的Find方法查找图像软件测试专业网站:51Testing软件测试网[BfK4a.^ ?o
procedure FindImage_Picture;
me}B,CJu J'i0var pict1,pict2 : olevariant;软件测试专业网站:51Testing软件测试网2X)}X0U_O E wDw:a8X
begin  软件测试专业网站:51Testing软件测试网yf-Yx_H
  pict1 := Regions.GetPicture('TCSampleForm');
2sam6J3b0  pict2 := Regions.GetPicture('TCSampleOperand1');软件测试专业网站:51Testing软件测试网8ih iO(~
  if (pict1.Find(pict2) = nil) then软件测试专业网站:51Testing软件测试网X i$m0Ox
    Log.Warning('Picture not found.');       
7F't4c!J1WlQ!D6t0end;
M"k\4e~d0


TAG: TestComplete

 

评分:0

我来说两句

Open Toolbar