Micro Focus QTP (UFT) Forums
How to find more than one application(AUT) instances are opened. - 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: How to find more than one application(AUT) instances are opened. (/Thread-How-to-find-more-than-one-application-AUT-instances-are-opened)



How to find more than one application(AUT) instances are opened. - dineshb - 08-06-2010

Hi,

During test batch execution the application is not closed,then it remains opened & second instance of the application invoked. Therefore multiple instances may be opened & batch execution fails.

Is there any way in QTP to find the total no. of "Application Under Test" instances are opened?

I know how to close the multiple instances. Use following command for it.
SystemUtil.CloseProcessByName("Notepad.exe")

Thanks in advance.
Dinesh


RE: How to find more than one application(AUT) instances are opened. - venkatbatchu - 08-06-2010

Hi,

If your application is web based application:
Code:
OnErrorResumeNext
browsercount=0
For temp=1 to 100000 step 1
intbrowser=Browser("xxxxxxxxxxxxx").GetRoProperty("Creation time")
     If len(intbrowser)>=1) Then
          browsercount=browsercount+1
     End If
     If (len(intbrowser)=0) Then
        Exit For
     End If
Next
After executing this script finally you would get the instances i.e browsercount.

Please let me know for further clarification.


RE: How to find more than one application(AUT) instances are opened. - lotos - 09-16-2010

Try this:

Code:
Public Function RunBrowser
   Set oBrowser = Description.Create
    oBrowser("micclass").Value = "Browser"

    Set oPage = Description.Create
    oPage("micclass").Value = "Page"

'Get all browsers
    Set allBrowser = Desktop.ChildObjects(oBrowser)

    Dim i, iCount
    iCount = allBrowser.Count - 1

        For i = 0 To iCount
            'Get the page object from the browser
            Set oPg = allBrowser(i).ChildObjects(oPage)(0)
            'Get the URL of the
            If  InStr (oPg.GetROProperty("URL"), "http://yahoo.com") > 0 then  
            'Close the browser
            allBrowser(i).Close
        End If
        Next
    SystemUtil.Run "iexplore.exe", "http://yahoo.com"
End Function

The function will check if in any browser exists the URL on which you are working(if it was not being closed), and will close it, after that will run again the browser with URL you need to be run.

To run your browser, call the method within first action as next:
Code:
'calling the RunBrowser function
RunBrowser

or, you can remove the "SystemUtil.Run "iexplore.exe", "http://yahoo.com"
line from the function and rename the function for e.g. as CloseAllMyURLs, and call it at the end of all your tests - it will check if your browser with your URL is closed:
Code:
'calling the CloseAllMyURLs function
CloseAllMyURLs


OR you can try this method at the end of each test:

Code:
Public Function CloseBrowser
'closing the browser
        If Browser("URL:=http://yahoo.com.*")).Exist Then
            Browser("URL:=http://yahoo.com.*")).Close
        End IF        
End Function