速度测试-未完成

上一篇 / 下一篇  2010-08-31 17:51:48 / 个人分类:QTP

'Declare Variables
Dim TestData_Location
Dim Login_Check
Dim TestCase
Dim start_Column
Dim start_Row
Dim brand_Row
Dim brand_Column
Dim TestPC    'The PC you want to test
Dim TestDevice 'The device you want to test "4K_001, 4K_003, C028"
Dim record_PC 'Find the Test PC row number in the Excel'
Dim record_row 'Find the Test device row number in the Excel'
Dim WorkingDir
Dim CreateFile_template
Dim testdataFolder
Dim fileszie
Dim sourceFolder
Dim CF_Storage
Dim Copy_Check

'initiate Variable
TestData_Location=""
Login_Check=Log_in("")
TestCase="C:\test.xls"
start_Column=66
start_Row=3
brand_Row=17
brand_Column=72
TestPC="##"
TestDevice="##"
WorkingDir="C:\Integration_test"
CreateFile_template="C:\test.txt"
testdataFolder="11"
sourceFolder="22"
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const sourceFile = "##"
CF_Storage=GetDriveLetter("CF_Storage")

OpenExcel()
Update_Result()

'Make sure your are authorized to access the server
Public Function  Log_in(ip,user,pw)
    Set bjShell=CreateObject("Wscript.Shell")
    objShell.Run ip
    Set bjShell=nothing
  
    Set fso=CreateObject("Scripting.FileSystemObject")
   If fso.FileExists(TestData_Location) Then
     Log_in=True
    Else
     Log_in=False
    End If
Set fso=nothing
End Function

Public Function OpenExcel()
 Set fso=CreateObject("Scripting.FileSystemObject")
 Set Excel=CreateObject("Excel.Application")
 oExcel.Visible=True
 
 'Check if the test case is Exist
 If fso.FileExists(TestCase)Then
  Set bjWorkBook = oExcel.Workbooks.Open(TestCase)
  sheet_count=oExcel.Sheets.Count
  oExcel.Sheets.Item(sheet_count).Select
  Set bjSheet=oExcel.Sheets(sheet_count)
  With objSheet
     For i=start_Row To brand_Row
      If RegExpTest(TestPC,.Range(Chr(start_Column)+CStr(i))) Then
       Exit For
      End if      
     Next
     record_PC=i
     For i=record_PC+2 To record_row+4
      If RegExpTest(TestDevice,.Range(Chr(start_Column)+CStr(i))) Then
       Exit For
      End if
     Next
     record_row=i
        For i=start_Column+1 To  brand_Column
         If RegExpTest("8G",.Range(Chr(i)+CStr(record_PC))) Then
          Call Record_8G()
         ElseIf RegExpTest("1k",.Range(Chr(i)+CStr(record_PC))) Then
          Call Record(512)
         ElseIf RegExpTest("2k",.Range(Chr(i)+CStr(record_PC))) Then
          Call Record(1024)
         ElseIf RegExpTest("4k",.Range(Chr(i)+CStr(record_PC))) Then
          Call Record(2048)
         ElseIf RegExpTest("8k",.Range(Chr(i)+CStr(record_PC))) Then
          Call Record(4096)
         ElseIf RegExpTest("16k",.Range(Chr(i)+CStr(record_PC))) Then
          Call Record(8192)
         Else
          MsgBox "Error, wrong case name"
         End if
        Next
        End with
 End If
 oExcel.Quit
 Set Excel=nothing
 Set fso=Nothing
End Function

Public Function Record_8G()
 Set fso=CreateObject("Scripting.FileSystemObject")
  If Not fso.FolderExists(WorkingDir+"\")Then
   fso.CreateFolder WorkingDir+"\"
  End If
  If Not fso.FolderExists(WorkingDir+"\8G") Then
   fso.CreateFolder WorkingDir+"\8G"
  End if
  If fso.FileExists("##") then
   fso.CopyFile "##", WorkingDir+"\8G\"
  End If
  If fso.FileExists( WorkingDir+"\"+"OfficeGuardain.zip") Then
   UnzipFile WorkingDir+"\"+"OfficeGuardain.zip",WorkingDir+"\8G"
  End if
 Set fso=nothing
End Function

Public Function Record(perFile)
 Dim copyTime
 CreateFiles(perFile)
 Copy59Times(perFile)
End Function

Function RegExpTest(patrn, strng)
  Dim regEx, Match, Matches  
  Set regEx = New RegExp  
  regEx.Pattern = patrn 
  regEx.IgnoreCase = True 
  regEx.Global = True 
  If regEx.Test(strng) Then
   RegExpTest=True
  Else
    RegExpTest=False
  End if
End Function

Public Function UnzipFile(file_zip_location, file_unzip_location)
    winRarLocation = "C:\Program Files\WinRAR\WinRAR.exe"
    zipToFolder = file_unzip_location
    dataCab_location=file_zip_location
    unzipCommand = "cmd /k CD C:\&"+chr(34)+winRarLocation+chr(34) + " x " + dataCab_location + " " + zipToFolder
    Set bjShell=CreateObject("Wscript.Shell")
    objShell.Run unzipCommand
    Set bjShell=nothing

    set pro = getobject("winmgmts:\\.").instancesof("Win32_Process")
 Do
  check_process=false
  For each ps in pro  
   If UCase(ps.name)="WINRAR.EXE" Then
    WScript.Sleep 10000
    check_process=true
    Exit For
           End If

        Next

   If check_process=true Then
    WScript.Sleep 10000
   Else
     UnzipFile=True
     Exit Do
    End If
    Set pro = getobject("winmgmts:\\.").instancesof("Win32_Process")
    Loop
   
    Set pro = getobject("winmgmts:\\.").instancesof("Win32_Process")
   
 For each ps in pro
  If UCase(ps.name)="CMD.EXE" Then
   ps.Terminate
  End If
 Next
 Set  pro=nothing
End Function

Public Function CreateFiles(perFile)
   filesize = CInt(perFile)

  
   WorkingDir_temp=WorkingDir+"\"+CStr(perFile)+"\"
   File_Copied_Location=WorkingDir_temp+sourceFile

   Set bjFso=CreateObject("Scripting.FileSystemObject")
   If Not objFso.FolderExists(WorkingDir_temp)then
    objFso.CreateFolder(WorkingDir_temp)
   Else
    copyCheck=False
    Exit Function
   End If

   'objFso.CopyFile CreateFile_template,WorkingDir_temp
   Set bjFso=nothing
   currentFolder=WorkingDir_temp
  
   Wscript.Echo ("MakeSure your folder&file exist, Starting...")

   Dim fso, MyFile, testFolder
   testFolder = currentFolder + "\" + testdataFolder
   Set fso = CreateObject("Scripting.FileSystemObject")
  
   If fso.FolderExists (testFolder  ) Then
      fso.DeleteFolder( testFolder  )
   End If
   fso.CreateFolder ( testFolder )

  
  'Set MyFile = fso.OpenTextFile( currentFolder + "\" + sourceFile, ForReading , True)
  Set MyFile = fso.OpenTextFile( CreateFile_template, ForReading , True)
  ReadLineTextFile MyFile, WorkingDir_temp,filesize
  MyFile.Close
  Wscript.Echo ("Create Finished")
End Function

Sub ReadLineTextFile (File,strPath,filesize)
   Dim nCount, folder, ret, LineText
   nCount=1
   'folder = ""
  
   'Do Until IsNull( LineText ) 'or (nCount>20)
    Do Until File.AtEndofStream  
       LineText = File.ReadLine   
        'Wscript.Echo LineText
  'Wscript.Echo ( QueryStr (LineText ) )   
        ret = QueryStr( LineText,folder,strPath,filesize )
        If Not IsNull(ret) Then
          folder = ret
         End If
        'nCount=nCount+1
    Loop
End Sub

Function QueryStr( SourceStr, SubFolder,strPath1,filesize)

  Dim str1, str2, retStr, retStr1, nPos1, nPos2
  Dim fso1, f1, strPath
  Set fso1 = CreateObject("Scripting.FileSystemObject")
  strPath = strPath1+ testdataFolder

  str1="[ ]"
  str2=" - "

  nPos1 = InStr( SourceStr, str1 )
  'nPos2 = Instr( Right(SourceStr, Len(SourceStr)-nPos1), str2 )
   nPos2 = InStr( SourceStr, str2 )
  If nPos1=0 then
     QueryStr = Null
  Else if nPos2=0 Then
      'Wscript.Echo Len(SourceStr)
      'Wscript.Echo nPos1
      'Wscript.Echo  Len(str1)
     retStr = Right( SourceStr, Len(SourceStr) - nPos1-Len(str1)+1 )
     strPath = strPath +"\" + trim(retStr)
     QueryStr = trim(retStr)
     'Wscript.Echo strPath
      CreateMyFolder(strPath)
   Else
     retStr = Mid( SourceStr, nPos1+Len(str1), nPos2 -nPos1-Len(str1))
     retStr1 = Right(SourceStr, Len(SourceStr)-nPos2-Len(str2)+1 )
     retStr1 = Replace( retStr1, "\", " or ")
     retStr1 = Replace( retStr1, "/", " or ")
     QueryStr = Null
     strPath = strPath + "\" + SubFolder + "\" + trim(retStr1) + "." + trim(retStr)
    'Wscript.Echo strPath
    CreateMyFile strPath,filesize
    End If
  End If
  'Wscript.Echo( nPos2)
  'Wscript.Echo( strPath)


End Function

Sub CreateMyFolder( strPath )
 
  Dim fso2, folder1
  Set fso2 = CreateObject("Scripting.FileSystemObject")
  If Not fso2.FolderExists(strPath) Then
     Set folder1 = fso2.CreateFolder(strPath)
  End If
  Set fso2=nothing
End Sub

Sub CreateMyFile( strPath, filesize)
  Dim fso3, file1
  Set fso3 = CreateObject("Scripting.FileSystemObject")
  If Not fso3.FileExists(strPath1) Then
     Set file1 = fso3.OpenTextFile( strPath, ForWriting , True) ' For Writing
     file1.WriteBlankLines filesize
     file1.Close
  End If
  Set fso3=nothing
End Sub

Sub Copy59Times(perFile)
   If CopyCheck=False Then
    Exit Sub
   End if

   Const copyFolder = "copy_data"
   'Const filesize = 512 '1kb
   Const nCount =59
   currentFolder = WorkingDir+"\"+CStr(perFile)
 Rem Wscript.Echo ("MakeSure your folder&file exist, Starting...")

   Dim fso, MyFile, testFolder
   Dim i, cFolder
    sFolder = currentFolder + "\" + sourceFolder

 Rem  sText = currentFolder + "\" + copyFolder+ Cstr(0) + "\file.txt"
  sText = currentFolder + "\file.txt"
  Rem Wscript.Echo (sText)


  Set fso = CreateObject("Scripting.FileSystemObject")
   for i=0 to nCount -1
      cFolder = currentFolder + "\" + copyFolder + CStr( i ) +"\"
      If fso.FolderExists ( cFolder + "\" ) Then
          fso.DeleteFolder( cFolder )
      End If
      fso.CreateFolder ( cFolder )

  'Set filetxt = fso.CreateTextFile(sText , True)
  'filetxt.WriteLine("STARTED AT")
  'filetxt.Close

  fso.CopyFolder sFolder,cFolder
   Next


  'Set filetxt = fso.OpenTextFile(sText , ForAppending , True)
  'filetxt.WriteLine("FINISHED AT")
  'filetxt.Close
End Sub

Public Function GetDriveLetter(keyWord)
 If keyWord="" Then
  keyWord="CF_Storage"
 End If
 Set bjFSO=CreateObject("Scripting.FileSystemObject")
 Set bjDrives=objFSO.Drives
 For Each objDrive In objDrives
  If objDrive.IsReady Then
   If objDrive.VolumeName=keyWord Then
     GetDriveLetter=objDrive
   End if
  End If
 Next
 Set bjFSO=nothing
End Function

 

Public Function Update_Result()
 Set fso=CreateObject("Scripting.FileSystemObject")
 Set Excel=CreateObject("Excel.Application")
 oExcel.Visible=True
 
 'Check if the test case is Exist
 If fso.FileExists(TestCase)Then
  Set bjWorkBook = oExcel.Workbooks.Open(TestCase)
  sheet_count=oExcel.Sheets.Count
  oExcel.Sheets.Item(sheet_count).Select
  Set bjSheet=oExcel.Sheets(sheet_count)
  With objSheet
  For i=start_Column+1 To  brand_Column
         If RegExpTest("8G",.Range(Chr(i)+CStr(record_PC))) Then
          CopyTime=Record_Time(8)
          off=offsite(8)
          .Range(Chr(off+start_Column)+CStr(record_row)).value=copyTime
         ElseIf RegExpTest("1k",.Range(Chr(i)+CStr(record_PC))) Then
          copyTime=Record_Time(512)
          off=offsite(512)
          .Range(Chr(off+start_Column)+CStr(record_row)).value=copyTime
         ElseIf RegExpTest("2k",.Range(Chr(i)+CStr(record_PC))) Then
          copyTime=Record_Time(1024)
          off=offsite(1024)
          .Range(Chr(off+start_Column)+CStr(record_row)).value=copyTime
         ElseIf RegExpTest("4k",.Range(Chr(i)+CStr(record_PC))) Then
          copyTime=Record_Time(2048)
          off=offsite(2048)
          .Range(Chr(off+start_Column)+CStr(record_row)).value=copyTime
         ElseIf RegExpTest("8k",.Range(Chr(i)+CStr(record_PC))) Then
          copyTime=Record_Time(4096)
          off=offsite(4096)
          .Range(Chr(off+start_Column)+CStr(record_row)).value=copyTime
         ElseIf RegExpTest("16k",.Range(Chr(i)+CStr(record_PC))) Then
          copyTime=Record_Time(8192)
          off=offsite(8192)
          .Range(Chr(off+start_Column)+CStr(record_row)).value=copyTime
         Else
          MsgBox "Error, wrong case name"
         End if
        Next
        End with 
 End If
 oExcel.Save
 oExcel.Quit
 Set fso=nothing
End Function

Public Function offsite(perFile)
 Dim off
 Select Case perFile
  Case 8
   off=1
  Case 512
   off=2
  Case 1024
   off=3
  Case 2048
   off=4
  Case 4096
   off=5
  Case 8192
   off=6
 End Select
 offsite=off
End Function

Public Function Record_Time(perFile)
 Dim start_timer,end_timer
 Dim dir_org,dir_din
 Set bjfso=CreateObject("Scripting.FileSystemObject")
 If  perFile <> 8 then
  dir_org=WorkingDir+"\"+CStr(perFile)
  dir_din=CStr(CF_Storage)+"\" 
  If objfso.FolderExists(dir_din+CStr(perFile)+"\")Then
   objfso.DeleteFolder(dir_din+CStr(perFile))
  End if
 Else
  dir_org=WorkingDir+"\"+"8G"
  dir_din=CStr(CF_Storage)+"\"
  If objfso.FolderExists(dir_din+"8G"+"\")Then
   objfso.DeleteFolder(dir_din+"8G")
  End If
 End if
 start_timer_hour=Hour(Now)
 start_timer_minutes=Minute(Now)
 start_timer_seconds=Second(Now)
 Debug.WriteLine(Now)
 start_timer=CLng(start_timer_hour)*3600+CLng(start_timer_minutes)*60+CLng(start_timer_seconds)
 Debug.WriteLine(start_timer)
 objfso.CopyFolder dir_org, dir_din
 end_timer_hour=Hour(Now)
 end_timer_minutes=Minute(Now)
 end_timer_seconds=Second(Now)
 Debug.WriteLine(Now)
 end_timer=CLng(end_timer_hour)*3600+CLng(end_timer_minutes)*60+CLng(end_timer_seconds)
 Debug.WriteLine(end_timer)
 Record_Time=end_timer-start_timer
 Set bjfso=Nothing
End Function


TAG:

 

评分:0

我来说两句

Open Toolbar