在写自动化脚本过程中,经常需要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