Showing posts with label QTP Tips. Show all posts
Showing posts with label QTP Tips. Show all posts

Thursday, January 21, 2010

Screen Capture Of Lengthy Web page using Snag IT Scroll Method and QTP

If you have SnagIT and QTP together in your machine, then you will be able to take screen capture of a lengthy web page.

Try the below code and you should have both QTP and SnagIT in your machine. If you don't have SnagIT, please download the trial version of SnagIT and try the code.

Function Capture_Scroll_Image
Set objShell = CreateObject("WScript.Shell")
Set oSnag = CreateObject("SNAGIT.ImageCapture")


oSnag.Input = 1
oSnag.Output = 2
oSnag.OutputImageFile.FileNamingMethod = 2
oSnag.OutputImageFile.Directory = "C:\Documents and Settings\Desktop"'Make sure to specify your file path where you need to save your screen capture file.


oSnag.EnablePreviewWindow = False
oSnag.AutoScrollOptions.AutoScrollMethod=3
oSnag.OutputImageFile.LoadImageDefaults 5
oSnag.Capture()


wait(2)


objShell.SendKeys "{ENTER}"


Do Until oSnag.IsCaptureDone
Loop


Set
oSnag=Nothing

Set objShell=Nothing
End Function

SystemUtil.Run "Iexplore.exe","http://www.google.co.in"

Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").Set "QTP"
Browser("name:=Google").Page("title:=Google").WebButton("name:=Google Search").Click
Browser("name:=QTP - Google Search").Sync


Call Capture_Scroll_Image'Calling the function to capture lengthy web page

Browser("name:=QTP - Google Search").Close


After running the script you will get the lengthy screen capture of the web page as same as below.


Adding Your Own QTP Tip Of The Day

If you want to add your own organization tip for QTP instead of predefined tips which are displayed in QTP start up page, then go to C:\Program Files\Mercury Interactive\QuickTest Professional\dat and open the Tips text file. In this file you can add your organization or training centers tips.

For example: I want to instruct the user to save all your scripts in D: drive.

After adding the tip for the above instruction in the Tip file, you can see the tip as same as below in your QTP start up page,



Friday, January 15, 2010

Balloon Tool Tip Trick in QTP Instead Of Automatic Timeout Message Box

If you are using automatic timeout msgbox in your QTP Script(s), then please switch over to Balloon Tool Tip. It is much better than VB script or WSH timeout message boxes.

For instance: If you want to know the current iteration number while running your scripts, then you may use automatic timeout msgbox using the below code.

Start_Time=Time

Set WshShell = CreateObject("WScript.Shell")
wshShell.Popup "Current Iteration No. "&Environment.Value("TestIteration"), 5 'Next step will not run until the time-out expires

SystemUtil.Run "Iexplore.Exe","
http://www.google.co.in"
Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").Set "QTP"
Browser("name:=Google").Page("title:=Google").WebButton("name:=Google Search").Click


End_Time=Time
Msgbox Hour(End_Time-Start_Time) & ":" & Minute(End_Time-Start_Time) & ":" & Second(End_Time-Start_Time)


The above code has one drawback. When the msgbox is invoked, next step will not run until the specified msgbox's time-out expires.

Try the same scenario using Balloon Tool Tip code. The current iteration number will be displayed in System Tray and the script will not be stopped to display the tool tip.

icon_Path="C:\Documents and Settings\Desktop\6.ico" 'Choose any Icon file path from your PC. Make sure the file format should be .Ico.
Set oNtfy=DotNetFactory.CreateInstance("System.Windows.Forms.NotifyIcon","System.Windows.Forms")
Set oToolTip =DotNetFactory.CreateInstance("System.Windows.Forms.ToolTipIcon","System.Windows.Forms")
Set oIcon=DotNetFactory.CreateInstance("System.Drawing.Icon","System.Drawing",icon_Path)


Function fn_BalloonToolTip(vIterationNo)
oNtfy.Icon=oIcon
oNtfy.BalloonTipIcon=oToolTip.Info
oNtfy.Visible=True

oNtfy.Text = "QTP Info." 'Balloon Tool Tip Text Name
oNtfy.BalloonTipTitle = "Current Iteration No" 'Balloon Tool Tip Title
oNtfy.BalloonTipText="Current Iteration No. "&vIterationNo
oNtfy.ShowBalloonTip(5000) 'This line displays current iteration No in system Tray
End Function

Function fn_Kill_Balloon 'This function kills all the objects.
oNtfy.Dispose() 'After calling this method you will not see the balloon icon in system tray
Set oIcon =Nothing
Set oTool =Nothing
Set oNtfy=Nothing
End Function


Start_Time=Time
Call fn_BalloonToolTip(Environment.Value("TestIteration")) 'Calling balloon tool tip function


SystemUtil.Run "Iexplore.Exe","
http://www.google.co.in"
Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").Set "QTP"
Browser("name:=Google").Page("title:=Google").WebButton("name:=Google Search").Click


Call fn_Kill_Balloon'Calling kill function

End_Time=Time

Msgbox Hour(End_Time-Start_Time) & ":" & Minute(End_Time-Start_Time) & ":" & Second(End_Time-Start_Time)

After invoking the fn_BalloonToolTip function, you will see the Balloon Tool Tip in your system tray as same as below,




In previous WScript code, the QTP script is waited until the msgbox timeout expires. Here QTP script will not wait for Balloon Tool Tip to be closed. The tool tip will remain in the system tray unless/until you call the fn_Kill_Balloon

I hope this technique will be useful for others also.

Please let me know if you have any questions in this.

Thursday, December 31, 2009

Browser Control in QTP using DOT Net Factory

Create browser control instance in QTP using DOT Net factory, then you are able to browse any web pages without browsers. Execute the below code,


Set obj = DotNetFactory.CreateInstance("System.Windows.Forms.Form","System.Windows.Forms")
Set objBrwsr = DotNetFactory.CreateInstance("System.Windows.Forms.WebBrowser","System.Windows.Forms")

With objBrwsr
.Width=800
.Height=800
.AllowNavigation=True
.AllowWebBrowserDrop=True
.IsWebBrowserContextMenuEnabled=True
End With

With obj .Controls.Add objBrwsrEnd with
objBrwsr.Navigate("
www.google.com")
obj.showdialog

Set obj =Nothing
Set objBrwsr=Nothing


You will get DOT Net Dialog with browser control as same as below,



Thanks and regards,

Asiq Ahamed

Accessing HTML Properties using QTP

Part-1

Getting URL from HTML form.

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

If you want to access URL from a form's action, use the below code.
Syntax: Browser().Page().Object.getElementsByTagName("form")(IndexOfTheForm).action
Example: Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("form")(0).action

Throughout this article I have used Google for all my examples.

How to find hyperlink's color of your webpage

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

Here is the code to find link's color of your webpage.

Example: Msgbox Browser("name:=Google").Page("title:=Google").Object.alinkColor

How to find a textbox's auto-complete property is enabled or not

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

Use the below code to find whether the textbox's auto-complete property is enabled or not.

Example: Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementsByName("q")(0).autocomplete

Getting default checked property for radio button and checkbox

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

If you want to know radio button's or checkbox's default checked property in QTP, then use the simple code which I use frequently.

Msgbox Browser("name:=Google").Page("title:=Google").WebRadioGroup("name:=meta").Object.defaultChecked

Or

Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementByID("cty").defaultChecked

Finding host or hostname of the location or URL.

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

To find host and port number.

Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("A")(0).Host

To find host name.

Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("A")(0).HostName

Find destination URL

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

The below code to find a destination URL or an anchor point.

Msgbox Browser("name:=Google").Page("title:=Google").Object.getElementsByTagName("A")(0).Href

Part -2 will be published soon

Please refer the below link, if you want to know more about DOM.

http://www.learnqtp.com/document-object-model-qtp-guide/

Masking Password Using DotNet Factory

If you want to mask your password instead of placing in datatable or encrypting it, then use the below code.

Set oForm=DotNetFactory.CreateInstance("System.Windows.Forms.Form","System.Windows.Forms")
Set oTextBox=DotNetFactory.CreateInstance("System.Windows.Forms.TextBox","System.Windows.Forms")Set oButton = DotNetFactory.CreateInstance("System.Windows.Forms.Button", "System.Windows.Forms")
Set oPoint = DotNetFactory.CreateInstance("System.Drawing.Point", "System.Drawing", x, y)

With oPoint
.x = 120
.y = 20
End With

With oButton
.Location = oPoint
.Width = 100
.Text = "OK"
End with

With oPoint

.x = 0
.y = 20
End With

With oTextBox

.Location = oPoint
.UseSystemPasswordChar=True
End with

'Add Controls

With oForm
.CancelButton = oButton
.Controls.Add oButton
.Controls.Add oTextBox
End with

oForm.ShowDialog
Msgbox oTextBox.Text



Set oForm=Nothing
Set oTextBox=Nothing
Set oButton=Nothing
Set oPoint=Nothing
Run the above code you will get a DOT Net dialog like below.


Enter your password and click on OK button. The entered password will be displayed in a message box.
For more information about DOT Net controls, please refer the below link.