WEB UI自动化之旅(二)

发表于:2010-1-18 14:20

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:wuyingminhui    来源:51Testing软件测试博客

  我们将Table看作一个页面, 我们能在上面检索buttons,images,links,tables等等的对象。

  ie.row(:id, 'row1')

  ie.cell(:id, 'cell_id')

  ie.table(:index, 2)[2][2].table(:index,1)[1][1].text

  ie.table(:index, 2)[1][1].button(:name, “button_name”).click

  当我们点击按纽或者连接打开新的window,我们能使用attach去识别依靠新的window的URL或者Windowstitle。

  ie2 = Watir::IE.attach(:url, 'http://mytestsite')

  ie3 = Watir::IE.attach(:title, 'Test New Window')

  Watir也支持正则表达式,这对测试将是非常有用的,特别是对页面对象进行复杂验证时。

  JavaScript.弹出框比如警告窗口,系统安全弹出框以及其他不属于页面的窗口。我们就得依靠AutoIt来操作了。

// jsPopupWindow.rb
$ie=Watir::IE.new
javascript_page = 'C:\\Watir\\unittests\\html\\JavascriptClick.htm'
$ie.goto(javascript_page)
Thread.new { system("rubyw jscriptExtraAlert.rb")}
proc{ $ie.button(:id, 'btnAlert').click }.call
 
// jscriptExtraAlert.rb
require 'watir/WindowHelper'
helper = WindowHelper.new
helper.push_alert_button()
 
// WindowHelper.rb
class WindowHelper
   def initialize( )
       @autoit = WIN32OLE.new('AutoItX3.Control')
   end
   def push_alert_button()
       @autoit.WinWait "Microsoft Internet Explorer", ""
       @autoit.Send "{ENTER}"
   end
....
 end

32/3<123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号