VBS 学习
VBS其他功能
獲取系統用戶名
DimWshNetwork
Set WshNetwork =CreateObject("WScript.Network")
strTaccount = WshNetwork.UserName
strRoot = "D:\"&strTaccount&"\Desktop\QAAutomation"
獲取系統時間
year(Now)& Month(Now) & day(Now) & Hour(Now) & Minute(Now) & Second(Now)
randomize()
dim Random:Random=int(rnd*999+1)
Split ,Ubound,For each
Dim MyStrs
MyStrs=split("a,b,c,d",",")
msgbox ubound(MyStrs)
For each Strs In MyStrs
Print Strs
Next
返回一個下標從0到ubound(MyStrs)的數組,數組元素共ubound(a)+1個
啟動應用程序
a.
SetStartURL ="https://agent.monthly.qa.motoristsinsurance.com/home/"
Set IE =CreateObject("InternetExplorer.Application")
IE.Visible= true
IE.NavigateStartURL????
b.
Dim IE,Chrome, strURL
IE ="C:\Program Files\Internet Explorer\iexplore.exe"
Chrome ="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
strURL ="https://agent.monthly.qa.motoristsinsurance.com/home/"
'SystemUtil.Run? IE ,strURL ,,,3
SystemUtil.Run? Chrome ,strURL ,,,3
?
關閉后臺進程
On ErrorResume Next
? ?Set objWMIService =GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
?? Set arrProcesses =objWMIService.ExecQuery( "select * from win32_process where Name='"&strProcName&"'" )
? ?For Each proccess In arrProcesses
? ?proccess.Terminate 0
Next
獲取系統時間?
CurrentTime = year(Now)&"-"&Month(Now)&"-"&day(Now)&"-"&Hour(Now)&":"&Minute(Now)&":"&Second(Now)
后臺啟動UFT跑vbs腳本
'Create QTP object
Set QTP = CreateObject("QuickTest.Application")
QTP.Launch
QTP.Visible = TRUE
'Open QTP Test
QTP.Open "\\MGPCTFSW01\UserFolders$\t165050\Desktop\Portal_Smoke_1214\Portal_MainScript", TRUE
'Set Result location
Set qtpResultsOpt = CreateObject("QuickTest.RunResultsOptions")
qtpResultsOpt.ResultsLocation = "\\MGPCTFSW01\UserFolders$\t165050\Desktop\Portal_Smoke_1214\Result"
'Run QTP test
QTP.Test.Run qtpResultsOpt
'Close QTP
QTP.Test.Close
QTP.Quit
?
' batch run vbs: CScript "\\MGPCTFSW01\UserFolders$\t165050\Desktop\QTP.vbs"
Others
去掉字符串前面和后面的空格 Trim()
從字符串中返回指定數目的字符 Mid(string, start[, length])
從字符串右邊返回指定數目的字符 Right(string, length)
返回指定數目的從字符串左邊算起的字符 Left(string, length)
把變量b轉換為字符串 a=CStr(b)
將一個字符串中的小寫字母轉化為大寫字母 Ucase()
返回一個字符串在另一個字符串中首次出現的位置 InStr()
Load function
?LoadFunctionLibrary "\\MGPCTFSW01\UserFolders$\"&UserAccount&"\Desktop\Portal_Smoke_1214\Functions\Functions.qfl"
?
鍵盤輸入
?
?
???????? Dim wshshell
????? ?? Set wshshell=createobject("wscript.shell")
??? ???? wshshell.sendkeys"{ENTER}"
??
?
?
轉載于:https://www.cnblogs.com/AmyHu/p/9168429.html
總結
- 上一篇: 实用比较,帮你决策到底选择Vue还是An
- 下一篇: Android Camera2 拍照(四