def Goto_web(ie,testSite) #打開指定URL的頁(yè)面
begin
ie.goto(testSite)
rescue StandardError , NameError => boom #捕獲異常
puts "Goto Web Error: "+ boom
if $refreshCount < 10
Goto_web(ie,testSite)
sleep 1
$refreshCount += 1 #用于加載失敗時(shí)刷新頁(yè)面的計(jì)數(shù)器
else
$returnStr = "{reply #{$strCmdPort} {return -code 0 {1 Err001}}}}"
ie.close
end
ensure
if ie.url != ""
ie.maximize
ie.bring_to_front
end
end
end
def Logon_web(ie,username,password,language = "English")
$var_language = "NULL"
if ie.contains_text("Please enter your username and password") == nil
return 0
else
ie.text_field(:name, "Username").set(username)
ie.text_field(:name, "Password").set(password)
$var_language = ie.select_list(:name, "language").getSelectedItems()
ie.select_list(:name, "language").select(language)
ie.link(:id, "btnLogin").click
$refreshCount = 0 #初始化加載失敗時(shí)的計(jì)數(shù)器
sleep 1
end
end
login
require 'Config.rb'
#Suc001:WAN配置操作成功
#Err001:缺少必要配置項(xiàng)沒有WAN連接可查詢
#Err002:輸入?yún)?shù)不合法
def Web_Login(testSite,strCmdArray)
##變量定義部分
##打開頁(yè)面部分
Goto_web($ie,testSite) #打開指定URL的頁(yè)面
username = "root" unless (username =get_InputPara(strCmdArray,"username")) != nil
password = "admin" unless (password =get_InputPara(strCmdArray,"password")) != nil
Logon_web($ie,username,password) #使用帳號(hào)密碼登錄頁(yè)面
#Goto_page($ie,strCmdArray[0]) #根據(jù)link,打開指定頁(yè)面
sleep 1
##實(shí)際操作部分
#查看WAN連接
$returnStr = "{reply #{$strCmdPort} {return -code 0 {0 Suc001}}}}"
$ie.close
return 0
end