Micro Focus QTP (UFT) Forums
Open Browser - 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: Open Browser (/Thread-Open-Browser)



Open Browser - stevol - 09-17-2008

Hi,
i have created a function to open a browser, but i don't understand one thing. Here the code:

Code:
Function FunOpenBrowser()
    
    dim objexpl, brow, pag, hwnd(1)
    set objexpl = CreateObject("InternetExplorer.Application")
    objexpl.visible = true
    objexpl.navigate "http://www.vodafone.it"
    wait(5)
    
    Set brow  = Browser("hwnd:=" & objexpl.hwnd)
    Set pag   = brow.Page("title:=" & objexpl.Document.Title)
    pag.Sync
    
    hwnd(0)  = brow.getroproperty("hwnd")
    hwnd(1)  =  pag.getroproperty("hwnd")
    
    FunOpenBrowser = hwnd
    
End Function

I use a program to modify host files, because I have different test environments, but when i launch this function the opend browser has always the same host...
[if i write a similar function using SystemUtil.Run "iexplore" i have not this problem].
Can somebody explain me this behaviour?
thanx a lot


RE: Open Browser - Ankur - 09-29-2008

what is the relation between the host files and the function you have given above?


RE: Open Browser - stevol - 09-29-2008

Hi Ankur,
I modify host file before launching the function, for example if i suppose:
1. host file1 -> vodafone of AAA environment
host file2 -> vodafone of BBB environment

At the beginning i have host file1. I change with host file2, and then i launch my function: in my idea the function must open a browser towards www.vodafone.it related to BBB environment, but it opens AAA environment.

If i modify my function with another in which i use "systemutil run iexplore" i have not these problems (i modify host file, then i launch the function and the open browser is related to right environment), but i'd like to use my other function.

thanks to any help


RE: Open Browser - Ankur - 09-29-2008

I still don't understand...can you explain the LOGICAL sequence? How are they related in terms of scripting?


RE: Open Browser - stevol - 09-29-2008

They are not related... the change of host is a pre-requisite before launch of script to choose the right environment in which doing tests... but i observe that with the function "systemutil.run ..." the browser will be opened always on the right environment, while with CreateObject("InternetExplorer.Application") not...
In particular, if for example there is a browser already opened on AAA environment, then change host towards BBB and launch function, the new browser will be opened again on AAA (and not BBB...), while if there are not previous opened browsers on AAA, the new browser will be correctly opened on BBB.
It seems that in case of pre-existent opened browsers, the CreateObject("InternetExplorer.Application") will open a new browser on the same environment of opened browsers...
It's strange because with "systemutil.run ..." i have not this behaviour...


RE: Open Browser - Ankur - 09-29-2008

ok you need to destroy the object and quit from IE in the end.


RE: Open Browser - stevol - 09-29-2008

so without closing opened browsers is it not possible to open new browsers in other environments using objects, right?
thanks a lot