您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源功能測(cè)試工具 > Watir
Ruby+watir自動(dòng)化測(cè)試中實(shí)現(xiàn)識(shí)別驗(yàn)證碼圖片
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/3/22 10:54:28 ] 推薦標(biāo)簽:

復(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對(duì)象獲取不到新的驗(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

上一頁(yè)12下一頁(yè)
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd