Sunday, January 22, 2012

Components & Different Views in QTP

Components of QTP




Different views in QTP
•Keyword view & Expert View – Used to generate script.
•Information Pane - The Information pane lists the syntax errors found in your document, and enables you to locate each syntax error so that you can correct it.
•Active Screen - The Active Screen provides a snapshot of your application as it appeared when you performed the corresponding step during a recording session.
•Missing Resource - The Missing Resources pane provides a list of the resources that are specified in your test but cannot be found. Missing resources can include calls to missing actions, missing function libraries, missing recovery scenarios, missing environment variable XML files, unmapped shared object repositories, and parameters that are connected to shared object repositories.


•Debug Viewer - The Debug Viewer pane assists you in debugging your tests or function libraries.
       •This pane contains three tabs—Watch, Variables, and Command.


•Data table - The Data Table contains one Global tab plus an additional tab for each action in your test. The Data Table assists you in parameterizing your test. To view the Data Table, click the Data Table toolbar button or select View >Data Table.


Link to Similar Posts



Environments Supported by QTP


Environments Supported by QTP:

QuickTest Professional supports functional testing of all enterprise environments, including
Windows,
Web,
.NET,
Java/J2EE,
SAP,
Siebel,
Oracle,
PeopleSoft,
 Visual Basic,
 ActiveX,
 mainframe terminal emulators, and more..

Thursday, January 19, 2012

ZIP & UNZIP files in QTP

'=======================================================
'ZIP:
'=======================================================
Function WindowsZip(sFile, sZipFile)
     Set oZipShell = CreateObject(“WScript.Shell”)
     Set oZipFSO = CreateObject(“Scripting.FileSystemObject”)

     If Not oZipFSO.FileExists(sZipFile) Then
       NewZip(sZipFile)
     End If

     Set oZipApp = CreateObject(“Shell.Application”)
     sZipFileCount = oZipApp.NameSpace(sZipFile).items.Count
     aFileName = Split(sFile, “\”)
     sFileName = (aFileName(Ubound(aFileName)))
    REM  listfiles

     sDupe = False

     For Each sFileNameInZip In oZipApp.NameSpace(sZipFile).items
        If LCase(sFileName) = LCase(sFileNameInZip) Then
         sDupe = True
         Exit For
       End If
    Next

     If Not sDupe Then
     oZipApp.NameSpace(sZipFile).Copyhere sFile
     REM  Keep script waiting until Compressing is done
     On Error Resume Next
      sLoop = 0
      Do Until sZipFileCount < oZipApp.NameSpace(sZipFile).Items.Count
         Wscript.Sleep(100)
         sLoop = sLoop + 1
       Loop
    On Error GoTo 0
     End If
  End Function
'=======================================================
'UnZip:
'=======================================================
Function Unzip(strFilePath, strFileName, blnOverWriteFiles, blnDeleteZipFileAfterExtract, out_ExtractToFolder)
' This routine unzips a file. NOTE: The files are extracted to a folder '
' in the same location using the name of the file minus the extension.  '
' EX. C:\Test.zip will be extracted to C:\Test ' 'strFile (String) = Full path and filename of the file to be unzipped. '
  Dim arrFile
  Dim FileInsideZip, FilesInsideZip
  Dim fso, strFile, pathToZipFile, extractTo
  Dim objShell

  Unzip = ""
  strFile = strFilePath & "\" & strFileName
  arrFile = Split(strFile, ".")
  Set fso = CreateObject("Scripting.FileSystemObject")
  If Not fnVerifyFileExists(strFilePath, strFileName) Then
   Reporter.ReportEvent micFail, "Unzip file : " & strFilePath & "\" & strFileName, "File does not exist"
   Exit Function
  End If
  fnCreateFolderStructure arrFile(0)    'Build the folder tree
 ' fso.CreateFolder(arrFile(0) & "\ ")
  pathToZipFile= arrFile(0) & ".zip"
  extractTo= arrFile(0) '& "\"
  Set objShell = CreateObject("Shell.Application")
  Set filesInzip=objShell.NameSpace(pathToZipFile).items

  'Verify that if files present in the zip file is already present in the folder. If yes, then delete those.

   For each itm in objShell.NameSpace(pathToZipFile).items
    FileInsideZip = itm.Name
      If  FilesInsideZip = "" Then
       FilesInsideZip = FileInsideZip
      Else
       FilesInsideZip = FilesInsideZip & ";" & FileInsideZip
      End If
    If blnOverWriteFiles = True Then
     If fnVerifyFileExists (extractTo, FileInsideZip) = True Then
      fnDeleteFile ExtractTo, FileInsideZip
     End If
    End If
   Next
  objShell.NameSpace(extractTo).CopyHere filesInzip

  If blnDeleteZipFile = True Then
   fso.DeleteFile pathToZipFile, True
  End If
  Reporter.ReportEvent micDone, "Unzip File : " &  strFilePath & "\" & strFileName, "Unzipped location : " & extractTo & vbcrlf & vbcrlf & "Files Unzipped : " & vbcrlf & FilesInsideZip
  Unzip = FilesInsideZip
  out_ExtractToFolder = extractTo
  Set fso = Nothing
  Set objShell = Nothing
End Function 'Unzip
'=======================================================
'Verify File Exists in the Specified Directory
Function fnVerifyFileExists(FilePath, FileName)
   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")
   fnVerifyFileExists = fso.FileExists(FilePath & "\" & FileName)
   Set fso = Nothing
End Function
'=======================================================
'Delete the specified File
Function fnDeleteFile(strFilePath, strFileName)
   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")
   If  fso.FileExists(strFilePath & "\" & strFileName) Then
    fso.DeleteFile strFilePath & "\" & strFileName
 End If
 Set fso = Nothing
End Function
'=======================================================
'Creates the entire folder structure
Function fnCreateFolderStructure(FolPath)
   Dim fso, arrFolderPath
   Dim fIndex,i, CurrentFolderPath
   Set fso = CreateObject("Scripting.FileSystemObject")
   arrFolderPath = Split(FolPath, "\")
 For fIndex = 0 to Ubound(arrFolderPath)     '0 will always have Drive letter
  CurrentFolderPath = 0
  For i = 0 to fIndex
   If i = 0 Then
    CurrentFolderPath = arrFolderPath(i)
   Else
    CurrentFolderPath  = CurrentFolderPath & "\" & arrFolderPath(i)
     End If
  Next

  If Not fso.FolderExists(CurrentFolderPath)  Then
   fso.CreateFolder CurrentFolderPath
  End If

   Next
   Set fso = Nothing
End Function

Functions to work with QC Attachments


'===============================================================
'Description : Returns the path of downloaded attachment
'===============================================================
'Example Usage :
' If you want to move the downloaded file to c:\ folder
' attpath = DownloadAttachment(“attachmentname”,”Root\D2D\Purchasing”, “TRUE”)
' If you DO NOT want to move the downloaded file to c:\ folder
' attpath = DownloadAttachment(“attachmentname”,”Root\D2D\Purchasing”, “FALSE”)

Public Function DownloadAttachment(TDAttachmentName, TDFolderPath, bMovetoRoot)
 Dim otaAttachmentFactory 'As TDAPIOLELib.AttachmentFactory
 Dim otaAttachment 'As TDAPIOLELib.Attachment
 Dim otaAttachmentList 'As TDAPIOLELib.List
 Dim otaAttachmentFilter 'As TDAPIOLELib.TDFilter
 Dim otaTreeManager 'As TDAPIOLELib.TreeManager
 Dim otaSysTreeNode 'As TDAPIOLELib.SysTreeNode
 Dim otaExtendedStorage 'As TDAPIOLELib.TreeManager
 Dim fso
 Dim strPath 'As String

 Set fso = CreateObject("Scripting.FileSystemObject")
 Set otaTreeManager = QCUtil.TDConnection.TreeManager
 Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
 Set otaAttachmentFactory = otaSysTreeNode.Attachments
 Set otaAttachmentFilter = otaAttachmentFactory.Filter
 otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & otaSysTreeNode.NodeID & "_" & TDAttachmentName & "'"
 Set otaAttachmentList = otaAttachmentFilter.NewList
 If otaAttachmentList.Count > 0 Then
  set otaAttachment = otaAttachmentList.Item(1)
  otaAttachment.Load True, ""
  strPath = otaAttachment.FileName
        If (bMovetoRoot) Then
   If (fso.FileExists(otaAttachment.FileName)) Then
    fso.CopyFile strPath, "c:\" & TDAttachmentName
    DownloadAttachment = "c:\" & TDAttachmentName
   Else
    DownloadAttachment = strPath
   End if
  Else
   DownloadAttachment = strPath
  End if
 Else
  fnReportEvent micFail, "Failure in library function 'GetFolderAttachmentPath'", "Failed to find attachment '" & TDAttachmentName & "' in folder '" & TDFolderPath & "'."
  DowloadAttachment = "Empty"
 End If
 Set otaAttachmentFactory = Nothing
 Set otaAttachment = Nothing
 Set otaAttachmentList = Nothing
 Set otaAttachmentFilter = Nothing
 Set otaTreeManager = Nothing
 Set otaSysTreeNode = Nothing
 Set fso = Nothing
End Function
'===============================================================
'Upload a File to QC to a specific path
'===============================================================
Public Function UploadAttachment(TDFolderPath,sFilePath)
 Dim otaAttachmentFactory 'As TDAPIOLELib.AttachmentFactory
 Dim otaAttachment 'As TDAPIOLELib.Attachment
 Dim otaAttachmentList 'As TDAPIOLELib.List
 Dim otaAttachmentFilter 'As TDAPIOLELib.TDFilter
 Dim otaTreeManager 'As TDAPIOLELib.TreeManager
 Dim otaSysTreeNode 'As TDAPIOLELib.SysTreeNode
 Dim otaExtendedStorage 'As TDAPIOLELib.TreeManager
 Dim fso
 Dim strPath 'As String

 Set fso = CreateObject("Scripting.FileSystemObject")
 Set otaTreeManager = QCUtil.TDConnection.TreeManager
 Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
 Set otaAttachmentFactory = otaSysTreeNode.Attachments
 Set ObjAttch = otaAttachmentFactory.AddItem(Null)
 ObjAttch.FileName = sFilePath
 ObjAttch.Type = 1
 ObjAttch.Post
 ObjAttch.Refresh

 Set otaAttachmentFactory = Nothing
 Set otaAttachment = Nothing
 Set otaAttachmentList = Nothing
 Set otaAttachmentFilter = Nothing
 Set otaTreeManager = Nothing
 Set otaSysTreeNode = Nothing
 Set fso = Nothing
End Function
'===============================================================
'Delete a QC Attachment file
'===============================================================
Public Sub DeleteFolderAttachment(TDAttachmentName, TDFolderPath)
'Test Director TDAPIOLELib object variables
Dim otaAttachmentFactory 'As TDAPIOLELib.AttachmentFactory
Dim otaAttachment 'As TDAPIOLELib.Attachment
Dim otaAttachmentList 'As TDAPIOLELib.List
Dim otaAttachmentFilter 'As TDAPIOLELib.TDFilter
Dim otaTreeManager 'As TDAPIOLELib.TreeManager
Dim otaSysTreeNode 'As TDAPIOLELib.SysTreeNode
Dim otaExtendedStorage 'As TDAPIOLELib.TreeManager
Dim strPath 'As String
Set otaTreeManager = QCUtil.TDConnection.TreeManager
Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
Set otaAttachmentFactory = otaSysTreeNode.Attachments
Set otaAttachmentFilter = otaAttachmentFactory.Filter
otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LISTS_" & otaSysTreeNode.NodeID & "_" & TDAttachmentName & "'"
Set otaAttachmentList = otaAttachmentFilter.NewList
If otaAttachmentList.Count > 0 Then
otaAttachmentFactory.RemoveItem otaAttachmentList.Item(1).ID
Else
Reporter.ReportEvent micFail, "Failure in library function 'GetFolderAttachmentPath'", "Failed to find attachment '" & TDAttachmentName & "' in folder '" & TDFolderPath & "'."
End If

Saturday, January 7, 2012

Introduction to Automation with QTP

Welcome you all!


    I have plans to post some basic features and modules of QTP. This would be helpful for those who newly came in to automation with QTP. Before jumping to Automation, we will see some basic things about testing. Testing is a phase in a software development. Software testing is nothing but testing the application with the intention of finding bugs or defects. There are multiple types and phases of testing like black box testing, White box testing, smoke testing, Regression testing, system testing etc.


   Smoke Testing - Testing the major areas/ high level functionality to make sure everything is working fine. In some projects, they used to perform Build Acceptance Testing which is also similar to Smoke testing.
 
   System Testing - Testing the whole application or system. Usually, System testing refers to cover all the functionality in a module/system.


   Regression Testing - As everyone aware, Regression Testing is some thing to make sure nothing is affected in unchanged modules of the application. There will be set of test cases that will remains unchanged for all the releases. Those test cases will be executed. This is where the requirement of Automation tools to evolved.


   As there are same set of test cases going to be executed repetitively, we can seek help of a tool to perform that operation. QTP (Quick Test Professional) is one such tool. QTP is basically called as a Record/Playback tool. So a tester can record a manual operation and QTP has all the capabilities to play back user actions. Also, user can enhance the recorded script to perform more action. Keep watching this space, I will start posting the functionality of various modules in QTP. 
    Automation testing also follows series of process to achieve effective automation with minimum effort. Please see below



Links to Similar posts:
Environments Supported by QTP
Components & Different Views in QTP



Monday, January 2, 2012

Welcome!

Greetings to All!

    It's been a great pleasure to welcome YOU all to my new Blog (Test Everyting - QTP). I am much delighted and thankful to all who have supported and guided me for creating this wonderful space. There was a thought running on mind most of the time about creating a blog and sharing knowledge. Today, all my dreams comes true by the way of presenting here a new space.

   I have many plans to post lots of information about QTP (Quick Test Professional). I request you all to give your extended support to this blog to made this more successful! Thank you very much for visiting!

Cheers and Keep blogging!
Ramesh

Read Data from EXCEL Sheet

There are multiple ways to read data from an EXCEL Sheet.
1st method: Reading Excel Data using DataTable


Datatable.Importsheet "path of the excel file.xls", source sheet ID/Name, desination sheet ID/Name
Datatable.SetCurrentRow(1)  'Read Value from First Row
value = datatable.Value(parameterName,Sheet ID/Name)

'To Read Value from All the rows

Datatable.Importsheet "path of the excel file.xls", source sheet ID/Name, desination sheet ID/Name
For vRow = 1 To Datatable.GetRowCount
    Datatable.SetCurrentRow(vRow)
    value = datatable.Value(parameterName,Sheet ID/Name)
Next


2nd method: Reading Excel Data using Excel Object

Dim objexcel, objWorkbook, objDriverSheet, columncount, rowcount
set objexcel = Createobject("Excel.Application")
Set objWorkbook = objExcel.WorkBooks.Open("path of the file.xls")
Set objDriverSheet = objWorkbook.Worksheets("name of the sheet / Id of the sheet")
columncount = objDriverSheet.usedrange.columns.count
rowcount = objDriverSheet.usedrange.rows.count
for i = 1 to colunmcount
  columnname = objDriversheet.cells(i,1)
  if columnname = knowncolumnname then
    for j = 1 to rowcount
      fieldvalue = objdriversheet.cells(j,i)
    next
  end if
next

 3rd method: Reading Excel Data using ADODB Connection

Function GetContentFromDB (strFileName, strSQLStatement)
Dim objAdCon, objAdRs
Set objAdCon = CreateObject(“ADODB.Connection”)

objAdCon.Open “DRIVER={Microsoft Excel Driver (*.xls)};DBQ=”&strFileName & “;Readonly=True”
If Err <> 0 Then
      Reporter.ReportEvent micFail,”Create Connection”, “[Connection] Error has occured. Error : ” & Err
      Set obj_UDF_getRecordset = Nothing
   Exit Function
End If

Set objAdRs = CreateObject(“ADODB.Recordset”)
objAdRs.CursorLocation=3                        ‘ set the cursor to use adUseClient – disconnected recordset
objAdRs.Open strSQLStatement, objAdCon, 1, 3

MsgBox objAdRs.fields(4).name
While objAdRs.EOF=false
   For i=0 to objAdRs.Fields.count
      Msgbox objAdRs.fields(i)
   Next
   objAdRs.moveNext
Wend

If Err<>0 Then
      Reporter.ReportEvent micFail,”Open Recordset”, “Error has occured.Error Code : ” & Err
      Set obj_UDF_getRecordset = Nothing
     Exit Function
End If

Set objAdRs.ActiveConnection = Nothing

objAdCon.Close
Set objAdCon = Nothing

End Function

Set rsAddin = GetContentsFromDB(“C:\Documents and Settings\gramesh\Desktop\Login.xls”, “Select * from [Login$]“)