Ask a Question

handle file download in browser

vthomeschoolmom
Super Contributor

handle file download in browser

I saw some related posts on this topic which refer to the SaveFile method of the Window object. A web app does not have a window object in it. At least mine doesn't. ๐Ÿ™‚

 

My application under test presents a user with an option to open or save a file to be downloaded. In my test, I want to save it to ... wherever. Obviously, the different brownsers have different dialogs. Object spy does not see the dialog at all. 

 

What is the best way to handle this in a web app in a manner that is useful for all browsers? THANKS!

18 REPLIES 18
AlexKaras
Community Hero

Re: handle file download in browser

Hi,

 

Do you have Web license only or also Desktop one?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
RUDOLF_BOTHMA
Community Hero

Re: handle file download in browser

Hi @vthomeschoolmom 

 

The implementation for Chrome and IE differ somewhat, but you could look at using UIAObjects.  I have implemented this previously for downloading files in IE following a similar question finding downloaded files:

 

https://community.smartbear.com/t5/TestComplete-Functional-Web/determine-file-name-of-downloaded-fil...

 

https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/window-and-process/ui...

 

Redacted code:

 

var frameObj = Aliases.browser.BrowserWindow.WaitWindow("Frame Notification Bar");
var UIANotificationObj = frameObj.UIAObject("Notification");
var objectName = "Save"; //Or whatever the button you are looking to click
var UIAfindObj = UIANotificationObj.UIAObject(objectName);
UIAfindObj.Click();

Of course you may need to map one or two objects.  And definately add some waits, checks, retries, refreshmappinginfo(s) to make sure it doesn't fall over, but basically you wait for the notification bar with the save/open/save as buttons and click it

 

Also, if you know exactly what your file is going to be called, you could look at:

 

https://support.smartbear.com/viewarticle/8999/

 

Haven't tried this myself though...


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
vthomeschoolmom
Super Contributor

Re: handle file download in browser

Web license only.

AlexKaras
Community Hero

Re: handle file download in browser

Hm-m... Then this may be a problem because both Save As system dialog and mentioned UIA object are regular Windows objects but not elements of web page.

I would recommend contact Support directly via the https://support.smartbear.com/message/?prod=TestComplete form in order to get official reply.

If they confirm that Desktop license is required to handle these windows and this is not the way to go for you, you may consider some workarounds to make these windows not to be displayed. For example, configure your application so that the file is downloaded without a prompt to a known location. Or use a popular Selenium workaround to issue plain HTTP HEAD request to verify that the file can be downloaded but without actual download.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
vthomeschoolmom
Super Contributor

Re: handle file download in browser

var frameObj = Aliases.browser.BrowserWindow.WaitWindow("Frame Notification Bar");

This makes me think a Desktop testing license is required. WaitWindow is not one of my options for a browser window. Am I thinking wrong?

tristaanogre
Community Hero

Re: handle file download in browser

No, I think you're correct.  The reason being is that you're interacting directly with the browser application rather than the web application the browser is serving up... The browser is a Desktop application and, while you're not TESTING it, you do need to interact with it.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
RUDOLF_BOTHMA
Community Hero

Re: handle file download in browser

Hmm,

My organisation has Web and desktop floating licences, so that might be the difference, but my tests don't use a desktop licence and still work.

 

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
vthomeschoolmom
Super Contributor

Re: handle file download in browser

How do you know that example you posted does not use the desktop license? I think it does. Thanks.

RUDOLF_BOTHMA
Community Hero

Re: handle file download in browser

Smartbear's licence manager tells us which user is using which license.  All the desktop licenses are used by other users, but my user is only allocated a web license.  It could be however, that Smartbear has a "Remote only" kind of user that can dip into the desktop license without using it, which would mean that the desktop licence is still required without "using" it.

 

What @tristaanogre says about the browser being a desktop license does make sense though.  I just don't understand their licensing structure and method well enough to comment.


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
cancel
Showing results forย 
Search instead forย 
Did you mean:ย