Handling FileDownload Dialogs

Telerik Testing Framework includes a number of classes that make handling of the file download dialogs very easy:

  • SaveAsDialog - Handles both the IE and FireFox "Save As" dialogs.
  • IEDownloadDialog - Handles IE's "Run/Save/Cancel" dialog.
  • IEDownloadComplete - Handles IE's "Download Complete" dialog.
  • FFOpenDownloadDialog - Handles Firefox's "Opening" and "Download Complete" dialogs.
  • DownloadDialogsHandler - Integrates all of the above dialogs into one easy to use compilation class.

 

Here is a set of screenshots showing all the dialogs that the above dialog handler classes handle:

 

 

 

Figure 1. IE Download Dialog

 

 

Figure 2. IE Download Complete Dialog

 

 

Figure 3. Firefox Open Download Dialog

 

 

Figure 4. Firefox Download Complete Dialog

 

 

Using the first four classes works the same way as using the Logon dialog handler. The only difference is the parameters supplied to the constructors:

 

C#

// Add a SaveAsDialog handler to the dialog manager
SaveAsDialog saveas = new SaveAsDialog(ActiveBrowser, DialogButton.SAVE, "webaii.msi", Desktop);
Manager.DialogMonitor.AddDialog(saveas);
  
// Add an IEDownloadDialog handler to the dialog manager
IEDownloadDialog ieDownload = new IEDownloadDialog(ActiveBrowser, DialogButton.SAVE, Desktop);
Manager.DialogMonitor.AddDialog(ieDownload);
  
// Add an IEDownloadCompleteDialog handler to the dialog manager
IEDownloadCompleteDialog ieDownloadComplete = new IEDownloadCompleteDialog(ActiveBrowser, DialogButton.SAVE, Desktop);
Manager.DialogMonitor.AddDialog(ieDownloadComplete);
  
// Add a FFOpenDownloadDialog handler to the dialog manager
FFOpenDownloadDialog ffDownloads = new FFOpenDownloadDialog(ActiveBrowser, DialogButton.SAVE, Desktop);
Manager.DialogMonitor.AddDialog(ieDownloadComplete);

 

Visual Basic

' Add a SaveAsDialog handler to the dialog manager
Dim saveas As SaveAsDialog = New SaveAsDialog(ActiveBrowser, DialogButton.SAVE, "webaii.msi", Desktop)
Manager.DialogMonitor.AddDialog(saveas)
  
' Add an IEDownloadDialog handler to the dialog manager
Dim ieDownload As IEDownloadDialog = New IEDownloadDialog(ActiveBrowser, DialogButton.SAVE, Desktop)
Manager.DialogMonitor.AddDialog(ieDownload)
  
' Add an IEDownloadCompleteDialog handler to the dialog manager
Dim ieDownloadComplete As IEDownloadCompleteDialog = New IEDownloadCompleteDialog(ActiveBrowser, DialogButton.SAVE, Desktop)
Manager.DialogMonitor.AddDialog(ieDownloadComplete)
  
' Add a FFOpenDownloadDialog handler to the dialog manager
Dim ffDownloads As FFOpenDownloadDialog = New FFOpenDownloadDialog(ActiveBrowser, DialogButton.SAVE, Desktop)
Manager.DialogMonitor.AddDialog(ieDownloadComplete)

 

The easiest to use and the most complete dialog handler class is the DownloadDialogsHandler. It wraps all of the individual download dialog handlers into one fully integrated class. If you use this class do not use the other four as they will conflict with each other.

  

C#

[TestMethod]
[Description("Handling Download Dialogs")]
public void DownloadDialogs()
{
    /// Note:
    /// Given that the download is usually a sequence of dialogs,
    /// the download sequence is wrapped using the DownloadDialogHandler.
    /// The DownloadDialogHandler supports Cancel or Save operations to a location on disk.
    /// If you want more control over each dialog, the dialogs are available
    /// under the Win32.Dialogs namespace
    ///
    /// Also the DialogHandler manages its own instance of the DialogMonitor so it won't affect your own
    /// Manager.DialogMonitor instance of your class.
  
    ///
    /// Option I - Using the generic handler.
    ///
    Element e = Find.ByTagIndex("a", 0);
  
    string saveLocation = System.IO.Path.Combine(Globals.PATH_TO_PAGES, "foo.exe");
    DownloadDialogsHandler handler = new DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, saveLocation, Desktop);
  
    Actions.Click(e);
    handler.WaitUntilHandled(20000);
  
    ///
    /// Option II - Using the built in support in HtmlControls
    ///
    Find.ByTagIndex<HtmlAnchor>("a", 0).Download(false, DownloadOption.Save, saveLocation, 20000);
 }

 

Visual Basic

 ' File Download
 <TestMethod(), _
 Description("Handling Download Dialogs")> _
 Public Sub DownloadDialogs()
   
    ' Note: 
    ' Given that the download is usually a sequence of dialogs,
    ' the download sequence is wrapped using the DownloadDialogHandler.
    ' The DownloadDialogHandler supports Cancel or Save operations to a location on disk.
    ' If you want more control over each dialog, the dialogs are available 
    ' under the Win32.Dialogs namespace
    
    ' Also the DialogHandler managers its own instance of the DialogMonitor so it won't affect your own
    ' Manager.DialogMonitor instance of your class.
   
    '
    ' Option I - Using the generic handler.
    '
    Dim e As Element = Find.ByTagIndex("a", 0)
  
    Dim saveLocation As String = System.IO.Path.Combine(Globals.PATH_TO_PAGES, "foo.exe")
    Dim handler As DownloadDialogsHandler = New DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, saveLocation, Desktop)
  
    Actions.Click(e)
    handler.WaitUntilHandled(20000)
  
    '
    ' Option II - Using the built in support in HtmlControls
    '
    Find.ByTagIndex(Of HtmlAnchor)("a", 0).Download(False, DownloadOption.Save, saveLocation, 20000)
  
End Sub