[Watir]Web对象属性识别
来源:互联网 发布:java自定义构造函数 编辑:程序博客网 时间:2024/05/16 17:15
我们知道,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操作脚本,呵呵...
- [Watir]Web对象属性识别
- [Watir]异常对象识别
- Watir 进行对象识别方式
- 异常对象识别(watir应用解决方案)
- 【Ruby+Watir测试框架系列讲座 3】测试对象识别
- 如何在 Watir 中识别各种 HTML 对象
- watir识别控件
- watir框架支持的元素及各元素识别属性列表
- watir web测试框架
- Watir Popup对象处理
- watir不能识别frame解决办法
- 如何在 Watir 中识别各种 HTML 对象(全/更新到 2007-6-20)
- 【Ruby+Watir测试框架系列讲座 4】各类Web控件对象的自动化操作
- 在Watir中识别HTML标签
- 标识符属性生成策略与对象识别
- watir
- QTP 无法识别web对象原因
- watir中如何获取dom属性?
- 将一整数逆序
- 软件开发不是一门艺术
- 超短波通信原理
- GamerClass Shading系统设计【二】普遍性与特殊性
- 我的第一篇
- [Watir]Web对象属性识别
- 一位软件工程师的6年总结(转)
- 数据库中相邻两行的交易时间差
- WTL8.1 发布了
- iphone模拟器的运行目录
- 94
- 软件顾问(咨询师)的素质
- 澄清P问题、NP问题、NPC问题的概念
- C#异步调用飞信WebService实时接收短信