def Goto_web(ie,testSite) #打开指定URL的页面
begin
ie.goto(testSite)
rescue StandardError , NameError => boom #捕获异常
puts "Goto Web Error: "+ boom
if $refreshCount < 10
Goto_web(ie,testSite)
sleep 1
$refreshCount += 1 #用于加载失败时刷新页面的计数器
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 #初始化加载失败时的计数器
sleep 1
end
end
login
require 'Config.rb'
#Suc001:WAN配置操作成功
#Err001:缺少必要配置项没有WAN连接可查询
#Err002:输入参数不合法
def Web_Login(testSite,strCmdArray)
##变量定义部分
##打开页面部分
Goto_web($ie,testSite) #打开指定URL的页面
username = "root" unless (username =get_InputPara(strCmdArray,"username")) != nil
password = "admin" unless (password =get_InputPara(strCmdArray,"password")) != nil
Logon_web($ie,username,password) #使用帐号密码登录页面
#Goto_page($ie,strCmdArray[0]) #根据link,打开指定页面
sleep 1
##实际操作部分
#查看WAN连接
$returnStr = "{reply #{$strCmdPort} {return -code 0 {0 Suc001}}}}"
$ie.close
return 0
end