Quick test professional

QTP Tips QTP codes QTP Faqs and more

Merge 2 XML using Dotnet Factory

Dim objReader1,objReader2,objds1,objds2
Set objReader1 = DotNetFactory.CreateInstance(“System.Xml.XmlTextReader”, “System.Xml”,”C:\Documents and Settings\kmohankumar\Desktop\11.xml”)’ Creates the instance for the XMLWriter
Set objReader2 = DotNetFactory.CreateInstance(“System.Xml.XmlTextReader”, “System.Xml”,”C:\Documents and Settings\kmohankumar\Desktop\12.xml”)’
Set objds1 = DotNetFactory.CreateInstance(“System.Data.DataSet”, “System.Data”)
Set objds2 = DotNetFactory.CreateInstance(“System.Data.DataSet”, “System.Data”)
objds1.ReadXml(objReader1)
objds2.ReadXml(objReader2)
objds1.Merge(objds2)
objds1.WriteXml(“C:\Documents and Settings\kmohankumar\Desktop\13.xml”)
objReader1.close
objReader2.close
Set objReader1=Nothing
Set objReader2=Nothing
Set objds1=nothing
Set objds2=nothing
  

Author:Mohan Kakarla

November 27, 2008 Posted by | DotNetFactory, XML Scripting | 1 Comment

Create XML using Dotnet Factory

 Dim objWriter,XmlWriter
   Set objWriter = DotNetFactory.CreateInstance(“System.Xml.XmlWriter”, “System.Xml”)’ Creates the instance for the XMLWriter
 set XmlWriter=objWriter.Create(“C:\Documents and Settings\kmohankumar\Desktop\1234.xml”)’ creates xml document
 
 XmlWriter.WriteStartElement(“Books”)’ start writing the element
 XmlWriter.WriteStartElement(“Author”)

XmlWriter.WriteAttributeString “Name”, “Mohan”‘ writes  attributes and its values to the element
 XmlWriter.WriteEndElement()’ ends writing the element
 XmlWriter.WriteStartElement(“Title”)

XmlWriter.WriteAttributeString “Title1”, “QTP”‘
 XmlWriter.WriteEndElement()
 XmlWriter.WriteFullEndElement()

XmlWriter.close()

Set objWriter =Nothing

Author:Mohan kakarla

November 27, 2008 Posted by | DotNetFactory, XML Scripting | 3 Comments

Read XML using Dotnet Factory

Set objReader = DotNetFactory.CreateInstance(“System.Xml.XmlReader”, “System.Xml”)
set XmlReader=objReader.Create(“C:\Documents and Settings\kmohankumar\Desktop\3.xml”)

while (XmlReader.Read())

If  XmlReader.NodeType = “XmlDeclaration” or XmlReader.NodeType = “Element”Then
  
    Reporter.ReportEvent micPass, “NodeType:”&XmlReader.NodeType &”  Name :”& XmlReader.Name& ” is at Depth:”& XmlReader.Depth,””

    If XmlReader.HasValue Then
        Reporter.ReportEvent micPass, ” Value: “& XmlReader.Value,””
    End If

    Reporter.ReportEvent micPass, “Element:”& XmlReader.Name&”  has attribute(s)”&”:”& XmlReader.AttributeCount,””

  If XmlReader.AttributeCount > 0 Then

        while  XmlReader.MoveToNextAttribute()
     fn = XmlReader.Name
     ns = XmlReader.NamespaceURI
      Reporter.ReportEvent micPass,” Attribute:”&fn &”  Value: “& ns&” Attribute:”& XmlReader.GetAttribute(fn, ns),””
        wend
     End If
End If
wend
XmlReader.Close()

Author: Mohan Kakarla

November 27, 2008 Posted by | DotNetFactory, XML Scripting | 3 Comments

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

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