Quick test professional

QTP Tips QTP codes QTP Faqs and more

Prompt Dialog For Password Entry In QTP with help of DotNetFactory

The following code popup a dialog with a edit box for a password entry when it run from the QTP

Set objForm = DotNetFactory.CreateInstance(“System.Windows.Forms.Form”, “System.Windows.Forms”)
Set objBtn1 = DotNetFactory.CreateInstance(“System.Windows.Forms.Button”, “System.Windows.Forms”)
Set objEdit1 = DotNetFactory.CreateInstance(“System.Windows.Forms.TextBox”, “System.Windows.Forms”)
x=80
y=40
Set p1 = DotNetFactory.CreateInstance(“System.Drawing.Point”,”System.Drawing”,x,y) ‘This will provide the locations(X,Y) for the controls
Set lbl= DotNetFactory.CreateInstance(“System.Windows.Forms.Label”,”System.Windows.Forms”)
lbl.Text=”Enter Password”
lbl.Location=p1
objForm.Controls.Add(lbl)
p1.Y=CInt(lbl.Height)+40
objEdit1.Location=p1
objForm.Controls.Add(lbl)

objEdit1.UseSystemPasswordChar=true’To set the password character From system

objForm.Controls.Add(objEdit1)
objBtn1.Text=”OK”

p1.Y=Cint(p1.Y)+CInt(objEdit1.Height)+20
objBtn1.Location=p1

objForm.CancelButton=objBtn1

objForm.Controls.Add(objBtn1)

objForm.StartPosition=CenterScreen
objForm.Text=”Mohan kakarla”
objForm.ShowDialog

msgbox “The Password You have Entered Is: “&objEdit1.Text

Author: Mohan Kumar Kakarla

Advertisements

March 15, 2008 Posted by | DotNetFactory, Uncategorized | , , , | 13 Comments

OpenFileDialog In QTP with help of DotNetFactory

 Set fd = DotNetFactory.CreateInstance(“System.Windows.Forms.OpenFileDialog”, “System.Windows.Forms”)
fd.InitialDirectory=”c:\\”
fd.Filter=”txt files (*.txt)|*.txt |All files (*.*) |*.*”
fd.RestoreDirectory=true
fd.FilterIndex=2
fd.ShowDialog()
msgbox fd.FileName

Author: Mohan Kakarla

March 15, 2008 Posted by | DotNetFactory, Uncategorized | , , | 11 Comments

Prompt Dialog with Radio buttons in QTP with help of DotNetFactory

The following code popup a dialog with 2 radi button to select an option when it run from the QTP

Set objForm = DotNetFactory.CreateInstance(“System.Windows.Forms.Form”, “System.Windows.Forms”)

Set objRd1 = DotNetFactory.CreateInstance(“System.Windows.Forms.RadioButton”, “System.Windows.Forms”)
Set objRd2 = DotNetFactory.CreateInstance(“System.Windows.Forms.RadioButton”, “System.Windows.Forms”)
Set objGb = DotNetFactory.CreateInstance(“System.Windows.Forms.GroupBox”, “System.Windows.Forms”)
Set objBtn2 = DotNetFactory.CreateInstance(“System.Windows.Forms.Button”, “System.Windows.Forms”)
x=10
y=10
Set p1 = DotNetFactory.CreateInstance(“System.Drawing.Point”,”System.Drawing”,x,y) ‘This will provide the locations(X,Y) for the controls

objRd1.Text=”Radio1″
objGb.Location=p1

p1.Y=30
objRd1.Location=p1
p1.Y=CInt(objRd1.Height)+CInt(objRd1.Top)+10
objRd2.Location=p1
objRd2.Text=”Radio2″
objGb.Text=”Select The Radio Button”
objGb.Controls.Add(objRd1)
objGb.Controls.Add(objRd2)
objBtn2.Text=”OK”
p1.X=60

p1.Y=CInt(objGb.Height)+20
objBtn2.Location=p1
objForm.CancelButton=objBtn2

objForm.Controls.Add(objGb)
objForm.Controls.Add(objBtn2)
objForm.StartPosition=CenterScreen
objForm.Text=”Mohan kakarla”
objForm.ShowDialog
If objRd1.Checked Then
msgbox “You have selected Radio 1”
elseif objRd2.Checked Then
msgbox “You have selected Radio 2”
else
msgbox “No Radio button was selected”
End If

Author: Mohan Kumar Kakarla

March 15, 2008 Posted by | DotNetFactory, Uncategorized | , , | 6 Comments

Compare 2 XML files

This Example was written for comparing two XML files assuming the contents of the both XML has the following elements:
<Books>
<Title>QTP</Title>
<Author>Mohan</Author>
<Title>VBS</Title>
<Author>Kumar</Author>
</Books>

Dim description, filepath
Set xmlDoc1 = CreateObject(“Msxml2.DOMDocument”)
xmlDoc1.load(“C:Documents and Settingsmohan.kakarlaDesktop1.xml”)’file 1
Set xmlDoc2 = CreateObject(“Msxml2.DOMDocument”)
xmlDoc2.load(“C:Documents and Settingsmohan.kakarlaDesktop2.xml”)’file 2
Set ElemList1= xmlDoc1.DocumentElement.ChildNodes
Set ElemList2= xmlDoc2.DocumentElement.ChildNodes
If ElemList1.length=ElemList2.length Then’ check weather both xml file has same number of childnodes
  msgbox “Both XML files have same number of Child nodes”

   For i = 0 to ElemList1.length-1

       If ElemList1.item(i).Text=ElemList2.item(i).Text Then
          msgbox “child element:”&i &” is same in both XML files”
      Else
         msgbox “child element:”& i &” is not same in both XML files, In XML file 1, The valueis:”&ElemList1.item(i).Text &” and In XML file 1, The value

is:”&ElemList2.item(i).Text
     End If
  Next
End If

Author: Mohan Kumar Kakarla

March 3, 2008 Posted by | XML Scripting | , , , , , , , , , , | 111 Comments