Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Showing posts with label uft script. Show all posts
Showing posts with label uft script. Show all posts

Simulating Keyboard and mouse operations in UFT using settings.replay type

In QTP, We can replicate device events, i.e keyboard and mouse operation using the below line of code.

Setting.WebPackage("ReplayType") = 2

By default, value of the Setting is 1, in which UFT interacts with application using the browser through DOM.

Setting.WebPackage("ReplayType") = 1

In case, you are not able to perform click or operation on an element in the page, please give a try by providing setting:

 Setting.WebPackage("ReplayType") =2

Renaming all/specific subfolders in a folder using vbscript FSO

In this post, how to rename all the subfolders in a folder using vbscript is explained

  • Renaming all sub folders in a folder removing spaces from the file

call RemoveblankSpace_Subfolders("D:\TextTest")

 ''strbasefoldername - Folder Path in which file needs to be replaced
 Public Function RemoveblankSpace_Subfolders(strbasefoldername)
 On error resume next
 Dim objFSO
 Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Dim objFolder 
    For Each objSubFolder In objFSO.GetFolder(strbasefoldername).SubFolders
     FlderName = objSubFolder.Name
  FlderName = replace(FlderName," ","")
  objSubFolder.Name = FlderName
    Next 
    Set objSubFolderFolder = Nothing 
    Set objFSO = Nothing 
End Function

  • Rename specific subfolder in a folder using vbscript


call Rename_Subfolders("D:\TextTest","es","twist",false,"test")

'' strbasefoldername - Folder Path in which file needs to be replaced
'' strFindtext - text in the folder name that needs to be replaced
'' strReplaceText - new text to replace the existing test
'' boolAllFlders - boolean flag to indicate if all the subfolder needs to be renamed or
'' specific folders needs to be renamed
'' OnlyfoldersWithText - replace only folder with specific text. will consider only if
'' boolAllFlders =true
 Public Function Rename_Subfolders(strbasefoldername,strFindtext,strReplaceText,boolAllFlders,OnlyfoldersWithText)
 On error resume next
 Dim objFSO
 Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Dim objFolder
    For Each objSubFolder In objFSO.GetFolder(strbasefoldername).SubFolders
 FlderName = objSubFolder.Name
  if boolAllFlders = false then
   if(instr(1,FlderName,OnlyfoldersWithText)>0) then
    FlderName = replace(FlderName,strFindtext,strReplaceText)
    objSubFolder.Name = FlderName
   End If
  else
    FlderName = replace(FlderName,strFindtext,strReplaceText)
    objSubFolder.Name = FlderName
  End If
    Next 
    Set objSubFolderFolder = Nothing 
    Set objFSO = Nothing 
End Function

UFT test information and failure reason from result.xml file

While running the UFT test in batch,we need to capture executed test information including testname, test execution status and reason for failure if any in the test execution. 
Below code in vbscript can be used to extract required information from results file (result.xml) in UFT and parsing the information in xml file using MSXML.DomDocument and Microsoft.XMLDOM


xmlFilePath = "c:\Results.xml"

Set xmlDoc = CreateObject("MSXML.DomDocument")
If xmlDoc.Load (xmlFilePath) Then
'Get the test name
 Set objNode = xmlDoc.GetElementsByTagName("DName")
 .TestName = objNode(0).Text
 Set objNode = xmlDoc.GetElementsByTagName("Summary")

 'Last Node with tagName "Summary" has details of Pass/Fail status
 Set Node = objNode(objNode.Length - 1)

 intStepsPassed = Node.getAttribute("passed")
 intStepsWarning = Node.getAttribute("warning")

 ''in case of failures get the testfailureReason
 If Cint(intStepsFailed) > 0 Then
  strFailureReason = getFailureReason(xmlFilePath)
 End if
 Set FSO = Nothing
 Set xmlDoc = Nothing
End If

Public function getFailureReason(strFileName)
 Set xmlDoc = CreateObject("Microsoft.XMLDOM")
 xmlDoc.async = False
 strErrorMsg = ""
 booleanxmlParse = xmlDoc.load(strFileName)
 if(booleanxmlParse) then
  xmlDoc.setProperty "SelectionLanguage", "XPath"
  set xmlDoc_node = xmlDoc.selectNodes("//Step//NodeArgs[@status='failed']")
  for each node in xmlDoc_node
   strNode = node.parentNode.getattribute("rID")
   set TCNode = xmlDoc.selectSingleNode("//Step[@rID='" + strNode + "']/Details")
   strErrorMsg=strErrorMsg & TCNode.text
  Next
 End If
 getFailureReason = strErrorMsg 
End Function