Quick test professional

QTP Tips QTP codes QTP Faqs and more

Remove Attachment from QC Through QTP

‘The following function will Remove the specified attachment  from the current test of QC when  the file name provided
Function RemoveQCAttachements(NameOfTheFile)
var_count= QCUtil.CurrentTest.Attachments.NewList(“”).count
For i= 1 to var_count

 If   QCUtil.CurrentTest.Attachments.NewList(“”).Item(2).Name =NameOfTheFile Then
         AttachmentID = QCUtil.CurrentTest.Attachments.NewList(“”).Item(1).ID
   QCUtil.CurrentTest.Attachments.RemoveItem(AttachmentID)
 Else
     Reporter.ReportEvent micFail,”Please provide the valid filename with extention”,”Please provide the valid filename with extention”
 End If

Next
End Function

NameOfTheFile=”abc.vbs” ‘Provide the file name with extension
call RemoveQCAttachements(NameOfTheFile)

Author:Mohan Kakarla

Advertisements

September 24, 2008 Posted by | Automating QC, QC-OTA | , , | 9 Comments

Copy an excel sheet to another excel

Following is the code to copy the conntents of a sheet in one excel to another excel sheet

Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(“C:\Documents and Settings\mohan.kakarla\Desktop\1.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(“C:\Documents and Settings\mohan.kakarla\Desktop\2.xls”)
objWorkbook1.Worksheets(“Sheet1”).UsedRange.Copy
objWorkbook2.Worksheets(“Sheet1”).Range(“A1”).PasteSpecial Paste =xlValues
objWorkbook1.save
objWorkbook2.save
objWorkbook1.close
objWorkbook2.close
set objExcel=nothing

 Author: Mohan Kakarla

June 9, 2008 Posted by | Excel Automation, Uncategorized | , , , | 25 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

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

Compare 2 Excel sheets cell by cell

This code will open two excel sheet and compare each sheet cell by cell, if any changes there in cells , it will highlight the cells in red color  in the first sheet.
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(“C:Documents andSettingsmohan.kakarlaDesktopDocs1.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(“C:Documents and

Settingsmohan.kakarlaDesktopDocs2.xls”)

Set objWorksheet1= objWorkbook1.Worksheets(1)

Set objWorksheet2= objWorkbook2.Worksheets(1)

   For Each cell In objWorksheet1.UsedRange
       If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
           cell.Interior.ColorIndex = 3’Highlights in red color if any changes in cells
       Else
           cell.Interior.ColorIndex = 0
       End If
   Next

set objExcel=nothing
 Author: Mohan Kumar Kakarla

February 27, 2008 Posted by | Excel Automation | , , , , , , , , , | 87 Comments

Excel Sorting(Ascending , Descending) By Rows and Columns

Excel Sorting By Row:

Const xlAscending = 1
Const xlNo = 2
Const xlSortRows = 2

Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True

Set objWorkbook = objExcel.Workbooks.Open(“C:Documents and Settingsmohan.kakarlaDesktopDocs1.xls”)
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Cells(1,1).activate

Set objRange = objExcel.ActiveCell.EntireRow
objRange.Sort objRange, xlAscending, , , , , , xlNo, , , xlSortRows
set objExcel=nothing

Excel Sorting By Colum :

Const xlAscending = 1’represents the sorting type 1 for Ascending 2 for Desc
Const xlYes = 1

Set objExcel = CreateObject(“Excel.Application”)’Create the excel object
objExcel.Visible = True’Make excel visible
Set objWorkbook = _
objExcel.Workbooks.Open(“C:\Documents and Settings\mohan.kakarla\Desktop\Docs1.xls”)’Open the

document

Set objWorksheet = objWorkbook.Worksheets(1)’select the sheet based on the index .. 1,2 ,3 …
Set objRange = objWorksheet.UsedRange’which select the range of the cells has some data other than blank
Set objRange2 = objExcel.Range(“A1”)’ select the column to sort

objRange.Sort objRange2, xlAscending, , , , , , xlYes
set objExcel=nothing

Reference: MSDN

February 26, 2008 Posted by | Excel Automation | , , , , , , , , , , , , | 18 Comments

Whats New In QTP 9.5

  • Maintenance Run Mode :

  • Repair your test on the fly, this will assists you to  adding the steps or uodating the object proprties in OR on the fly.i.e. if your object properties are changed after a new build, you just run the Maintenance Run Mode and update your OR according to that on the fly.

  • Process Guidance :

  • This is little more than more accessible help files. Maybe this is good for when you are first learning to record a test, but it doesn’t seem to add much utility.

  • Flow Pane
  • Available Keywords Pane

  • All Test Objects and functions in one handy location.Rapid test development with drag & drop.Object repository now also supports drag & drop

    1.jpg

  • Resources Pane :

  • All resources associated with the test. You can see all your library file in this pane

    11.jpg

  • Missing Resources Pane
  • Relative Path Helper
  • Improved Bitmap Checkpoint
  • Web Extensibility :
  • 1.Anyone can add support for new web controls

    2.Rapid development in JavaScript

    3.Solid infrastructure supplied by the Web add-in

    4.Extensibility objects are first class citizens

     5.Built-in toolkit: ASPAjax

  • Tabbed browsing :
  • Tabs identified as separate browsers.Same test compatible with tabbed and non tabbed browsers.

  • New Technologies :
  • 1.PowerBuilder

    2. Oracle − Forms 10 −Apps 12

    3.StingRay Objective Grid 10, 114. PeopleSoft 9.0•

    4.New Terminal Emulator versions

    5.NET 3.5 (beta)

  • New environments  :
  • 1.Windows Vista 64 bit

    2. Eclipse 3.2, 3.3

    3.Record on SWT

    4. Firefox 3.0

    5.Netscape 9

    Reference: HP website

    You can download QTP 9.5 on HP website  https://h10078.www1.hp.com/cda/hpms/display/main/hpms_content.jsp?zn=bto&cp=1-11-127-24^1352_4000_100__

    February 21, 2008 Posted by | New Features In QTP9.5, Whats New in QTP 9.5 | , , , , , , | 49 Comments

    Uninstall a software using vbscript , QTP

    This works for uninstalling most applications. In this example I will show how AutoCAD 2005 can be uninstalled using a VBScript. Open Regedit and look in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall search for the application and find a the product code that is in GUID format looking like this: {5783F2D7-0301-0409-0002-0060B0CE6BBA} It might be something else for you. The code below will uninstall AutoCAD 2005 as well as Express Tools. Copy the code below into Notepad and give the file the extension vbs.on error resume next
    Set WshShell = CreateObject("WScript.Shell")
    ' Uninstall Express Tools
    WshShell.Run "msiexec /x {5783F2D7-0311-0409-0000-0060B0CE6BBA} /q",1,true
    ' Uninstall AutoCAD 2005
    WshShell.Run "msiexec /x {5783F2D7-0301-0409-0002-0060B0CE6BBA} /q",1,true

    Reference:JTBWorld blog

    February 20, 2008 Posted by | Uninstall a software using QTP, Uninstall a software using vbscript | , , , , , , | 3 Comments