Wednesday, June 12, 2013

Read XML


Below code is to read xml file and verify if "ExpItemSeqNo" variable is present in the xml.


Public Function CXF_XML_Verification(ExpItemSeqNo)

Set doc = XMLUtil.CreateXML()
doc.LoadFile "C:\Abhi\Workplace\New Project Payments\CXF_641240000_17092012_193900_01_1.XML"
Set root = doc.GetRootElement()

Set children = root.ChildElements() 'Set child object for root.
chdrncount=children.count   'Getting child counts of root.
Print  "Child count : "&chdrncount

Print "*******--------------------*************"
For j=1 to children.count

Set firstChild = children.Item(j) 'firstChild object is created to read item. This line is for first immediate child.

Set attribbes = firstChild.Attributes() 'To read attributes of immediate first child.
numOfAttr = attribbes.Count()

i=1  'To read only first attribute for all nodes.

'This loop is for reading all the attributes with the node "children.Item(j)"
' While i <= numOfAttr

Set attr = attribbes.Item(i)
nameStr = attr.Name()
valStr = attr.Value()

If (valStr = ExpItemSeqNo) Then

While i <= numOfAttr
'This will give you, attributes within node. in this case it is for first subsequent node.
Set Act_attr = attribbes.Item(i)
nameStrs = Act_attr.Name()
valStrs = Act_attr.Value()
attrStrs =attrStrs + nameStrs+" = "+chr(34)+valStrs+chr(34) + " " +chr(11)
i = i+1

Wend
'This will display sub childs node of any child node depending on j.
Print "Attributes: "  + attrStrs
          set firstChildName = firstChild.ChildElements()
                           
Print "---------------------"
subchdrncount=firstChildName.Item(1)
Print subchdrncount
If (Instr(subchdrncount, "RSA_with_SHA256")<>0) Then
Print vbcrlf 'Add new empty line.
Print "Value exist in <AddendA "
End If
Print "*******-------------------------------"

subchdrncount=firstChildName.Item(2)
Print subchdrncount
If (Instr(subchdrncount, "RSA_with_SHA256")<>0) Then
Print vbcrlf
Print "Value exist in <<MICRDS "
End If
Print "*******-------------------------------"

subchdrncount=firstChildName.Item(3)
Print subchdrncount
If (Instr(subchdrncount, "RSA_with_SHA256")<>0) Then
Print vbcrlf
Print "Value exist in <ImageViewDetail  "
End If
Print "*******-------------------------------"

subchdrncount=firstChildName.Item(4)
Print subchdrncount
If (Instr(subchdrncount, "RSA_with_SHA256")<>0) Then
Print vbcrlf
Print "Value exist in <ImageViewDetail  "
End If
Print "*******-------------------------------"


subchdrncount=firstChildName.Item(5)
Print subchdrncount
If (Instr(subchdrncount, "RSA_with_SHA256")<>0) Then
Print vbcrlf
Print "Value exist in <ImageViewDetail  "
End If
Print "*******-------------------------------"

print " "


End If

' attrStr = attrStr + nameStr+" = "+chr(34)+valStr+chr(34) + " " +chr(11)
attrStr = nameStr+" = "+chr(34)+valStr+chr(34) + " " +chr(32)
' i = i+1

' Wend
print "- "&j&" Attributes: "  + attrStr
print "**********************************"&j

Next

End Function
-----------------------------------------
ExpItemSeqNo = "64100100000250"

call CXF_XML_Verification(ExpItemSeqNo)




Thursday, May 30, 2013

SwfObject in QTP - WPF

Let's start off with swf, is a standard prefix QuickTest Professional uses to denote a Windows Forms object. This is normal and all Windows Forms objects are prefixed with that identifier. As to the subitem identifier SwfObject("someObjectName_#") the _# is added when QTP's methodology of naming a particular object, which in most cases for WindowsForms is the control's name, comes up with the same name. Since it cannot distinguish between the two, it identifies both the same.

     This is more common with Windows like SwfWindow("someForm_#"), because you can easily have more than one Window open with the same name, but is not nearly as common with SwfObjects because they are typically named after the controls, and the controls are required to be uniquely named, in most Windows Forms applications.

     I would like to start off with a few questions, first, is the application a WPF application? If so do you have the QTP WPF add-in installed, the required patches.

QTP tricks


----------------------------------------------------------------------------------------------

The ASCII codes for a line is Chr(10)

arrlines = Split(c, chr(10), -1, 1)

Ref: http://www.joecolantonio.com/2011/07/26/qtp-ascii-chr-code-chart/

----------------------------------------------------------------------------------------------
Sendkeys:

 ALT+F4 :-
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "%f"

Ref: http://www.quicklearnqtp.com/2010/05/sendkeys-method-in-qtp.html
----------------------------------------------------------------------------------------------

popupExist = SubmitPopUp().Object.currentStyle.display 'Verifying if submit pop-up is displayed or not.

If popupExist = "block" Then 'Verifying is submit pop-up is displayed.
   Print "Submit POP UP exist."

Ref: http://testeverythingqtp.blogspot.com/2012/01/qtp-object-is-visible-or-not-on-web.html

----------------------------------------------------------------------------------------------
Example for getvisibletext:

c = Browser("RemoteCapture").Page("RemoteCapture").WinObject("tblScanRecords").GetVisibleText

Print c

----------------------------------------------------------------------------------------------

Print vbcrlf 'Add new empty line.
----------------------------------------------------------------------------------------------

QTP device replay:-

The Device Replay feature is used to perform mouse and keyboard actions against screen coordinates that are provided. The Device Replay functions are not automatically recorded, but must be programmed manually in the Expert View.

Set DeviceReplay = CreateObject("Mercury.DeviceReplay")

DeviceReplay.MouseMove 290, 70

DeviceReplay.MouseClick 290, 70,LEFT_MOUSE_BUTTON
wait 2
Set DeviceReplay = Nothing


Ref: http://www.unlimitedqtp.com/2012/10/mercury-device-replay.html
----------------------------------------------------------------------------------------------