记录阿里巴巴QA架构组成长点滴。2008年关键词为效率,技术,影响力!QA/测试架构师定义:开发和设计测试框架测试库;纵横全局的考虑产品的功能,设计复杂的测试系统;负责研发某一项特定的测试技术;为公司考虑如何提高测试效率。领导公司测试技术的发展和测试策略上的方向,关注整个公司的测试部门的问题,前瞻性的考虑未来的版本的测试策略和技术。测试架构师计划/设计测试平台,关注着产品的测试过程,提供咨询服务,影响到公司内的测试机构测试社区,以及开发机构等,对产品各个方面施加深远而正确的影响,最终提高整体软件质量。

watir中,类似QTP object spy等方法替代实行

上一篇 / 下一篇  2008-07-06 23:57:01 / 个人分类:自动化测试框架与实现

by Wiston Li


我们知道,QTP提供object spy工具,对象库录制功能,或描述性编程提供给我们快捷识别对象,
一定程度上可以做到脚本批处理生成。相应的,我在想如此好的工具和技术,为啥watir没有支持?
也许将来,在自动化同学与watir开发团队努力下,可满足这一需求。

另一个问题抛出,是否为了准备watir脚本,我们一定要在那么冗长的代码,查找并挑选我们想要操作的对象?
给出我的简单总结,

1, 类似object spy工具,为微软为开发人员做的工具ie developer toolbar,可以借助它通过指针指示
对象,在attribute view中找到相应属性。

2,类似描述性编程,

在cmd中运行irb,

如: puts 2+2
打印4,可以通过命令实现所见即所得,

如:
require ‘watir’
ie=Watir::IE.start(‘http://localhost:8080’)
ie.show_all_objects

结果:

-----------Objects in  page -------------
text              name=name           id= 

如:ie.text_field(:name, 'name').flash
结果:使操控对象webedit框有黄色闪动效果.


更有意思的是,当我把鼠标焦点移到某个webedit上,
然后:
irb> puts ie.show_active
text         name=name          
id=          value=             
alt=         src=               
innerText=
=> nil
在这里,watir将帮助我们标识当前active的对象.
对于button和其他对象,也可以通过tab key来实现焦点移动,
再用alt + tab 激活irb窗口,用相同show active方法实现.

再如:

irb> puts ie.show_active
submit              name=submit_logon  
id=                 value=Login        
alt=                src=               
innerText=
=> nil


irb> ie.text_field(:name, 'name').set(‘Test1’)
=> nil

可以参照watir api对web edit对象进行内容清除,追加等.
另外可以输出当前IE对象的HTML

irb> puts ie.html
<H1>
<P align=center>Create the First Job </P></H1>
<TABLE cellSpacing=0 cellPadding=3 border=0>
<TBODY>
<TR>
<TD align=middle width="40%">
<FORM id=job name=job action=job method=get><INPUT type=hidden value=22909012 name=session></INPUT>
<TABLE cellSpacing=0 cellPadding=3 border=0>
<TBODY>

或只输出text :

irb> puts ie.text
Create the First Job
 Please create the first job

 Make it a background job
If you make this job a background job, it will be a job that accumulates time when you're not doing any specific task. You'll start it in the morning,
 do your work - starting and pausing other jobs - then stop it when you're done for the day.
Each time you pause another job, the background job will resume accumulating time.
If you don't have a background job, you'll have to manage time more explicitly.
=> nil
irb(main):024:0>


对于页面中只有一个同特征对象时可以用index, 如:
ie.text_field(:index, 1).set(‘Testing for Bugs’)

irb> ie.button(:index,1).click
=> nil

可以借用show_all_objects方法显示页面中所有对象
也可以显示某一特定类型对象, 像:


show_images Show all the images in the document
show_spans Show all the span tags in the document
show_labels Show all the labels in the document
show_links Show all the links in the document
show_divs Show all the div tags in the document
show_frames Show all the frames in the document
show_forms Show all the forms in the document

如这里用ie.show_table作为示例
irb> ie.show_tables
Found 8 tables
1  id=      rows=1   columns=3
2  id=      rows=2   columns=1
3  id=      rows=3   columns=1
4  id=      rows=2   columns=1
5  id=      rows=3   columns=1
6  id=      rows=1   columns=1
7  id=      rows=3   columns=1
8  id=recent_records      rows=2   columns=1
=> nil

我们可用flash方法来标识对象,
irb> ie.table(:id , ‘recent_records’).flash

也可以只显示特定table的html code,

irb> puts ie.table(:id , ‘recent_records’).html

<TABLE id=recent_records cellSpacing=0 cellPadding=3 width="66%" align=center border=1><TBODY>
<TR bgColor=#66ffff>
<TD align=middle colSpan=4>Recent Records </TD></TR>
<TR bgColor=#ccffff>
<TD>Testing for Bugs </TD>
<TD>10:05 PM </TD>
<TD>0.00 hours </TD>
<TD><B>running</B> </TD></TR></TBODY></TABLE>

这里可用ruby内置函数 to_a输出行记录数组,

irb> irb(main):009:0> my_array = ie.table(:id , 'recent_records').to_a
=> [["Recent Records"], ["Testing for Bugs", "10:05 PM",

以上可以看到,采用 show_XXX方法,枚举同特征对象,
是否感觉到类似QTP:create descrīption.../ mic class='web object'/...的方法?

类似,甚至可以通过修改底层show_XXX代码,来批处理生成脚本,
如生成已经填值的text field操作脚本,呵呵...

 

 

 

 

 

 

 

 

 

 

 


 


TAG: 自动化测试框架与实现

引用 删除 叼炸哥1   /   2016-05-26 17:39:20
1
 

评分:0

我来说两句

日历

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

数据统计

  • 访问量: 153178
  • 日志数: 163
  • 文件数: 1
  • 建立时间: 2008-02-26
  • 更新时间: 2008-12-10

RSS订阅

Open Toolbar