Thursday, 21 July 2011

How to close all IE browsers using QTP?

Syntax is:-

SystemUtil.CloseProcessByName ("iexplore.exe")

What is different between Dim and Redim? And how to handle Dynamic array?

Declaring an array with empty parentheses (without dimension subscripts) is called Dynamic arrays.

Ex: Public\Private\Dim ArrayName ( )

The Dim Statement is used to declare the Size for Static array.
The ReDim statement is used to size or resize a dynamic array.
Using ReDim statement You can change the number of elements and dimensions in an array repeatedly.

Ex: 1 )  Dim  X(10) 
            ReDim X(15)
Ex :2 ). Dim X(10, 10) 
            ReDim  X(10, 15) 
            Here if your array has two or more dimensions, you can change the size of only the last dimension   only.

NOTE: If you are using ReDim for changing the size or Dimensions of Dynamic array, it's erasing an existing data contained in the array. to avoid this you should use Preserve Keyword before the array name.

Ex: Dim X(10)
       ReDim Preserve X(15)

How to capture the bitmap and save all into one folder ?

Example:-
For i=1 to 10
 SystemUtil.Run "iexplore.exe","www.google.com",,,3
 a= "D:\vel\" & i &".bmp"
Browser("Google").Page("Google").WebEdit("q").Set a
Browser("Google").Page("Google").WebButton("Google Search").Click
Browser("Google").Page("Google").CaptureBitmap a,False
Browser("Google").Close
Next

How to get font size, color, background color and other attributes of Web Element?

Dim a,b
Set a =Browser("Google_2").Page("Google").WebElement("India")
Set b= a.Object
sColor = b.currentStyle.color
sBackgrColor = b.currentStyle.backgroundColor
sFontSize = b.currentStyle.fontSize
sFontStyle = b.currentStyle.fontStyle
sFontFamily =b.currentStyle.fontFamily
sFontWeight = b.currentStyle.fontWeight

What is the Difference between Wait To & Sync?

Wait is like forcing the QTP to wait for specified amount of time, whereas synchronization is not forced wait.
If the webpage gets loaded before the specified time, it moves to next step in case of synchronization.
If the webpage wait time is 10 sec and the page loaded in 2 sec, it waits for the remaining 7 sec in case of wait statement given.

What is Difference between Action and Function?

1. Action is a specific to QTP while functions are a generic thing which is a feature of VB Scripting.
2. Action have a object repository, Data table etc associated with it while a function can't. 
3. A function is just lines of code with some/none parameters and a single return value while 
    an action can have more than one input/output parameters.
4. Inside of Action we can declare lot of Function , incase Function can’t declare more Action

How to connect Database and retrieve date’s from Database?

'Variable Declaration
 
Option Explicit
Dim Dsn_conn,rs,PTime,NowDate
Dim myarray,DiffADate
Dim strServer,strUid,strQry
Dim objConnection
 
' Action parameters
 
strServer=parameter("Server") ' This is Server Name
strUid=parameter("Uid") ' User Id
Set objConnection=Createobject("ADODB.Connection")
 
Dsn_conn="DRIVER=SQL Server;SERVER="&strServer&";UID="&strUid&";APP=QuickTest Professional;WSID="&strServer&";Trusted_Connection=Yes"
 
objConnection.Open(Dsn_conn)
 
If err.number <> 0 Then
Reporter.ReportEvent 1 ,"DBConnection","Unable to Connect to the database"&"Err Description = " & err.Description
Else
Reporter.ReportEvent 0 ,"DBConnection","Connection Succeeded"
End If
 
Set rs=CreateObject("ADODB.RecordSet")
strQry = "UPDATE ELinkQueues.dbo.ELKMasterArchive SET ProcessedTime = DATEADD(""Day"", -10, ProcessedTime) WHERE (ProcessedTime IS NOT NULL) AND (Status = 2 OR Status = 3)" ' this is Query
 
Set rs=objconnection.execute(strQry)
Set rs=objconnection.execute("Select * from d_name from Doctordt")
rs.MoveFirst
Do While Not rs.EOF
PTime=rs.fields.item("ProcessedTime")
Exit Do
rs.movenext
Loop
rs.Close
objConnection.Close

How to Change the QTP result Report Color?

Reporter.ReportEvent 0, "&lt;<Font Color=Orange>object r Orange color.</Font> &gt;","&lt;<Font color=blue> Details r blue color.</Font>&gt;"

How to change the Date and Time using QTP?

newTime="05:40:00"
newDate=Date+1
Dim oShell
Set oShell=CreateObject("WScript.Shell")
oShell.run "cmd /k date" &CStr(" "&newDate)&"& exit"
oShell.run "cmd /k time" &CStr(" "&newTime)&"& exit"
set oShell=nothing
currentDateTime=now
msgbox currentDateTime
Here -

" cmd/K is  one of the switches avaliable with the cmd.exe"
For Example:
/C Switch : This switch loads a session of ‘cmd.exe’ into 
memory, executes the command specified after /C and 
terminates the cmd session.
/K Switch :    This creates a new command session and 
executes the date command, the session is not terminated 
after completion of the command.

How To Get current date and Time using QTP?

Method :1

Dim dt,mdt
Set dt=CreateObject ("Wscript.shell")
dt.run "cmd /k date"
dt.run "cmd /k time"
Set dt=Nothing

Method :1

Currentdatetime=Now
msgbox Currentdatetime

How To Exit from function or iteration? And continue with other function?

'Ex- For Exit funtion from iteration=5

Option Explicit
Dim i,a,
app()
open()
Function app()
For i=1 to 10
 a= "Test1" & i
SystemUtil.Run "iexplore.exe","www.google.com",,,3
Browser("Google").Page("Google").WebEdit("q").Set a
Browser("Google").Page("Google").WebButton("Google Search").Click
Browser("Google").Close
If i=5  Then
 Exit Function ' This Syntax is used for Quit this Function
End If
Next
End Function
Function open()
SystemUtil.Run "iexplore.exe","www.google.com",,,3
Browser("Google").Page("Google").WebEdit("q").Set "Velmuruganqa"
Browser("Google").Page("Google").WebButton("Google Search").Click
End Function

Vb Script for How to Stop QTP while an Error Occurred?

'open QTP
qtapp()
Function qtapp()
   Set qtapp=Createobject("QuickTest.Application")
   qtapp.launch
   qtapp.visible=True
End Function

'Open Application
app()
Function app()
SystemUtil.Run "flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","Open"
End Function

'Open Login window
login()
Function login()
  Set qapp=qtapp.Test
 Dialog("Login").WinEdit("Agent Name:").Set "velmurugan"
   Dialog("Login").WinEdit("Password1:").SetSecure "krishnan"
   Dialog("Login").WinButton("OK").Click
      qapp.Settings.Run.OnError="Stop" 'its for Stop appliction 
Window("Flight Reservation").Close
End Function

Vb Script For How To Stop QTP while Running or Executing?

'Need to Stop Running or Iteration while i=5

Option Explicit
Dim i,a,qaapp,aTest
qapp()
app()

Function qapp()
Set qaapp=CreateObject ("QuickTest.Application")
qaapp.launch
qaapp.visible=True
End Function

Function app()
For i=1 to 10
 a= "Test1" & i
SystemUtil.Run "iexplore.exe","http://www.google.com",,,3/
Browser("Google").Page("Google").WebEdit("q").Set a
Browser("Google").Page("Google").WebButton("Google Search").Click
Browser("Google").Close

Set aTest=qaapp.Test
If i=5  Then
 aTest.Settings.Run="Stop"
End If

Next
End Function

Monday, 18 July 2011

What is HWND?


hWND breaks up into h+ WND = handle +Windows. You can reference a window through its handle.A window handle (usually shortened to hWnd) is a unique identifer that Windows assigns to each window created.

Ex- a=Browser("index:=0").GetROProperty("hwnd")
       msgbox a

How to maximize or minimize the Windows using QTP? Or Syntax for Maximize Window


‘Method 1- Using SystemUtil

SystemUtil.Run "iexplore.exe","www.google.com",,,3

‘Here
0-      For close window
2-      For minimize window
3-      For Maximize window

‘Method 2 using Windows Handle property

Dim ie
Set ie=CreateObject ("InternetExplorer.Application")
ie.visible=True
Window("hwnd:=" &ie.HWND).Maximize
ie.navigate "www.google.com"

‘Method 3 – Using Shall Scripts 

Dim wsh
Set wsh = CreateObject("WScript.Shell")
wsh.Run "iexplore.exe www.google.com",3 , False
Set wsh = Nothing

Sunday, 17 July 2011

What is the syntax to move to next step in QTP while Error occurred in run time? Or How have to move next step in QTP while Error occurred in Runtime?

Syntax is :-

On Error Resume Next

Example:-

Function browsehome(n_url)

On Error Resume Next ‘have to declare Every function
   SystemUtil.Run "iexplore.exe",n_url
   browsehome="Pass"

End Function

Wednesday, 13 July 2011

Different way to Open the website or application using VB script

'Method 1 using SystemUtil

SystemUtil.Run "iexplore.exe","www.google.com"

'Method2 using without SystemUtil

Option Explicit
Dim a,b
a="www.google.com"
Set b=Createobject("InternetExplorer.Application")
b.visible=True
b.navigate a

'Method3 using Invoke

InvokeApplication "C:\Program Files\Internet Explorer\Iexplore.exe http://www.google.com"

'Method4 using Shall Script

Dim wsh
Set wsh = CreateObject("WScript.Shell")
wsh.Run "iexplore.exe www.google.com",3 , False
Set wsh = Nothing

Monday, 11 July 2011

How to Import date from Excel to QTP? And How to Report the status to QTP Report?–Easy Script

'Open Application
app()
Function app()
SystemUtil.Run "flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","Open"
End Function
'import Data's from Excel Sheet to QTP Global Sheet
Datatable.Import"D:\Velmurugan\Learning\Data\Login.xls"
a=Datatable.GetRowCount
msgbox a
login()
'Open Login window
Function login()
   For i=1 to a
   Datatable.SetCurrentRow(i)
  Dialog("Login").WinEdit("Agent Name:").Set datatable.Value("agentname")
   Dialog("Login").WinEdit("Password:").SetSecure datatable.Value("password")
   Dialog("Login").WinButton("OK").Click
   If Window("Flight Reservation").Exist  Then
    'Status to Report
   Reporter.ReportEvent micPass, "Login","Passed"
    Window("Flight Reservation").Close
    Else
    Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
    'Status to Report  
 Reporter.ReportEvent micFail,"Login","Faild"
   End If
  If Not Dialog("Login").Exist(5) Then
  Call app()
 End If
 Next
End Function
--------------------------*-------------------------*-----------------------------------*----------------
Data’s
Ex-

Tuesday, 5 July 2011

Common GUI Test Case for web application


TC-ID
Description
Expected Result
TC-001
Check for the display of the report screen

The Report screen should be displayed without any interruption
TC-002
Check for the Title of the screen
The Title of the screen should be displayed as
TC-003
Check for the title bar of the browser is consistent with the Screen Title
the title bar of the browser should be consistent with the Screen title
TC-004
Check for the address displayed in the address bar of the browser.
The screen path should be displayed with screen name.
TC-005
Check for the contents displayed in the Report Screen
The following contents should be displayed in the From Fortnight Start Date* (Text Box with Calendar Look up), To Fortnight End Date* (Text Box with Calendar Look up) , FEDRO Code (Text Box with Look up), AD Code (Text Box with Look up). Report Format (Combo Box) and Report (Button), Reset (Button) & Close (Button)
TC-006
Check for the enable and disable nature of buttons and fields when the screen is loaded.
The buttons enabled and disabled should be proper as per the specifications.
TC-007
Check display of mandatory fields.
The mandatory fields should contain the red color asterisk (*) symbol on the top right side of the field.
TC-008
Check for the screen layout
The screen layout should be proper as per the
specifications.
TC-009
Check for the Font style, Font Size and Font color of the Screen objects
All the fields should have same Font style, Font Size and Font color as per the requirement specifications.
TC-010
Check for the proper alignment of the Screen objects on screen load
The fields and buttons should be aligned properly without overlapping.
TC-011
Check for the spelling mistakes of the Screen objects
The Screen objects should be devoid from the spelling mistakes
TC-012
Check for the back ground color and the logos used are consistent throughout the application.
The back ground color and the logos used should be consistent throughout the application.
TC-013
Check for the tab movement
The tab movement should be proper as the requirement specifications.
TC-014
Check for the Tool Tips displayed in the screen
Appropriate Tool Tips should be displayed in the screen.
TC-015
Check for the default values displayed on form load
All default values should be displayed properly while loading a page
TC-016
Check for mandatory nature of the From Fortnight Start Date*
Should be displayed Based on the System date, the Text Fields From Fortnight
TC-017
Calendar textbox fields.

Start Date* and To Fortnight Start Date* should display either First or Second Fortnight and 'PDF' should be selected in Report Format Combo box.
TC-018
Calendar lookup window.
The From Fortnight Start Date* calendar should be opened and Cursor should be focused on the Current date and User should be allowed to select required date.


How to retrieve the cookie from webpage using QTP?

A cookie is a small piece of information stored by the browser that applies to a Web page. Each cookie can store up to 20 name=value; pairs called crumbs, and the cookie is always returned as a string of all the cookies that apply to the page.
This means that you must parse the string returned to find the values of individual cookies.
 
 
You can retrieve cookies for a specific URL with two methods:
 
 
Method 1:GetCookies
msgbox Browser("Google").GetCookies("http://www.google.com")
Retrieve value of cookies for a web page with HP QTP
Method 2: Object.cookie
strCookie = Browser("Google").Page("Google").Object.cookie
msgbox strCookie
Retrieve value of cookies for a web page with HP QTP

Thursday, 23 June 2011

QTP: Parameterization with Excel

Dim xlApp, xlBook, xlSheet
Dim iRow, sUserName, sPassword
CONST iUserNameCol = 1 'UserName is in Column A
CONST iPasswordCol = 2 'Password is in Column B

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.WorkBooks.Open("C:\TestFile.xls")
Set xlSheet = xlBook.WorkSheets("Sheet1")
 
'iRow = 2 because data to be driven starts from Row #2
For iRow = 2 to xlSheet.UsedRange.Rows.Count
 
   'Retrieve UserName and Password from "iRow" rows and columns A & B
   sUserName = xlSheet.Rows(iRow).Columns(iUserNameCol).Value
   sPassword = xlSheet.Rows(iRow).Columns(iPasswordCol).Value
 
   'Parameterization Block:
   With Browser("title:=Welcome: Mercury Tours", "index:=0")
      'Step 2
      .WebEdit("name:=userName").Set sUserName   'Parameter 1: UserName
      .WebEdit("name:=password").Set sPassword   'Parameter 2: Password
      .Image("name:=login").Click
   End With   
 
   'Step 3: If Find a Flight page appears, go back to Home
   If Browser("title:=Find a Flight: Mercury Tours:", "index:=0").Exist(10) Then
      Browser("title:=Find a Flight: Mercury Tours:", "index:=0").Link("text:=Home").Click
 
      'Step 4: Pass the iteration
      Reporter.ReportEvent micPass, "Iteration " & iRow-1, "UserName: " &sUserName& " is valid"
   Else
      'Step 5: Fail the iteration and return to the Home page
      Reporter.ReportEvent micFail, "Iteration " & iRow-1, "UserName: " &sUserName& " is invalid"
      Browser("title:=Sign-on: Mercury Tours", "index:=0").Link("text:=Home").Click
   End If   
 
Next
 
xlBook.Close
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

Wednesday, 15 June 2011