您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 > Watir
Watir--Web自動(dòng)化UI測(cè)試的框架
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/3/14 15:40:45 ] 推薦標(biāo)簽:

// 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,這是框架式自動(dòng)化測(cè)試的基礎(chǔ)。

  以下是一個(gè)簡(jiǎn)單的實(shí)例:

require 'unittests/setup'
     require 'test/unit'
 class TC_Fields < Test::Unit::TestCase
      include Watir
 
      def setup()
          gotoTestPage
      end
      def gotoTestPage()    $ie.goto($htmlRoot + "textfields1.html")end
      def test_tabbing
          $ie.text_field(:name, 'text1').focus
          $ie.send_keys('{tab}')
          $ie.send_keys('Scooby')
          assert('Scooby', $ie.text_field(:name, 'beforetest').value)
      end
 
      def test_enter
          $ie.text_field(:name, 'text1').focus
          $ie.send_keys('{tab}{tab}{tab}{tab}')
          $ie.send_keys('Dooby{enter}')
          assert($ie.contains_text('PASS'))
      end
 end


對(duì)RUBY和WATIR框架進(jìn)行進(jìn)一步的分析。主要針對(duì)WATIR源碼進(jìn)行簡(jiǎn)單的分析。

  一般的WATIR自動(dòng)化測(cè)試都是以對(duì)瀏覽器的初始化開始的:

#Jaycer.D.Woo#
 
#open the IE browser
ie = Watir::IE.new
# print some comments
ie.goto test_site

  這是簡(jiǎn)單的初始化IE并連接到URL(test_site)。

  這里用的是IEController的navigate屬性轉(zhuǎn)到相應(yīng)的URL(與.NET中的nevigate同質(zhì)):

# * url - string - the URL to navigate to

def goto( url )

    @ie.navigate(url)

    wait()

    sleep 0.2

    return @down_load_time

end


一般對(duì)PAGE中的object操作:

  Text fields

  ie.text_field(:name, "field_name").set("Watir World")

  對(duì)應(yīng)的源碼處理:

def text_field(how , what=nil)

   return TextField.new(self, how, what)

end

  在CLASS TextField中有:

def initialize( ieController, how , what )

      @ieController = ieController

      @how = how

      @what = what

                if(how != :from_object) then

               @o = @ieController.getObject(@how, @what, supported_types)

     else

               @o = what

     end

      super( @o )

end

  TextField的初始化方法還有supported_types,size,maxLength,assert_not_readonly,verify_contains,dragContentsTo,append,set,clear等方法。

上一頁123下一頁
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd