Micro Focus QTP (UFT) Forums
Unable to close the new browser - when clicked on attachment - 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: UFT / QTP Others (https://www.learnqtp.com/forums/Forum-UFT-QTP-Others)
+--- Thread: Unable to close the new browser - when clicked on attachment (/Thread-Unable-to-close-the-new-browser-when-clicked-on-attachment)



Unable to close the new browser - when clicked on attachment - kkishore123456 - 05-19-2010

Dear All,

Hope you are doing well. I am facing a silly problem.

scenario is like this:
1. On a webpage, I need to add few attachments with extensions like .txt, .doc, .xls, .jpg, .bmp etc
2.After that when I click on those links (example: samplefile.txt or samplefile.bmp) for some of the filetypes, new browser is getting opened (for all image files and text files, new browser gets opened)
3.I need to close this browser --this is the verification procedure to validate that the file has been opened.

I tried with If Browser("CreationTime:=1").exist then Browser("CreationTime:=0").close

On my application, 1st browser is QCenter 2nd will be my application and this 3rd browser gets opened when I click on these image files, new browser gets opened, it has to be closed.

I want to close the recently opened browser.

Please provide me solutions ASAP.
Thanks,
kishore


RE: Unable to close the new browser - when clicked on attachment - sreekanth chilam - 05-19-2010

Hi Kishore,

I would suggest you to go with the below way.

Step1: Create a Description object for "Browser" object class and Retrieve the Active browser count after clicking on the image/text files.
Step2: Use the loop > iterate thru the loop and retrieve the Browser property "Name" value using GetROProperty.
Step3: Use Instr function to search for the expected filename content in the entire Browser Name > once it is found > close the current browser > Exit out of the Loop

Code will be something like this as given below :

Code:
Expected_FileName="test Image file Filename"    
   Set br=description.Create
   br("micclass").value="Browser"

   Set br_collection=Desktop.ChildObjects(br)
   br_count=br_collection.count-1
  
    For i=0 to br_count
         Current_brName=br_collection(i).GetROProperty("Name")
            If (instr(1,Current_brName,Expected_ImageFileName)>0) then
                  br_collection(i).close
           Exit for
            End if  
    Next

It would work fine as you expected Smile


RE: Unable to close the new browser - when clicked on attachment - kkishore123456 - 05-19-2010

Thanks my dear friend.

Let me try this one and get back to you. BTW, new browser will open for sample.txt, sample.bmp, sample.pdf. sample.gif, sample.jpg files alone.

In that case, how do I give the Expected_FileName value?

In the datatable, I have the paths of the filenames
1.sample.txt
2.sample.bmp
3.sample.jpg
4.sample.gif
5.sample.pdf
6.sample.html
7.sample.xls
8.sample.doc

I am making use of For i=1 to Datatable.Getsheet("sheetname").Getrowcount

Inside the loop, I am attaching files and opening those attachments.
I need to throw a reporter.pass message or fail message once these files are viewable, then this is pass else fail

Please advise!
thanks
kish

Moreover, when I click on these attachments, (bmp,gif,pdf,html,jpg), new browser gets opened, but its name/title is just "browser" thats all. I tried to record and added to OR as well, same thing is happening, no specific name or title is being identified for this browser.

Please advise!
kishore


RE: Unable to close the new browser - when clicked on attachment - kkishore123456 - 05-21-2010

Dear all,

I got the solution by for my problem

Code:
Function CloseRecentlyOpenedBrowser()

Dim oDescription
Dim BrObjectList
Dim oLatestBrIndex

Set oDescription=Description.Create
oDescription("micclass").value="Browser"
Set BrowserObjectList=Desktop.ChildObjects(oDescription)
oLatestBrIndex=BrObjectList.count-1

Browser("creationtime:="&oLatestBrIndex).close

Set oDescription=Nothing
Set BrObjectList=Nothing
End Function
I found this function in one of the sites and I made changes to it as per my requirement.

Thanks guys!
Kishore