Save Downloaded file

37 posts, 1 answers
  1. Satyajeet
    Satyajeet avatar
    8 posts
    Member since:
    Jun 2012

    Posted 16 Jan 2012 Link to this post

    Hi,

    I am using the below code to save a file download dialog to a particular path.
    Below is my code.

     

    Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle; 
    DownloadDialogsHandler handler = new DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, @"D:\address.xls", Manager.Desktop); 
    Manager.ActiveBrowser.WaitUntilReady(); 
    Pages.abcd.FrameFrame1.DownloadlinkLink.Click(false);
    handler.WaitUntilHandled(9000);

    I am getting the attached exception and the file doesnot save.
    It opens the SaveAs dialog and doesnot pick the given path and freezes.
    Attached is the screenshot of steps performed to save.

    Could you please help.

    Thanks,
    Satya

  2. Satyajeet
    Satyajeet avatar
    8 posts
    Member since:
    Jun 2012

    Posted 16 Jan 2012 Link to this post

    Hi,

    I found the solution and the download works fine now.
    The file downlaods to the given path but the Download Complete dialogue box does not close.

    I have handled this by below code, but does not work. I have also unchecked the checkbox.
    IEDownloadCompleteDialog dlComplete = new IEDownloadCompleteDialog(ActiveBrowser, DialogButton.CLOSE, Manager.Desktop);

    Please help.

    Thanks,
    Satya
  3. Nitin
    Nitin avatar
    29 posts
    Member since:
    Oct 2010

    Posted 16 Jan 2012 Link to this post

    Hi Satya

    Which Browser you are Using, IE 8 or IE 9

    How you Handled the Download Dialogs
    I am facing the same issues in IE 9 

    http://www.telerik.com/automated-testing-tools/community/forums/test-studio-express/automation-framework/unable-to-handle-the-download-dialog-in-ie-9.aspx 
     
    Thanks
    Nitin
  4. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 16 Jan 2012 Link to this post

    Hello Satya,

    The initial code you posted is intended to work with IE8 and 9, however a regression was just discovered with IE8 where the final "Download Complete" window is not handled properly. You can track the PITS Issue here.

    As a work-around in the meantime, you can revert to the old style of handling the download in three parts. Instead of using the dialog handler for part three (where the bug is), add code to press the Enter key instead:


    Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
      
    string saveLocation = string.Format("address-{0:HH-mm-ss}.xls", DateTime.Now);
      
    //Create dialogs
    IEDownloadDialog part1 = newIEDownloadDialog(ActiveBrowser, DialogButton.SAVE, Manager.Desktop);
    SaveAsDialog part2 = SaveAsDialog.CreateSaveAsDialog(ActiveBrowser, DialogButton.SAVE, @"C:\"+ saveLocation, Manager.Desktop);
      
    //Exclude part 3
    //IEDownloadCompleteDialog part3 = new IEDownloadCompleteDialog(ActiveBrowser, DialogButton.CLOSE, Manager.Desktop);
                  
    //Add each dialog to the monitor
    Manager.DialogMonitor.AddDialog(part1);
    Manager.DialogMonitor.AddDialog(part2);
    //Manager.DialogMonitor.AddDialog(part3);
                   
    HtmlAnchor dlLink = Find.ByContent<HtmlAnchor>("Sample Address File");
    dlLink.Click();
      
    part1.WaitUntilHandled(5000);
    part2.WaitUntilHandled(5000);
    //part3.WaitUntilHandled(5000);
      
    //Alternative handling of part 3
    System.Threading.Thread.Sleep(5000);
    Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Enter);


    Kind regards,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Satyajeet
    Satyajeet avatar
    8 posts
    Member since:
    Jun 2012

    Posted 16 Jan 2012 Link to this post

    Hi Anthony,
     
    Thanks. The code works perfectly.

    Satya.
  6. Amos
    Amos avatar
    11 posts
    Member since:
    Oct 2010

    Posted 16 Feb 2012 Link to this post

    Hi, 
    I have updated Test Studio with the last Release (TestStudio_2011_2_1413) but the bug about the final "Download Complete" window persists, is normal?
  7. N1t1nA
    N1t1nA avatar
    37 posts
    Member since:
    Mar 2011

    Posted 17 Feb 2012 Link to this post

    Hi Amos 

    Which version of IE you are using,
    use downloads dialogs Handler Class

    DownloadDialogsHandler handler = new DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, @"D:\address.xls", Manager.Desktop); 
    //Click Event which initiates the Download Process
    handler.WaitUntilHandled(30000);

    Hope this Helps 
    Thanks
    Nitin



     
  8. Amos
    Amos avatar
    11 posts
    Member since:
    Oct 2010

    Posted 17 Feb 2012 Link to this post

    Hi Nitin,

    I use IE8 and I tested your code but the final "Download Complete" window remains open.



  9. N1t1nA
    N1t1nA avatar
    37 posts
    Member since:
    Mar 2011

    Posted 17 Feb 2012 Link to this post

    Hi Amos

    Please Check your browser settings
    http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/configure-your-browser/internet-explorer.aspx

    Also, you can Close this Download Complete by using Keyboard Actions,
    Sort of Workaround.
    Manager.Desktop.KeyBoard.KeyDown(Keys.Alt);
    Manager.Desktop.KeyBoard.KeyPress(Keys.F4);
    Manager.Desktop.KeyBoard.KeyUp(Keys.Alt);

    -Nitin-
  10. Amos
    Amos avatar
    11 posts
    Member since:
    Oct 2010

    Posted 17 Feb 2012 Link to this post

    My browser's settings are setted correctly .

    I use your Workaround 

    So in this release of TestStudio this bug is not really fixed?
  11. N1t1nA
    N1t1nA avatar
    37 posts
    Member since:
    Mar 2011

    Posted 17 Feb 2012 Link to this post

    Hi Amos

    Yes, this seems to be, may be Support Guys put some light on this.

    -Nitin-
  12. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 17 Feb 2012 Link to this post

    Hello Amos,

    We've discovered that certain machine configurations still leave the "Download complete" dialog open at the end of the test. We're investigating the issue and hope to have it resolved shortly.

    In the meantime please use one of the work-arounds in this thread to handle the "Download complete" dialog.

    All the best,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  13. Satyajeet
    Satyajeet avatar
    8 posts
    Member since:
    Jun 2012

    Posted 19 Jun 2012 Link to this post

    Hi Anthony,
    I am trying to handle a file download dialogue. Am using the below code.
    I would like to perform some ABC steps on the page and then handle File download diagloue and then perform some XYZ steps on the same page and then handle File download dialogue one after the other.

    The file download handles perfectly for the first time saves the output to the specified folder, but when it comes to the second file handling dialogue, the file dilogue opens but it does not click on the Save button. It hover on the Save button, but does not perform the click opertaion on the Save button. The same code works for the first time and doesnt work for the second time.

    Could you please help.

    try
     -----ABC  code here------------------
    IEDownloadDialog ieDialog = new IEDownloadDialog(ActiveBrowser, DialogButton.SAVE, Manager.Desktop);
    Manager.DialogMonitor.AddDialog(ieDialog);
                      
    SaveAsDialog saveExport;
     saveExport = SaveAsDialog.CreateSaveAsDialog(ActiveBrowser, DialogButton.SAVE, testRunDir + "\\" + "Snap" + ".pptx", Manager.Desktop);
      
                    if (File.Exists(saveExport.SaveFileName))
                    {
                        File.Delete(saveExport.SaveFileName);
                    }
                    Manager.DialogMonitor.AddDialog(saveExport);
      
                    IEDownloadCompleteDialog dlComplete = new IEDownloadCompleteDialog(ActiveBrowser, DialogButton.CLOSE, Manager.Desktop);
                    Manager.DialogMonitor.AddDialog(dlComplete);
      
                    Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
                    Manager.DialogMonitor.Start();
                    Thread.Sleep(10000);
                     Pages.panelXYZ.OwnerBrowser.Actions.InvokeScript("document.getElementById('btnGo').click()");                
                    ieDialog.WaitUntilHandled(50000000);
                     saveExport.WaitUntilHandled(50000000);
                    Thread.Sleep(2000);
                   Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Enter);
    }
    catch
    {
    }
    try
    {
     ----- XYZ code here------------------
      
     IEDownloadDialog ieDialogSnapSlicer = new IEDownloadDialog(ActiveBrowser, DialogButton.SAVE, Manager.Desktop);
     Manager.DialogMonitor.AddDialog(ieDialogSnapSlicer);                
    SaveAsDialog saveSnapSlicer;
    saveSnapSlicer = SaveAsDialog.CreateSaveAsDialog(ActiveBrowser, DialogButton.SAVE, testRunDir + "\\" + "SnapSlicer" + ".pptx", Manager.Desktop);
      
          if (File.Exists(saveSnapSlicer.SaveFileName))
                    {
                        File.Delete(saveSnapSlicer.SaveFileName);
                    }
                    Manager.DialogMonitor.AddDialog(saveSnapSlicer);
      
     IEDownloadCompleteDialog dlCompleteSnapSlicer = new IEDownloadCompleteDialog(ActiveBrowser, DialogButton.CLOSE, Manager.Desktop);
     Manager.DialogMonitor.AddDialog(dlCompleteSnapSlicer);
      
    Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
     Manager.DialogMonitor.Start();
    Thread.Sleep(10000);
    Pages.panelXYZ.OwnerBrowser.Actions.InvokeScript("document.getElementById('btnGo').click()");
     ieDialogSnapSlicer.WaitUntilHandled(50000000);
    Thread.Sleep(2000);
    saveSnapSlicer.WaitUntilHandled(50000000);
    Thread.Sleep(2000);                
    Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Enter);
      
    }
    catch
    {
    }


    Regards,
    Satya
  14. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 19 Jun 2012 Link to this post

    Hello Satya,

    Now that the original issue is resolved, you can use the DownloadDialogsHandler once again. It automatically handles all three download dialogs in sequence.

    The following code successfully handles two downloads consecutively in version 2012.1.528:

    Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
    Manager.LaunchNewBrowser();
     
    string saveLocation = string.Format("address-{0:HH-mm-ss}.xls", DateTime.Now);
    DownloadDialogsHandler handler1 = new DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, @"C:\1" + saveLocation, Desktop);
     
    HtmlAnchor dlLink = Find.ByContent<HtmlAnchor>("Sample Address File");
    dlLink.Click();
    System.Threading.Thread.Sleep(2500);
    handler1.WaitUntilHandled(30000);
     
    System.Threading.Thread.Sleep(2500);
    DownloadDialogsHandler handler2 = new DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, @"C:\2" + saveLocation, Desktop);
    dlLink.Click();
    System.Threading.Thread.Sleep(2500);
    handler2.WaitUntilHandled(30000);
     

    All the best,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  15. Satyajeet
    Satyajeet avatar
    8 posts
    Member since:
    Jun 2012

    Posted 21 Jun 2012 Link to this post

    Hi Anthony,
    As suggested by you, i also tried using DownloadDialogsHandler, but the same issue exists. The download dialogue handles for the first save dialogue perfectly, but when it moves to the second file download dialogue....it is unable to handle it and file download dialogue just stays on......it does not perform the click operation on the SAVE button.....i see that on the file download dialogue for the second time the CANCEL button is highlighted with blue border blinking and on the on the SAVE button i see a dotted border....i guess the mouse hover on SAVE button, but is unable to perform the click operation for the second time......if i manually click the save button when the file download dialogue stays on, it works good.....when i debug the code, the file download handles the second dialogue aswell.......it successfully handles two downloads consecutively when i debug the code and also when i manually perform the click on the SAVE button, but stays on when i run the application.
    I am unable to figure out this strange behavior. i am stuck with this issue since couple of days. It would be very kind if you could please provide me a perfect solution.

    FYI....in my application i am trying to handle 5 file download dialogues one after the other. i ALSO tried to keep the DownloadDialogsHandler in a seperate method and just call the method everytime....it just works for the first time as usual.....stays on when it comes to handle the second dialogue, if i manually click save button for second time, it again stays on when it comes to handle the third file download dialogue and so on..
    Hope i have explained my issue in detail

    Thanks,
    Satya

  16. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 22 Jun 2012 Link to this post

    Hello Satya,

    Are you using version 2012.1.528 of the Framework where this issue is fixed? Have you tried the sample code I provided in my last response, which is written against a public site?

    If you upgrade and continue to experience difficulty, please provide a complete code sample against a public site that demonstrates the issue.

    Kind regards,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  17. Aliluyko
    Aliluyko avatar
    8 posts
    Member since:
    Oct 2012

    Posted 03 Jan 2013 Link to this post

    Hi,
    Could you help with download toolbar in IE9??
    I have one solution but it's doesn't stability.
    I use Telerik_Testing_Framework_2012_2_1204_FREE_EDITION.
                            // for IE9
                            downloadLink.Click(true);

                            Thread.Sleep(3000); // to show download bar

                            WindowManager winManager = new WindowManager();
                            Process prc = _telerikManagerObj.ActiveBrowser.Window.OwnerProcess;
                            winManager.GetAllWindows(prc);

                            foreach (Window win in winManager.Items)
                            {
                                //if (win.ClassName == "DirectUIHWND")
                                if (win.ClassName == "Frame Notification Bar")
                                {
                                    // relative position formula: xPos = frameWidth / 12 * 2 * -1.
                                    // 12 - amount of buttons that could be placed in frame
                                    // 2 - "Save As" button is second button from the right
                                    // -1 - for negative offset
                                    _telerikManagerObj.Desktop.Mouse.Click(MouseClickType.RightClick, win.Rectangle, new Point(win.Size.Width/12*2*-1, 7), OffsetReference.RightCenter);
                                    Thread.Sleep(500);
                                    // sometimes one click is not enough to set focus
                                    _telerikManagerObj.Desktop.Mouse.Click(MouseClickType.RightClick, win.Rectangle, new Point(win.Size.Width/12*2*-1, 7), OffsetReference.RightCenter);
                                    Thread.Sleep(500);
                                    _telerikManagerObj.Desktop.KeyBoard.KeyPress(Keys.Down);
                                    _telerikManagerObj.Desktop.KeyBoard.KeyPress(Keys.Down);
                                    _telerikManagerObj.Desktop.KeyBoard.KeyPress(Keys.Enter);
                                    break;
                                }
                            }

                            //start monitoring for download dialog with 5 sec delay
                            _systemHandler.ProcessDownloadDialog(pathForDownload);

    Thanks.

  18. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 03 Jan 2013 Link to this post

    Hello Aliluyko,

    It appears to me you may be taking the hard way to handling the standard IE download popup. We have a built-in download dialog handler that will do 90% of the work for you.

    Regards,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  19. Aliluyko
    Aliluyko avatar
    8 posts
    Member since:
    Oct 2012

    Posted 03 Jan 2013 Link to this post

    Hello Cody,

    Does this solution work with toolbar, which was attached above?
    Thanks.
  20. Aliluyko
    Aliluyko avatar
    8 posts
    Member since:
    Oct 2012

    Posted 04 Jan 2013 Link to this post

    Cody,

    Solution, which was provided doesn't work with download toolbar.(Image of toolbar was attached).
    Have you another solutions?
    Thanks.
  21. Mario
    Admin
    Mario avatar
    8 posts

    Posted 08 Jan 2013 Link to this post

    Hi Aliluyko,

    Here is a code sample and execution video of the download handler running against the IE9 'toolbar':

    Settings.Current.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
    Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
    ActiveBrowser.NavigateTo("http://www.fiddlercap.com");
    Element b = Find.ByAttributes("href=/dl/FiddlerCapSetup.exe");
    string saveLocation = System.IO.Path.Combine("C:\\", "FiddlerCapSetup.exe");
    DownloadDialogsHandler handler = new DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, saveLocation, Desktop);
    Actions.Click(b);
    handler.WaitUntilHandled(20000);

    Let me know if you have any followup questions.

    All the best,
    Mario
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  22. Aliluyko
    Aliluyko avatar
    8 posts
    Member since:
    Oct 2012

    Posted 10 Jan 2013 Link to this post

    Hi Mario,
    Thanks.
  23. Aliluyko
    Aliluyko avatar
    8 posts
    Member since:
    Oct 2012

    Posted 21 Jan 2013 Link to this post

    Hi Mario,

    I have issue with handling download dialog.
    During download I get multiline toolbar. He more width than standard.
    Could you help with this issue?
    I use following code:
                                                                         ...
                    DownloadDialogsHandler downloadDialogsHandler = new DownloadDialogsHandler(downloadLink.OwnerBrowser, DialogButton.SAVE, saveLocationFilePath, _telerikManagerObj.Desktop);
                    //raise download dialog
                    downloadLink.Click(true);
                    try
                    {
                        downloadDialogsHandler.WaitUntilHandled(GlobalConst.Win32DialogTimeout);
                        _telerikManagerObj.DialogMonitor.Stop();
                    }
                                                                   ...
    Thanks,

  24. Mario
    Admin
    Mario avatar
    8 posts

    Posted 24 Jan 2013 Link to this post

    Hi Aliluyko,

    I apologize for the delay in getting back to you on this.

    Looking at your images, these IE dialog's appear to be nearly identical with one main difference. From what I can tell, the file being downloaded in the 'ExportIssue.png' dialog has a longer name which distorts the button locations slightly. However this does not affect the dialog handler, using the same code as before on a downloadable file with a long enough name to widen the download dialog still works as expected for me.

    Kind regards,
    Mario
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  25. Raj
    Raj avatar
    1 posts
    Member since:
    Jun 2014

    Posted 30 Jun 2014 Link to this post

    Hi Mario,

    How do I handle the dialog box in IE 11? I tried all the above methods but none of them seem to work with download dialogs in IE 11. Any suggestions?
  26. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 02 Jul 2014 Link to this post

    Hi Raj,

    First I must ask what version of Test Studio, or our framework do you currently have installed? We used to not have support for IE 11, but did add it about a year ago. I just need to verify you are using a version that is compatible with IE 11.

    Regards,
    Cody
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  27. Ganga
    Ganga avatar
    37 posts
    Member since:
    Nov 2010

    Posted 07 Jul 2014 in reply to Cody Link to this post

    Hi Cody,

    I can able to give some information based on your question.

    I am using latest TestingFramework_2014_2_618 and my tests run on IE 10 & IE 11 as well as Chrome. The download test always successful on Chrome, but IE 10 & IE 11 failed 90% of the time.

    The download handler able interact with Save as dialog and save the file successfully all the time in IE 10 & IE 11, but toolbar is failed closes after file saved.  I was playing with my code, but still no luck. I was able to run the below mention code in IE 10 & 11 10% of the time.

    Please note this, all my test are executing successfully,  if I comment it out // dlgHandler.WaitUntilHandled(18000000);.  What is happening, file saved successfully and rest of the steps executed successfully all the time in IE 10 or IE 11. 

    I tested with Windows 7, 8 & 2012....


    My Code:
    public static void InvokeDownload(Element element)
    {
           // Create the filename, save to Log folder for current run, file name to be
           // DateTime.Now.Ticks plus original file extension which will be added automatically 
           //string fileName = String.Format("Download_{0}{1}{2}", DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
           string fileName = String.Format("File_{0}{1}{2}", DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
           string logPath = Manager.Current.Settings.LogLocation;
           string filePath = System.IO.Path.Combine(logPath, fileName);

           HtmlControl control = element.As<HtmlControl>();
                
            //Create dialogs
            DownloadDialogsHandler dlgHandler = new DownloadDialogsHandler(Manager.Current.ActiveBrowser, DialogButton.SAVE,                   fileName, Manager.Current.Desktop);
                                        
            try
            {
                   //Clicking on button/link ‘Save Dialog’ will open     
                    control.Click(true);

                    //Wait until dialog is handled
                   dlgHandler.WaitUntilHandled(18000000);
                   
                   
                  // Search file path for file starting with fileName to find physical fileName
                  string[] files = System.IO.Directory.GetFiles(logPath);
                  foreach (string file in files)
                  {
                        if (System.IO.Path.GetFileName(file).StartsWith(fileName, StringComparison.OrdinalIgnoreCase))
                        {
                            fileName = file;
                            break;
                        }
                  }
                  // Log to manager
                  Manager.Current.Log.WriteLine(String.Format("File \"{0}\" downloaded.", fileName));
            }
            catch
            {
                   //Manager.Current.ActiveBrowser.Window.SetFocus(); 
                    WriteLog(element, "handling dialog");
             }
             finally{}          
    }
     



  28. Ganga
    Ganga avatar
    37 posts
    Member since:
    Nov 2010

    Posted 07 Jul 2014 Link to this post

    Hi Cody,

    I forget to attached image... Please see the attached image....

    Cheers
    Ganga S
  29. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 10 Jul 2014 Link to this post

    Hi Ganga,

    First I can confirm that TestingFramework_2014_2_618 includes support for IE 10 & 11.

    I was able to run the below mention code in IE 10 & 11 10% of the time.

    Maybe the browser is not configured right. Make sure that "Notify me when my downloads are complete." is checked as documented near the bottom of this page.

    Regards,
    Cody
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  30. Ganga
    Ganga avatar
    37 posts
    Member since:
    Nov 2010

    Posted 13 Jul 2014 in reply to Cody Link to this post

    Hi Cody,

    Thanks for the confirmation. 

    My IE web browser configured according the documentation.

    Cheers
    Ganga S
Back to Top