码迷,mamicode.com
首页 > 其他好文 > 详细

VBS 学习

时间:2018-06-11 19:04:40      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:HERE   lis   空格   script   UNC   ror   rip   cat   nat   

VBS其他功能

    1. 获取系统用户名

      DimWshNetwork

      Set WshNetwork =CreateObject("WScript.Network")

      strTaccount = WshNetwork.UserName

      strRoot = "D:\"&strTaccount&"\Desktop\QAAutomation"

    2. 获取系统时间

      year(Now)& Month(Now) & day(Now) & Hour(Now) & Minute(Now) & Second(Now)

      randomize()

      dim Random:Random=int(rnd*999+1)

    3. 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个

    4. 启动应用程序

      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

 

  1. 关闭后台进程

    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

  2. 获取系统时间 

    CurrentTime = year(Now)&"-"&Month(Now)&"-"&day(Now)&"-"&Hour(Now)&":"&Minute(Now)&":"&Second(Now)

  3. 后台启动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"

  4. Others

    去掉字符串前面和后面的空格 Trim()

    从字符串中返回指定数目的字符 Mid(string, start[, length])

    从字符串右边返回指定数目的字符 Right(string, length)

    返回指定数目的从字符串左边算起的字符 Left(string, length)

    把变量b转换为字符串 a=CStr(b)

    将一个字符串中的小写字母转化为大写字母 Ucase()

    返回一个字符串在另一个字符串中首次出现的位置 InStr()

  5. Load function

     LoadFunctionLibrary "\\MGPCTFSW01\UserFolders$\"&UserAccount&"\Desktop\Portal_Smoke_1214\Functions\Functions.qfl"

     

  6. 键盘输入

     

 

         Dim wshshell

         Set wshshell=createobject("wscript.shell")

         wshshell.sendkeys"{ENTER}"

  

 

 

VBS 学习

标签:HERE   lis   空格   script   UNC   ror   rip   cat   nat   

原文地址:https://www.cnblogs.com/AmyHu/p/9168429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!