Micro Focus QTP (UFT) Forums
UFT IS NOT ABLE TO FIND THE RUNTIMEOBJECT(myo) IN FOR LOOP FOR THE SECOND ITERATION - 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: UFT IS NOT ABLE TO FIND THE RUNTIMEOBJECT(myo) IN FOR LOOP FOR THE SECOND ITERATION (/Thread-UFT-IS-NOT-ABLE-TO-FIND-THE-RUNTIMEOBJECT-myo-IN-FOR-LOOP-FOR-THE-SECOND-ITERATION)



UFT IS NOT ABLE TO FIND THE RUNTIMEOBJECT(myo) IN FOR LOOP FOR THE SECOND ITERATION - lakshmi29 - 09-14-2014

Please find the program and attachment
Option explicit 'mandatory to declare a variable before using it

Code:
'declaration of variables
Dim vhvalue,virate,vpmi,vprincipal,vtax,vterm,i,j
Dim vurl,vapp1,vapp2,xpath,xsheet
Dim vpayment1,vpayment2,myo

' fixed variable assignment (paths)used
vurl="C:\Program Files (x86)\Internet Explorer\iexplore.exe"
vapp1="www.mortgagecalculator.org/"
vapp2="http://www.mortgagecalculatorplus.com/"
xpath="E:/QTP_PRACTICE/MORTAGAGEXL.xlsx"
xsheet="MORTAGAGEINPUT"

'loop to repeat the test with different sets of input values

For i = 2 To 7
j=1

virate= myxl_read(xpath,xsheet,i,1)
vpmi=myxl_read(xpath,xsheet,i,2)
vtax=myxl_read(xpath,xsheet,i,3)
vterm=myxl_read(xpath,xsheet,i,4)
vprincipal=myxl_read(xpath,xsheet,i,5)
vpayment1=app1()
vpayment2=app2()
print "result for the iteration" & j & "is" & cmp_fun(vpayment1,vpayment2)

Next
    

Function app1()

'launches browser and opens the app1
systemutil.Run vurl , vapp1

'Sets the  input values into the app1

browser("Mortgage Calculator").Page("Mortgage Calculator").WebEdit("irate").Set virate
browser("Mortgage Calculator").Page("Mortgage Calculator").WebEdit("pmi").Set vpmi
browser("Mortgage Calculator").Page("Mortgage Calculator").WebEdit("tax").Set vtax
browser("Mortgage Calculator").Page("Mortgage Calculator").WebEdit("term").Set vterm
browser("Mortgage Calculator").Page("Mortgage Calculator").WebEdit("principal").Set vprincipal

'Calculating the result
browser("Mortgage Calculator").Page("Mortgage Calculator").WebButton("Calculate").Click

'Capturing the result

Set myo=description.Create()
myo("htmltag").value="H3"
myo("index").value="1"
****************************************************
app1=browser("Mortgage Calculator").Page("Mortgage Calculator").WebElement("myo").GetROProperty("innertext"
*****************************************************

print  "result of app1" &app1

'Close the mortagage calculator app1
browser("Mortgage Calculator").Close

End Function

wait 3

Function app2()
    
'launches browser and opens the app2
systemutil.Run vurl , vapp2

'Sets the  input values into the app2

browser("Mortgage Calculator").Page("Mortgage Calculator").WebEdit("irate").Set virate
browser("Mortgage Calculator").Page("Mortgage Calculator").WebEdit("pmi").Set vpmi
browser("Mortgage Calculator").Page("Mortgage Calculator").WebEdit("tax").Set vtax
browser("Mortgage Calculator").Page("Mortgage Calculator").WebEdit("term").Set vterm
browser("Mortgage Calculator").Page("Mortgage Calculator").WebEdit("principal").Set vprincipal

'Calculating the result
browser("Mortgage Calculator").Page("Mortgage Calculator").WebButton("Calculate").Click

'Capturing the result of app2

myo("htmltag").value="H3"
myo("index").value="0"
**************************************************
app2=browser("Mortgage Calculator1").Page("Mortgage Calculator").WebElement("myo").GetROProperty("innertext")
**************************************************
print "result of app2" &app2


'Closing the browser of app2

browser("Mortgage Calculator1").Close

End Function
    
    
    

'Compareing the result of two applications
Function cmp_fun(val1,val2)

If val1=val2 Then
    cmp_fun= "pass"
else
    cmp_fun="fail"
End If
    
End Function


Function myxl_read(xpath,xsheet,xrow,xcol)
    Dim myxlapp,myxlsheet
    
    set myxlapp=createobject("Excel.application")
    myxlapp.Workbooks.Open(xpath)
    set myxlsheet= myxlapp.ActiveWorkbook.Worksheets(xsheet)
    myxl_read=myxlsheet.cells(xrow,xcol)
    
    myxlapp.ActiveWorkbook.Close
    myxlapp.Application.Quit

End Function