Tuesday, December 6, 2011

How "On Error Resume Next" can be a problem in QTP?

How "On Error Resume Next" can be a problem in QTP?
'"On Error Resume Next" is used to handle errors in vbscript/QTP and usually very helpful. But many times, it might give you unexpected outcomes. Let's see how..
Example 1:
Function Example(var1 , var2)
On Error Resume Next
Example = var1/var2
On Error GOTO 0
End Function
msgbox Example(2, 0)
Run this code and see the result.


Result - Blank value is returned because of 'On Error Resume Next', which is incorrect! If 'On Error Resume Next' is not there, it must return an error code - 11, as division by zero.
Consider the situation where you are passing the above output as an input is some other function! What'll happen? Whole your test will do something unexpected and you..... :)
You'll just keep looking in the code for What went wrong!!



Example 2:
Suppose there is a bug in application, i.e. Login button is not displayed.
On Error Resume Next
Browser("mybrowser").Page("mypage").WebEdit("loginname").Set "abhikansh"
Browser("mybrowser").Page("mypage").WebEdit("password").SetSecure "mypass"
Browser("mybrowser").Page("mypage").WebButton("login").click
On Error GOTO 0
Result : Even though the Login button is not displayed on the page, there will be no runtime error and because steps inside the 'On error resume next' are not optional, it leads to incorrect result.
So what's the lesson? Shall I avoid to use 'On error resume next'?
No. Not at all! But be very careful while using.
Remember.. Its useful when you intentionally don't want to let errors occur i.e. any temporary browser specific error or printer error which is not about AUT (application under test).

Monday, October 10, 2011

Search for Particular value in Excel

Set myxl = createobject("excel.application")
myxl.Application.Visible = true
myxl.Workbooks.Open "C:\Documents and Settings\pavann\Desktop\qtp15"
'This is the name of Sheet in Excel file "qtp15.xls" where data needs to be entered
set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")
'Select the used range in particular sheet
With mysheet.UsedRange
' Data "PAVAN" to search
' Loop through the used range
For each search_data in mysheet.UsedRange
' compare with the expected data
If search_data="PAVAN" then
'make the cell with color if it finds the data search_data.Interior.ColorIndex = 10
End If
next
End With
myxl.ActiveWorkbook.Save
myxl.ActiveWorkbook.Close
myxl.Application.Quit
Set mysheet =nothing
Set myxl = nothing

-- Pavankumar Nandagiri

Read the data from Excel File

Set xlapp3 = createobject("excel.application")
xlapp3.Visible = true
Set xlbook3 = xlapp3.Workbooks.Open("C:\Documents and Settings\pavann\Desktop\qtp15")Set xlsheet3= xlbook3.Worksheets("sheet1")
xlrwcnt = xlsheet3.usedrange.rows.count
'msgbox xlrwcnt
xlcolcnt = xlsheet3.usedrange.columns.count
'msgbox xlcolcnt
For m=1 to xlrwcnt
For n=1 to xlcolcnt
val = xlsheet3.cells(m,n).value
msgbox val
Next
Next

-- Pavankumar Nandagiri

Wednesday, October 5, 2011

Creating a new Excel sheet, Opening the exsisting sheet & entering data and saving it

'Creating a new Excel sheet
Set xlapp = createobject("excel.application")
xlapp.Visible = true
xlapp.Workbooks.Add
xlapp.ActiveWorkbook.SaveAs("C:\Documents and Settings\pavann\Desktop\qtp12")xlapp.Application.Quit
Set xlapp=nothing

'Opening the exsisting sheet & entering data and saving it
Set xlapp1 = createobject("Excel.Application")
xlapp1.Visible = true
Set xlbook1 = xlapp1.Workbooks.Open("C:\Documents and Settings\pavann\Desktop\qtp12")Set xlsheet1 = xlbook1.Worksheets("sheet1")
For i = 1 to 10
xlsheet1.cells(i,1).value = "pavan"
For k = 1 to 10
If k>1 Then
xlsheet1.cells(i,k).value = "soumya"
End If
Next
Next
set objrange = xlsheet1.usedrange
For each cell in objrange
cell.value = ucase(cell.value)
Next
xlbook1.Save
xlapp1.Application.Quit
Set xlapp1=nothing

-- Pavankumar Nandagiri

Tuesday, October 4, 2011

Adding values into excel sheet and changing the cell values to Uppercase

Set xlapp = createobject("Excel.Application")
xlapp.Visible = true
set xlbook = xlapp.Workbooks.Open("C:\Documents and Settings\pavann\Desktop\test")
set xlsheet = xlbook.Worksheets("sheet1")
For i = 1 to 10
For j= 1 to 10
xlsheet.cells(i,1) = "pavan"
If j>1 Then
xlsheet.cells(i,j) = "soumya"
End If
Next
Next
set objrange = xlsheet.usedrange
For each objcell in objrange
objcell.value = Ucase(objcell.value)
Next

-- Pavankumar Nandagiri

Associating the evironment variables (By Parametrization)

' Associating the evironment variables (By Parametrization)


'Develop the script in test pane as below:' Setting the declered environment value (a ) to value1 edit button
VbWindow("Form1").VbEdit("val1").Set environment.Value("a")
' Setting the declered environment value (b ) to value2 edit button
VbWindow("Form1").VbEdit("val2").Set environment.Value("b")
' clicking on ADD button
VbWindow("Form1").VbButton("ADD").Click




-- Pavankumar Nandagiri

Monday, October 3, 2011

To find the last day of the current month & also last day of any month and year

'To find last day of the current month
MsgBox DateSerial(Year(Now), 1 + Month(Now), 0)

'To find last day of any month and year

usr_dte = inputbox("Enter the date for which you want to know the last day of the month in the format dd/mm/yyyy")
current_date = now()
only_date = left(current_date,9)
dat_diff = datediff("m",only_date,usr_dte)
req_mnth = DateAdd ("m",dat_diff,only_date)
a = split(req_mnth,"/")
mnth = a(0)
dat = a(1)
yr= a(2)
msgbox DateSerial(yr, 1 +mnth, 0)

--Pavankumar Nandagiri

Creating a new column in a runtime datatable and adding values and moving the these values to the new column

Datatable.AddSheet("sample").AddParameter "OldColumn","pavan"
For i= 1 to 10
datatable.SetCurrentRow(i)
datatable.Value("OldColumn","sample") = "pavan"&(i)Next
rw_cnt = datatable.GetSheet("sample").GetRowCount
msgbox rw_cnt
datatable.GetSheet("sample").AddParameter "newcoloumn","Row1Value"
For k = 1 to rw_cnt
datatable.SetCurrentRow(k)
old_val = datatable.Value("OldColumn","sample")
datatable.Value("newcoloumn","sample") = old_val
Next
datatable.GetSheet("sample").DeleteParameter("OldColumn")


-- Pavankumar Nandagiri

How to add multiple values to a column for a runtime data table

'Adding a new sheet @ runtime
Datatable.AddSheet("dtGlobalSheet").AddParameter "OldColumn","pavan"
'Adding multiple values
For i= 1 to 10
datatable.SetCurrentRow(i)
datatable.Value("OldColumn","dtGlobalSheet") = "pavan"&(i)
Next

Thanks,
Pavankumar Nandagiri

Tuesday, January 6, 2009

Script for connecting to TD QC using AOM and open a script "qtp_demo"

Dim qt_obj 'Define a Quick Test object
qt_obj = CreateObject("Quick Test.Application") ' Instantiate a QT Object. It does not start QTP.
qt_obj.launch ' Launch QT
qt_obj.visible ' Make QT visible
qt_obj.TDConnection.Connect "http://tdserver/tdbin", _ 'Referencing TDConnection Object
"TEST_DOMAIN", "TEST_Project", "Ankur", "Testing", False ' Connect to Quality Center
If qt_obj.TDConnection.IsConnected Then ' If connection is successful
qt_obj.Open "[QualityCenter] Subject\tests\qtp_demo", False ' Open the test
Else
MsgBox "Cannot connect to Quality Center" ' If connection is not successful, display an error message.
End If
To quickly generate an AOM script with the current QTP settings. Use the Properties tab of the Test Settings dialog box (File > Settings) OR the General tab of the Options dialog box (Tools > Options) OR the Object Identification dialog box (Tools > Object Identification). Each contain a "Generate Script" button. Clicking this button generates a automation script file (.vbs) containing the current settings from the corresponding dialog box.
You can run the generated script as is to open QuickTest with the exact configuration of the QuickTest application that generated the script, or you can copy and paste selected lines from the generated files into your own automation script.

Wednesday, December 31, 2008

Working with AOM

Dim qtApp, qtRepositories, lngPosition


'Open QuickTest and create the Application object

Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True


'Open a test and get the "Login" action's object repositories collection

qtApp.Open "D:\Fatima\trial-qtp\adv topics\Test1", False, False
Set qtRepositories = qtApp.Test.Actions("Login").ObjectRepositories

' Add shared_rep.tsr if it's not already in the collection
If qtRepositories.Find("D:\Fatima\trial-qtp\adv topics\shared_rep.tsr") = -1 Then ' If the repository cannot be found
qtRepositories.Add "D:\Fatima\trial-qtp\adv topics\shared_rep.tsr", 1
End If

' If additional_rep.tsr is moved down the list - place it back at position 1
If qtRepositories.Count > 1 And qtRepositories.Item(1) = "D:\Fatima\trial-qtp\adv topics\additional_rep.tsr" Then
qtRepositories.MoveToPos 1,2
End If

' If debug.tsr is in the collection - remove it
lngPosition = qtRepositories.Find("D:\Fatima\trial-qtp\adv topics\debug.tsr")
If lngPosition <> -1 Then
qtRepositories.Remove lngPosition
End If

' Set the new object repository configuration as the default for all new actions
qtRepositories.SetAsDefault


qtApp.Test.Save
qtApp.Quit

Set qtRepositories = Nothing
Set qtApp = Nothing

Thursday, December 18, 2008

how to return a value from a function

Function func1(a,b)

sum = a+b
func1 = sum
End Function


aaa= func1(2,3)
msgbox aaa


Regards,

Pavankumar Nandagiri............

Tuesday, November 11, 2008

how to call Library Files(.vbs) in the Test Script

method 1 :
ExecuteFile <>
method 2:
u can add library file to ur script through Test-----------
-->Resources tab here u find option called add file there u
can add ur files manually before running the script then
save it so when ever u open that script attached lib files
also opened with that script.

Method 3:

path1="C:/Lib1"
path2="C:/Lib2"
set qtApp1 = CreateObject("QuickTest.Application")

Set qtLibraries = qtApp1.Test.Settings.Resources.Libraries ' Get the libraries collection object
qtLibraries.Add path1 ,1
qtLibraries.Add path2 ,2

Regards,

Pavankumar nandagiri..........

Thursday, November 6, 2008

FileSystemObject Properties

AtEndOfLine Property
Returns true if the file pointer is positioned immediately before the end-of-line marker in a TextStream file; false if it is not.
AtEndOfStream Property
Returns true if the file pointer is at the end of a TextStream file; false if it is not.
Attributes Property
Sets or returns the attributes of files or folders.
AvailableSpace Property
Returns the amount of space available to a user on the specified drive or network share.
Column Property
Returns the column number of the current character position in a TextStream file.
CompareMode Property
Sets and returns the comparison mode for comparing string keys in a Dictionary object.
Count Property
Returns the number of items in a collection or Dictionary object.
DateCreated Property
Returns the date and time that the specified file or folder was created. Read-only.
DateLastAccessed Property
Returns the date and time that the specified file or folder was last accessed.
DateLastModified Property
Returns the date and time that the specified file or folder was last modified.
Drive Property
Returns the drive letter of the drive on which the specified file or folder resides.
DriveLetter Property
Returns the drive letter of a physical local drive or a network share.
Drives Property
Returns a Drives collection consisting of all Drive objects available on the local machine.
DriveType Property
Returns a value indicating the type of a specified drive.
Files Property
Returns a Files collection consisting of all File objects contained in the specified folder, including those with hidden and system file attributes set.
FileSystemProperty
Returns the type of file system in use for the specified drive.
FreeSpace Property
Returns the amount of free space available to a user on the specified drive or network share.
IsReady Property
Returns true if the specified drive is ready; false if it is not.
IsRootFolder Property
Returns true if the specified folder is the root folder; false if it is not.
Item Property
Sets or returns an item for a specified key in a Dictionary object. For collections, returns an item based on the specified key.
Key Property
Sets a key in a Dictionary object.
Line Property
Returns the current line number in a TextStream file.
Name Property
Sets or returns the name of a specified file or folder.
ParentFolder Property
Returns the folder object for the parent of the specified file or folder.
Path Property
Returns the path for a specified file, folder, or drive.
RootFolder Property
Returns a Folder object representing the root folder of a specified drive.
SerialNumber Property
Returns the decimal serial number used to uniquely identify a disk volume.
ShareName Property
Returns the network share name for a specified drive.
ShortName Property
Returns the short name used by programs that require the earlier 8.3 naming convention.
ShortPath Property
Returns the short path used by programs that require the earlier 8.3 file naming convention.
Size Property
For files, returns the size, in bytes, of the specified file. For folders, returns the size, in bytes, of all files and subfolders contained in the folder.
SubFolders Property
Returns a Folders collection consisting of all folders contained in a specified folder, including those with hidden and system file attributes set.
TotalSize Property
Returns the total space, in bytes, of a drive or network share.
Type Property
Returns information about the type of a file or folder.
VolumeName Property
Sets or returns the volume name of the specified drive.
Regards,

PavanKumar Nandagiri..............

Wednesday, October 1, 2008

QTP Testing process

  1. Create your test plan - Prior to automating there should be a detailed description of the test including the exact steps to follow, data to be input, and all items to be verified by the test. The verification information should include both data validations and existence or state verifications of objects in the application.
  2. Recording a session on your application - As you navigate through your application, Quick Test graphically displays each step you perform in the form of a collapsible icon-based test tree. A step is any user action that causes or makes a change in your site, such as clicking a link or image, or entering data in a form.
  3. Enhancing your test - Inserting checkpoints into your test lets you search for a specific value of a page, object or text string, which helps you identify whether or not your application is functioning correctly. NOTE: Checkpoints can be added to a test as you record it or after the fact via the Active Screen. It is much easier and faster to add the checkpoints during the recording process. Broadening the scope of your test by replacing fixed values with parameters lets you check how your application performs the same operations with multiple sets of data. Adding logic and conditional statements to your test enables you to add sophisticated checks to your test.
  4. Debugging your test - If changes were made to the script, you need to debug it to check that it operates smoothly and without interruption.
  5. Running your test on a new version of your application - You run a test to check the behavior of your application. While running, Quick Test connects to your application and performs each step in your test.
  6. Analyzing the test results - You examine the test results to pinpoint defects in your application.
  7. Reporting defects - As you encounter failures in the application when analyzing test results, you will create defect reports in Defect Reporting Tool.

Tuesday, August 19, 2008

How to call a function from a action to another action

' create a environment variable called my_var
'Action where to want to call the function i ,e ex: -Action2

environment("my_var")="login"
runaction "Action1",environment("my_var")

'Action1

If environment("my_var")="login" Then
Call func_login()
End If


Regards,

PavanKumar Nandagiri..............

Tuesday, August 5, 2008

To load the object repository

Dim objQTP
Dim QTP_OR
Set objQTP = CreateObject("QuickTest.Application")
Set QTP_OR = objQTP.Test.Actions("Action2").ObjectRepositories
If QTP_OR.Find("D:\pavan\Test1\new.tsr") = -1 Then
QTP_OR.Add "D:\pavan\Test1\new.tsr", 1
End If
Set QTP_OR = Nothing
Set objQTP = Nothing


Regards,

Pavankumar Nandagiri..............

To find the child objects & their class in the application

Dim oDesc
Set oDesc = Description.Create()
Set parent = Window("Text:=Flight Reservation")
Set children = parent. ChildObjects (oDesc)
co = children.Count
MsgBox co
k=0
For j = 1 to (co-1)
cln= children(j).GetROProperty("micclass")
Select Case(cln)
case("WinEdit")
Objpr = children(j).GetROProperty("attached text")
case("WinButton")
Objpr = children(j).GetROProperty("text")
case("WinComboBox")
Objpr = children(j).GetROProperty("attached text")
case("AciveX")
Objpr = children(j).GetROProperty("Progid")
case("WinObject")
Objpr = children(j).GetROProperty("text")
case("Static")
Objpr = children(j).GetROProperty("text")
End Select
If Objpr <> "" Then

msgbox cls & " " & Objpr
End If

Objpr = ""
Next
MsgBox k


Regards,

PavanKumar Nandagiri.....................

Deleting the dupliacte data from Excel sheet

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

Set objWorkbook = objExcel.Workbooks.Open("D:\Qtp_ framewrk_Keyworddriven\16June_Final_Test_Scenarios_phpcollab.xls")

nor = objExcel.sheets(3).usedrange.rows.count

for i = 1 to nor
cd = objExcel.sheets(3).Cells(i, 1)
j = i+1
do Until objExcel.Cells(j, 1).Value = ""
cd1 = objExcel.sheets(3).Cells(j, 1)
if Ucase(trim(cd)) = Ucase(trim(cd1)) then
Set objRange = objExcel.Cells(j, 1).EntireRow
objRange.Delete
j = j-1
End If
j = j + 1
Loop
Next


Regards,

PavanKumar Nandagiri...........

Wednesday, July 30, 2008

How to parametrize from external file

Set xlapp =createobject("excel.application")
set xlbook = xlapp.workbooks.open ("D:\pavan\nanda.xls")
Set xlsheet = xlbook.worksheets("Sheet1")

xlcount = xlsheet.usedrange.rows.count
xlcln_count = xlsheet.usedrange.columns.count
msgbox xlcln_count

For i=2 to xlcount
For j=1 to xlcln_count


Dialog("Login").WinEdit("Agent Name:").set xlsheet.cells(i,j).value
Dialog("Login").WinEdit("Password:").set xlsheet.cells(i,j).value
xlsheet.cells(i,3).value = "pass"

Next
Next
xlbook.save
xlbook.close
xlapp.quit


Regards,

PavanKumar Nandagiri..................

Google Search

Google