Forum Discussion

vthomeschoolmom's avatar
vthomeschoolmom
Super Contributor
6 years ago

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!

      • vthomeschoolmom's avatar
        vthomeschoolmom
        Super Contributor

        No love.

        Sub Test
          Dim strFileURL, strHDLocation, objHTTP, objADOStream, objFSO 
          
          ' Specify the names of the source and destination files
          strFileURL = "http://www.automatedqa.com/file to get"
          strHDLocation = "c:\temp\filename"

        I am looking for means to handle the USER INTEFACE within the browser. 

         

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Do you have Web license only or also Desktop one?

     

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        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.

         

  • 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-file/m-p/184958#M34453

     

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

     

    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...

    • vthomeschoolmom's avatar
      vthomeschoolmom
      Super Contributor
      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's avatar
        tristaanogre
        Esteemed Contributor

        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.