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

TC中如何添加对象及比较对象(转载)

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

 

自动化的过程中,经常需要对两个对象(或属性)进行比较,看否前后一致,来判断某个对象是否被修改过,而在TC中就提供了这样的方法:Objects.Compare(Object1,Object2)

首先,我们要添加两个对象,可以在脚本录制或回放过程添加,也可以在这之前添加,通过以下方法可以添加对象:

//添加对象属性方式软件测试专业网站:51Testing软件测试网"`yh J w`wq Z z+G
//1.Adding property collections from the Object Browser软件测试专业网站:51Testing软件测试网 xH;M-_\9QA9|
//2.Adding property collections from the Object Properties window软件测试专业网站:51Testing软件测试网^w)I+CR|J:E h1?
//3.Adding property collections from the Tools toolbar软件测试专业网站:51Testing软件测试网|w#Uif+f9~
//4.Adding property collections during recording软件测试专业网站:51Testing软件测试网$RL^6jbRO;i-A
//5.Adding property collections from scrīpts软件测试专业网站:51Testing软件测试网 PYC9Ta^ypS
//6.Adding property collections from the Objects editor软件测试专业网站:51Testing软件测试网&Z/O?bz5Fxm5R
//7.Adding property collections from the Project Explorer

接下来就是如何比较了,这些方法具体使用如下:

//在脚本中添加对象属性
e\vF{F(ERd?0procedure AddObjectfromscrīpt;软件测试专业网站:51Testing软件测试网#e^.H)h2]*Y ?X4U
var软件测试专业网站:51Testing软件测试网 U/Vc7i;W$jZEN
  w, PropertyNames, CollectionName : OleVariant;
gf _U F%U5c!HG]/t0begin
.SG KV{ Uj&k"W0  //激活窗体软件测试专业网站:51Testing软件测试网Sm \{"Hlr$E
  Aliases.TCSampleForm.Activate;软件测试专业网站:51Testing软件测试网+TXc9D.B:nB.M
  //保存当前激活的窗体对象软件测试专业网站:51Testing软件测试网 g"j+XhM
  w := Sys.Desktop.ActiveWindow();软件测试专业网站:51Testing软件测试网|v5mwjXHG.d
  //设置将要保存的属性名称  软件测试专业网站:51Testing软件测试网:|+B3Cl|T|3z
  PropertyNames := 'WndCaption';
7o3J&N#O r@#Y+t:S0  //设置在Object集合中保存的名称软件测试专业网站:51Testing软件测试网})_jP8{4M\
  CollectionName := 'TCSampleFormName';
L;xI N"] GU.f!l0  //保存激活窗体对象属性
v[z)p-?0  Objects.Save(w, CollectionName,PropertyNames);
Gqv:U1hU T+Q0end;

//比较操作数1的对象属性名称是否改变软件测试专业网站:51Testing软件测试网1\;q8W oR#oI$e@
procedure CompareOperend1;
H2k6QE8N3w0begin
fx,Gr2Yc0  if not Objects.Compare(Aliases.TCSampleOperand1, 'TCSampleOperand1') then
%gK#ErS)W0    showmessage('Objects are not identical.'+Objects.LastError)软件测试专业网站:51Testing软件测试网,K%GY)~2Y:E-l
else showmessage('Objects are identical.');
:Z9G{thQ W0end;

注,以上脚本都很简短,是因为对象做了别名映射。

 


TAG: TestComplete

 

评分:0

我来说两句

日历

« 2024-03-20  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 28571
  • 日志数: 51
  • 图片数: 1
  • 文件数: 1
  • 建立时间: 2007-10-25
  • 更新时间: 2009-02-14

RSS订阅

Open Toolbar