51Testing软件测试论坛

标题: 【seagull1985-QTP】测试过程屏幕截图保存 [打印本页]

作者: seagull1985    时间: 2016-4-18 18:03
标题: 【seagull1985-QTP】测试过程屏幕截图保存
  1. '==========================================================================
  2. ' NAME: User Login
  3. ' AUTHOR: heyl  
  4. ' DATE  : 2012-12-21
  5. ' COMMENT:  
  6. '==========================================================================
  7. Class ScreenCaptureEngine

  8.              Public str_ScriptPath
  9.                          Public  oFSO
  10.                        
  11.                          Private Sub Class_Initialize   
  12.                                   str_ScriptPath = str_Test_Path&"Report\"
  13.                                   str_ScriptPath = str_ScriptPath&GetTestName
  14.                                   me.Createreporterfolder(str_ScriptPath)
  15.              End Sub
  16.                        
  17.                         Private Sub Class_Terminate      
  18.                         Set oFSO = nothing
  19.                         End Sub
  20.             
  21.                         'create a folder
  22.                         Function Createreporterfolder(str_folderpath)
  23.                         Dim fso, f
  24.                         Set fso = CreateObject("Scripting.FileSystemObject")
  25.                            If Not fso.FolderExists(str_folderpath)  Then
  26.                            Set f = fso.CreateFolder(str_folderpath)
  27.                            Set f = Nothing
  28.                            Set fso = Nothing
  29.                            Else
  30.                            Set fso = Nothing
  31.                            End If
  32.                         End Function

  33.                         Public Sub Report()
  34.                          
  35.                            Dim sFile
  36.                            Dim sTimeStamp
  37.                
  38.                        
  39.                        
  40.                            Set oFSO = createobject("Scripting.FileSystemObject")
  41.                            sTimeStamp = CStr(Now)
  42.                            sTimeStamp = Replace(sTimeStamp , "\", "")
  43.                            sTimeStamp = Replace(sTimeStamp , "/", "")
  44.                            sTimeStamp = Replace(sTimeStamp , ":", "")
  45.                        
  46.                            sFile = str_ScriptPath
  47.                            If Mid(sFile, Len(sFile),1) <> "\" Then sFile = sFile & "\"
  48.                           
  49.                            sFile = sFile & " " & sTimeStamp & ".png"
  50.                        
  51.                            While oFSO.FileExists(sFile)
  52.                                    sFile = Mid(sFile ,1,Len(sFile)-4) & "_1" & ".png"
  53.                            Wend
  54.                           
  55.                            Desktop.CaptureBitmap(sFile)
  56.                          
  57.                         End Sub
  58. End Class

  59. Set oScreenCapture = new ScreenCaptureEngine
复制代码



作者: 赵佳乐SMILE    时间: 2016-4-19 09:15
棒棒哒




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2