如何安装和使用RAutomation
生活随笔
收集整理的這篇文章主要介紹了
如何安装和使用RAutomation
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天在本地的gem list中發現了1個叫做rautomation的擴展,仔細一看原來這是個使用watir的語法進行windows程序測試的工具庫,不敢獨享,略志一二。
首先看一下rautomation的簡介
RAutomation is a small and easy to use library for helping out to automate windows and their controls for automated testing. RAutomation是個小巧易用的工具庫,其主要用來進行windows窗體和控件的自動化測試工作。
RAutomation的特點
- Easy to use and user-friendly API (inspired by Watir http://www.watir.com) 易用的watir like API
- Cross-platform compatibility 跨平臺
- Easy extensibility - with small scripting effort it's possible to add support for not yet supported platforms or technologies 易擴展
RAutomation的用法
require "rautomation"# 通過匹配部分標題來獲取窗口 window = RAutomation::Window.new(:title => /part of the title/i) window.exists? # => true window.title # => "blah blah part Of the title blah" window.text # => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ultricies..."# 控件操作 window.text_field(:class => "Edit", :index => 0).set "hello, world!" button = window.button(:text => "&Save") button.exists? # => true button.click# 獲取當前所有窗口的句柄 all_windows = RAutomation::Window.windows all_windows.each {|window| puts window.hwnd}# 根據標題匹配所有窗口 window = RAutomation::Window.new(:title => /part of the title/i) windows = window.windows puts windows.size # => 2 windows.map {|window| window.title } # => ["part of the title 1", "part of the title 2"] window.windows(:title => /part of other title/i) # => all windows with matching specified title# 遍歷窗口上所有的button控件 window.buttons.each {|button| puts button.value} window.buttons(:value => /some value/i).each {|button| puts button.value}# 使用autoit adapter來定位和操作窗口 # 注意:需要注冊AutoitX的DLL window2 = RAutomation::Window.new(:title => "Other Title", :adapter => :autoit) # use AutoIt adapter # 使用autoit的原生方法來操作控件 # use adapter's (in this case AutoIt's) internal methods not part of the public API directly window2.WinClose("[TITLE:Other Title]")RAutomation的安裝
安裝了watir 1.9后該擴展自動安裝。另外也可以使用下面的命令進行安裝
gem install rautomation總結
以上是生活随笔為你收集整理的如何安装和使用RAutomation的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 脊髓损伤截瘫就用养髓复痿汤?
- 下一篇: vb 用代码添加控件