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 |
Ruby擁有自己的XUNIT框架test::unit,這是框架式自動化測試的基礎。
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/