|
在各位论坛朋友的帮助下,我终于如期搞定了这个CASE。
大概内容是,建立日志文件,从配置文件中读取参数,并将相关参数赋值到QTP的脚本中,调用外部TCL程序发包验证,最后写日志。
此过程感谢论坛里的各种精华帖,以及各位朋友,xiaonan斑竹。
'Creat log file
Dim LOGFile, fso, MyFile
LOGFile="C:\Log.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
'Whether judging file exists or not
If fso.FileExists(LOGFile) = False Then
Set MyFile = fso.CreateTextFile(LOGFile, True)
MyFile.Close
end if
'Reading parameter from config file
Dim CONFIGFile,objFSO,strText
Const ForReading = 1
CONFIGFile="C:\config.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(CONFIGFile, ForReading)
strText = objTextFile.ReadALL
objTextFile.Close
Execute strText
'Split the "Lan_Start_IP"
tmp1 = Split(Lan_Start_IP, ".")
lanip1 = tmp1(0)
lanip2 = tmp1(1)
lanip3 = tmp1(2)
lanip4 = tmp1(3)
'Split the "Wan_Start_IP"
tmp2 = Split(Wan_Start_IP, ".")
wanip1 = tmp2(0)
wanip2 = tmp2(1)
wanip3 = tmp2(2)
wanip4 = tmp2(3)
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("contents").Link("Firewall Rules").Click
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe").WebButton("Add").Click
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebList("service_list").Select GW_SERVICE
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebList("fwout_action").Select GW_ACTION
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebList("fwout_laniptype").Select LanMode
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebEdit("lan_start_ip1").Set lanip1
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebEdit("lan_start_ip2").Set lanip2
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebEdit("lan_start_ip3").Set lanip3
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebEdit("lan_start_ip4").Set lanip4
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebList("fwout_waniptype").Select WanMode
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebEdit("wan_start_ip1").Set wanip1
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebEdit("wan_start_ip2").Set wanip2
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebEdit("wan_start_ip3").Set wanip3
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebEdit("wan_start_ip4").Set wanip4
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebList("fwout_logging").Select Log_Mode
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebButton("Apply").Click
'Send the packet by IXIA,the rule would to be functioning normally.
SystemUtil.Run "tclsh.exe","main.tcl","C:\ixia\","open"
wait 10
If Browser("NETGEAR Router").Dialog("Microsoft Internet Explorer").exist Then
Browser("NETGEAR Router").Dialog("Microsoft Internet Explorer").WinButton("OK").Click
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_2").WebButton("Cancel").Click
'If warnning windows will display ,write log file with " add runle failure"
Set MyFile = fso.OpenTextFile(LOGFile, 8, True)
MyFile.WriteLine("")
MyFile.WriteLine(" " & Cstr(Now) & " ---------------------------------------------------------")
MyFile.WriteLine("LOG Information!")
MyFile.WriteLine("Add rule failure!")
MyFile.Close
Browser("NETGEAR Router").Page("NETGEAR Router").Frame("formframe_3").WebButton("Apply").Click
else
'Write the log, add rules success.
Set MyFile = fso.OpenTextFile(LOGFile, 8, True)
MyFile.WriteLine("")
MyFile.WriteLine(" " & Cstr(Now) & " ---------------------------------------------------------")
MyFile.WriteLine("LOG Information!")
MyFile.WriteLine("add rule success!")
MyFile.Close
End If |
|