復(fù)制代碼
def CheckCode_ok(gifurl,CheckCode)
#獲取驗(yàn)證碼圖片
require 'net/http'
#Net::HTTP.start(url) do |http|
#resp = http.get(gifurl)
resp = Net::HTTP.get_response(URI(gifurl))
File.open("C:\CheckImg.jpg", "wb") do |file|
file.write(resp.body)
file.close
end
#end
#執(zhí)行批處理文件
system("c:\CheckBat.bat")
#獲取txt中的驗(yàn)證碼
if File.exists?("c:\CheckCode.txt") ==true
File.open("c:\CheckCode.txt","r") do |line|
CheckCode=line.readline
line.close
end
end
puts CheckCode
return CheckCode
end
復(fù)制代碼
調(diào)用:
復(fù)制代碼
def xxx_www_login(user,pwd)
LoadObject("../../testcase/xxx/xxx.yaml")
times = 0
loop do
times += 1
code = CheckCode_ok("http://xxx.xxxx.com/CheckImg.aspx/CheckImg.gif",code)
puts code
sleep 10 #獲取新的驗(yàn)證碼以后,加個(gè)sleep等待時(shí)間,貌似IE需要時(shí)間緩存新的驗(yàn)證碼code,否則@b對象獲取不到新的驗(yàn)證碼code而登陸失敗
if @b.text.include?(ExpectData("expect1")) == true #是否存在“商家登錄”
xxx_login(user,pwd,code)
elsif @b.text.include?(ExpectData("expect2")) == true #是否存在“退出”
xxx_www_logout
xxx_login(user,pwd,code)
end
break if times >= 5 or @b.text.include?(ExpectData("expect2")) == true #是否存在“退出”
end #loop end end