在寫自動化腳本過程中,經常需要require其他文件。
一、require單個文件
require File.expand_path('../../common/xiaozhan', __FILE__)
二、require多個文件(當前目錄下所有.rb文件,除了文件名中包含了suite的rb文件)
Dir['./*.rb'].each{ |file|
unless file.include? "suite"
require file
end
}
三、watir上傳文件
vpath = Dir.pwd //當前目錄
vpath = vpath.gsub(/TestCase.*/,'TestData/Waterlilies.jpg')
vpath = vpath.gsub("/",'\\') //待上傳圖片的路徑
ai = WIN32OLE.new("AutoItX3.Control")
ai.Send vpath
sleep 2
ai.Send('{ENTER}')
四、watir處理js彈框
def check_for_popups
autoit = WIN32OLE.new('AutoItX3.Control')
# Do forever - assumes popups could occur anywhere/anytime in your application.
loop do
# Look for window with given title. Give up after 1 second.
ret = autoit.WinWait('來自網頁的消息', '', 5)
# If window found, send appropriate keystroke (e.g. {enter}, {Y}, {N}).
if (ret==1)
msg=autoit.WinGetText('來自網頁的消息') //獲取彈框的內容
autoit.Send("{enter}")
end
return msg
end
end
五、獲取彈出框的hwnd值
getForegroundWindow = Win32API.new('user32', 'GetForegroundWindow',[] , 'L')
hwnd = getForegroundWindow.call