复制代码
def CheckCode_ok(gifurl,CheckCode)
#获取验证码图片
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
#执行批处理文件
system("c:\CheckBat.bat")
#获取txt中的验证码
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
复制代码
调用:
复制代码
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 #获取新的验证码以后,加个sleep等待时间,貌似IE需要时间缓存新的验证码code,否则@b对象获取不到新的验证码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