Quick test professional

QTP Tips QTP codes QTP Faqs and more

Get TooTip text from Java Table

JavaWindow(“abc”).JavaTable(“xyz”).Object.setColumnSelectionAllowed=False

JavaWindow(“abc”).JavaTable(“xyz”).Object.setRowSelectionAllowed=False

JavaWindow(“abc”).JavaTable(“xyz”).ClickCell”#1″,”#0″

set obj=JavaWindow(“abc”).JavaTable(“xyz”).Object.getCellRect(1,0,True)

JavaWindow(“abc”).JavaTable(“xyz”).FireEvent micMouseMove,0, “BUTTON1_MASK”, obj.x, obj.y, 1, “OFF”

msgbox JavaWindow(“abc”).JavaObject(“toolkit class:=javax\.swing\.JToolTip
“).Object.tipText

July 7, 2011 Posted by | Uncategorized | , , | 6 Comments

How to Download a file using VbScript

Following is the code to download a file using Vbscript, without using QTP

This code uses the HTMLDom and URLDownloadToFile method from urlmon API.

Since VBScript does support calling Native API methods directly, here I am using  Excel macro to declare a function for the urlmon API and running the macro by Excel API from VBscript

Step1: Create a new excel and open the visual basic editor, Insert Module and paste the following code the Module, save the excel file

Private Declare Function URLDownloadToFile Lib “urlmon” Alias _
                                           “URLDownloadToFileA” ( _
                                           ByVal pCaller As Long, ByVal szURL As String, _
                                           ByVal szFileName As String, _
                                           ByVal dwReserved As Long, _
                                           ByVal lpfnCB As Long) As Long
Sub FileSave(strUrl, Des)
    r = URLDownloadToFile(0, strUrl, Des, 0, a)
   
End Sub

Step2: Create a VBS  and copy the below code and change the file paths

Set ie = CreateObject(“InternetExplorer.Application”)
ie.navigate “www.google.com
ie.Visible = True
WScript.Sleep 3000
ie.document.all.q.Value = “Testing + doc”
ie.document.all.btnG.Click
WScript.Sleep 1000
Set obj = ie.document.getElementsByTagName(“A”)
 For i = 0 To obj.Length
   If obj(i).innerText = “Testing Document” Then
      hr = obj(i).href
      Exit For
   End If
 Next

arrhr = Split(hr, “/”)
fname = arrhr(UBound(arrhr))
If hr <> “” Then
    strUrl = hr
    Des = “C:\Documents and Settings\Desktop\” & fname
   Set objXL = CreateObject(“Excel.Application”)
    With objXL.Application
        .Visible = False
        ‘Open the Workbook
        .Workbooks.Open “C:\Documents and Settings\Desktop\Download.xls”
        ‘Include CARMA in menu, run AutoOpen
        objXL.Application.DisplayAlerts = False
        x = .Run(“FileSave”, strUrl, Des)
    End With
    Set objXL = Nothing
MsgBox “Download Completed , the location of the saved file is->” & Des
End If

Set ie = Nothing

‘Special Thanks to Chandan Ray

November 8, 2010 Posted by | Uncategorized, VBScript and IE Automation | 3 Comments

Search for a particular value in Excel

Set appExcel = CreateObject(“Excel.Application”)
appExcel.visible=true
 Set objWorkBook = appExcel.Workbooks.Open (filepath)’opens the sheet

 Set objSheet = appExcel.Sheets(“Sheet1”)’ To select particular sheet
With objSheet.UsedRange ‘ select the used range in particular sheet
    Set c = .Find (“nn”)’ data to find  
For each c in objSheet.UsedRange’ Loop through the used range
 If c=”nn” then’ compare with the expected data
            c.Interior.ColorIndex = 40′ make the gary color if it finds the data
End If
            Set c = .FindNext(c)’ next search
       
next
End With
objWorkBook.save
objWorkBook.close
set appExcel=nothing

Author:Mohan Kakarla

October 21, 2008 Posted by | Excel Automation, Uncategorized | , , | 18 Comments

Automation Process Folwchart

October 12, 2008 Posted by | Uncategorized | Leave a comment

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

Prompt for password entry and hide while it is being typed

some times we need to prompt input box for a password and we need to  hide a password while it is being typed.
 But it is not possible with normal VBScript . we can use the AOM for IE with VBScript to do this.

Following is the code

strPw = GetPassword( “Please enter your password:” )
msgbox  “Your password is: ” & strPw

Function GetPassword( myPrompt )
‘ This function uses Internet Explorer to
‘ create a dialog and prompt for a password.

    Dim objIE
    ‘ Create an IE object
    Set objIE = CreateObject( “InternetExplorer.Application” )
    ‘ specify  the IE  settings
    objIE.Navigate “about:blank”
    objIE.Document.Title = “Password”
    objIE.ToolBar        = False
    objIE.Resizable      = False
    objIE.StatusBar      = False
    objIE.Width          = 300
    objIE.Height         = 180
    ‘ Center the dialog window on the screen
    With objIE.Document.ParentWindow.Screen
        objIE.Left = (.AvailWidth  – objIE.Width ) \ 2
        objIE.Top  = (.Availheight – objIE.Height) \ 2
    End With
  
    ‘ Insert the HTML code to prompt for a password
    objIE.Document.Body.InnerHTML = “<DIV align=””center””><P>” & myPrompt _
                                  & “</P>” & vbCrLf _
                                  & “<P><INPUT TYPE=””password”” SIZE=””20″” ” _
                                  & “ID=””Password””></P>” & vbCrLf _
                                  & “<P><INPUT TYPE=””hidden”” ID=””OK”” ” _
                                  & “NAME=””OK”” VALUE=””0″”>” _
                                  & “<INPUT TYPE=””submit”” VALUE=”” OK “” ” _
                                  & “OnClick=””VBScript:OK.Value=1″”></P></DIV>”
    ‘ Make the window visible
    objIE.Visible = True
    ‘ Wait till the OK button has been clicked
    Do While objIE.Document.All.OK.Value = 0
        WScript.Sleep 200
    Loop
    ‘ Read the password from the dialog window
    GetPassword = objIE.Document.All.Password.Value
    ‘ Close and release the object
    objIE.Quit
    Set objIE = Nothing
End Function

The code will create the screen like this

ie_password_dialog.gif

Author: Robvan der Woude

February 15, 2008 Posted by | Uncategorized, VBScript and IE Automation | , , , | 7 Comments

Run an .exe file and wait till it finish

To run path\abc .exe and wait to contunie with next statement in the .vbs-file until after abc.exe has finished.

add the bWaitOnReturn  parameter to the Run statement …

object.Run strCommand, [intWindowStyle], [bWaitOnReturn]

February 15, 2008 Posted by | Uncategorized | 1 Comment