Micro Focus QTP (UFT) Forums
Getting object reference error if i run QTP script - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Getting object reference error if i run QTP script (/Thread-Getting-object-reference-error-if-i-run-QTP-script)



Getting object reference error if i run QTP script - nistalaramesh - 02-03-2010

I am using a Dot Net Application. It contains a wizard. If i run manually the wizard after clicking on finish button in the last form the wizard gets closed.

I recorded the same in QTP and if i run the script when qtp clicks on finish button i am getting Object reference error and my application gets closed.
Please anyone can help me in this how can i proceed with QTP in this case.

Error:
Exception in <Application name(exe file)>.My.MyApplication. Object reference not set to an instance of an object.
And if i click on the message box my application gets closed. But if i run manually i am not getting this type of error.


RE: Getting object reference error if i run QTP script - Saket - 02-05-2010

Can you paste the part of recorded script where it fails and gives the error?
may be that can help us to understand the issue.


RE: Getting object reference error if i run QTP script - nistalaramesh - 02-05-2010

Hi Saket,
This is my recorded script. While running at last if QTP clicks on finish button then getting the error. But manually if i run it application not throwing error. I am also attaching the screen shots for the wizard. In the results page we are not entering any thing just clicking on finish only.

Recorded QTP Script
Code:
SwfWindow("ITKK.NET").SwfTreeView("tvITKKTree").Select "AutoCustomer-3-Feb-2010;test compressor class 2.1;1st Stage", micRightBtn
SwfWindow("ITKK.NET").SwfToolbar("SwfToolbar").Select "Operating Condition Wizard"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtOCName1").Set "Design"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtSuctionPressure1").Set "1.03"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtDischargePressure1").Set "3.90"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtSuctionTemperature1").Set "-90"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfButton("Next").Click
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtGasAnalysisName2").Set "methane"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtGasAnalysisName2").Type  micTab
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtHumidity2").Type  micTab
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfComboBox("cmbHumidity2").Type  micTab
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvGases").SelectCell 93,"Gas Name"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfButton("btnAdd").Click
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvSelectedGases").SelectCell 1,"Proportion"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvSelectedGases").SetCellData 1,"Proportion","90"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvGases").SelectCell 119,"Gas Name"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvSelectedGases").SelectCell 2,"Gas Name"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvSelectedGases").SelectCell 2,"Proportion"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvSelectedGases").SetCellData 2,"Proportion","10"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfButton("Next").Click
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfButton("Finish").Click


Even i modified the script as like below. But no use. Tabhits is just a small function contains for loop.

Code:
Set WshShell = CreateObject("WScript.Shell")
Public Function TabHits(i)
       For j = 1 to i
            WshShell.SendKeys "{TAB}"
       Next
End Function


Code:
SwfWindow("ITKK.NET").Activate
SwfWindow("ITKK.NET").SwfTreeView("tvITKKTree").Select "AutoCustomer-3-Feb-2010;test compressor class 2.1;1st Stage"
SwfWindow("ITKK.NET").SwfTreeView("tvITKKTree").Select "AutoCustomer-3-Feb-2010;test compressor class 2.1;1st Stage", micRightBtn
SwfWindow("ITKK.NET").SwfToolbar("CMSOpen").ShowDropdown "Wizards"
SwfWindow("ITKK.NET").SwfToolbar("CMSOpen").Select "Wizards;Operating Condition Wizard"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtOCName1").Set "Design"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtSuctionPressure1").Set "1.03"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtDischargePressure1").Set "3.90"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtSuctionTemperature1").Set "-90"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfButton("Next").Click
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfEdit("txtGasAnalysisName2").Set "methane"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvGases").SelectCell 0,"Formula"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvGases").SelectCell 93,"Gas Name"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfButton("btnAdd").Click
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvSelectedGases").SelectCell 1,"Proportion"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvSelectedGases").SetCellData 1,"Proportion","90"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvGases").SelectCell 119,"Gas Name"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfButton("btnAdd").Click
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvSelectedGases").SelectCell 2,"Proportion"
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfTable("dgvSelectedGases").SetCellData 2,"Proportion","10"
wait(3)
SwfWindow("ITKK.NET").SwfWindow("Operating Condition").SwfButton("Next").Click
wait(3)
Call TabHits(21)
wait(2)
WshShell.SendKeys "{ENTER}"

Hi Saket i am also attaching the screen shots for the same.


RE: Getting object reference error if i run QTP script - Saket - 02-05-2010

may be it is related to the way QTP is interacting with controls/COM objects before the AUT is ready to handle the event.

what I can suggest here is to use wait/sync statements to wait the application to finish its internal processes.


RE: Getting object reference error if i run QTP script - nistalaramesh - 02-05-2010

Hi Saket,
The error still appears even if i put a wait time of about 30 Sec to 5 minutes. After clicking on finish normally the wizard closes.

Please any suggestions more?