This is a migrated thread and some comments may be shown as answers.

How to support Save Dialog

8 Answers 538 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dafna
Top achievements
Rank 1
Dafna asked on 30 Apr 2013, 06:02 AM
Hi,

My application is a WPF application.
I need to test an export of a file and save it on the computer.
How can I support the Save Dialog in order to save taht file?

Thanks
Dafna

8 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 30 Apr 2013, 01:02 PM
Hello Dafna,

Here's a sample code you can use to handle the Save File dialog:
SaveAsDialog saveDlg = SaveAsDialog.CreateSaveAsDialog(Manager.ActiveApplication, DialogButton.SAVE, @"c:\test");
Manager.DialogMonitor.AddDialog(saveDlg);
Manager.DialogMonitor.Start();
 
//Enter the code that triggers the dialog here...
 
saveDlg.WaitUntilHandled(30000);
Manager.DialogMonitor.Stop();

See this short video demonstrating the execution of the code above against a sample WPF application that I just created. Please give it a try and let me know if you need further assistance on this. 

Kind regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Valentijn
Top achievements
Rank 1
answered on 29 Oct 2013, 03:53 PM
I have a couple of remarks and questions on this one for Silverlight. First of all I haven't found any documentation that explains or gives an example on how to use the CreateSaveAsDialog method except from the API reference, which I find very unsufficient. Is there any place else this is described? Is there a best practice on how to use it?

I haven't been able to get this feature to work stable on any browser yet. In IE8 it even seems to work about 20% of the times I tried it. It seems like a very buggy feature.

Then if you look at the contextual help you provide with the method, visual studio lists the second parameter as the 'dismissButton' and states that the possible options are OPEN and CANCEL. Clearly everbody in their right minds would need a SAVE dialogbutton here...

            var dialog = SaveAsDialog.CreateSaveAsDialog(Manager.ActiveBrowser, DialogButton.SAVE, fileName, Manager.Desktop);

I don't see any option on how to get more information on getting this fixed. The dialog appears sometimes (in Chrome always) and the filename does not get filled in, finally the WaitUntilHandled call times out. And without any explanation at all to why this happens. Jeez...


            var dialog = SaveAsDialog.CreateSaveAsDialog(Manager.ActiveBrowser, DialogButton.SAVE, fileName, Manager.Desktop);
            Manager.DialogMonitor.AddDialog(dialog);
            Manager.DialogMonitor.Start();
    toolbarItemButton.User.Click(typeOfMouseClick);
    if (ReferenceEquals(dialog, null)) return;
            dialog.WaitUntilHandled(5000);

Sorry for my tone, but this has been frustrating!
0
Velin Koychev
Telerik team
answered on 01 Nov 2013, 04:10 PM
Hello Valentijn,

Thank you for your feedback. I was able to reproduce the issue you are describing against our demo website. I filed  a bug report  on this problem with your feedback, which you can follow in our Feedback Portal. I am sorry for any inconvenience it has probably caused and I have also updated your Telerik Points to your account for having been first to report it. I am sure that our developers will be able to fix this problem quickly. The only workaround I can currently find is to record this step with Test Studio.

You can find more information and code samples how to handle dialogs in this article
We also appreciate feedback on where our documentation is lacking or needs improvement so we can make the needed corrections and additions. 

Thank you for your understanding. 

Regards,
Velin Koychev
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Graham
Top achievements
Rank 1
answered on 06 Nov 2013, 11:19 AM
This has also been broken in the latest version of TestStudio. I've just upgraded from 2012.2.1220.0  to  2013.1.911.0 and the following code, that was previously working fine, now no longer functions -

SaveAsDialog dialog = SaveAsDialog.CreateSaveAsDialog(manager.ActiveBrowser, DialogButton.SAVE, filePath, manager.Desktop);
manager.DialogMonitor.AddDialog(dialog);
 
pages.RedBoxRecorderID1.FrameQMFramePlugin.SilverlightApp.SaveRadbutton.User.Click();
dialog.WaitUntilHandled(20000);
manager.DialogMonitor.RemoveDialog(dialog);

Previously the value of filePath was inserted into the dialog which then closed. Now this doesn't happen and the dialog sits there - it doesn't even time out.
0
Velin Koychev
Telerik team
answered on 11 Nov 2013, 09:10 AM
Hi Graham,

Thank you for reporting this problem. I can see from the code that you have sent us that this is the same problem that Valentijn reported which you can follow in our Feedback Portal.

Did you try to record the same step using Test Studio or manually add a handle download dialog step? The recorded step should resolve this problem.  

Let  me know if this helps.

Regards,
Velin Koychev
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Naveen
Top achievements
Rank 1
answered on 19 Feb 2020, 05:45 PM

Its broken again in latest build 2019.3.1412.0. Here is my code snippet

public ActionOutput RegisterDownloadDialog(RegisterDownloadDialogAction action)
        {
            var downloadPath = Path.Combine(AutomationContext.Current.TestRunSettings.StorageLocation, "TestRuns", AutomationContext.Current.TestRun.TestRunId.ToString(), "Downloads");

            if (!Directory.Exists(downloadPath))
            {
                Directory.CreateDirectory(downloadPath);
            }

            var targetFile = Path.Combine(downloadPath, action.FileName);

            if (File.Exists(targetFile))
            {
                File.Delete(targetFile);
            }

            if (AutomationContext.Current.Manager.ActiveBrowser.Manager != AutomationContext.Current.Manager)
            {
                throw new Exception("do not match");
            }

            AutomationContext.Current.Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
            var dialog = SaveAsDialog.CreateSaveAsDialog(AutomationContext.Current.Manager.ActiveBrowser, DialogButton.SAVE, targetFile, AutomationContext.Current.Manager.Desktop); 
            //var dialog = new DownloadDialogsHandler(AutomationContext.Current.Manager.ActiveBrowser, DialogButton.SAVE, targetFile, AutomationContext.Current.Manager.Desktop);          

            AutomationContext.Current.RegisterDialog(action.DialogName, dialog);

            return ActionOutput.Empty;
        }

0
Naveen
Top achievements
Rank 1
answered on 19 Feb 2020, 05:48 PM
I tried both ways: using SaveAsDialog() and also using DownloadDialogsHandler(). Both methods are not working in IE. Its working fine in chrome and other browsers
0
Plamen Mitrev
Telerik team
answered on 24 Feb 2020, 09:47 AM

Hello Naveen,

I am sorry to hear that the dialog handling is not working as expected.

Based on the provided code snippet, I see that you have defined the download dialog correctly with the DownloadDialogsHandler(). In addition to that, you need to start the DialogMonitor, which should the register the dialogs that appear on the page. I am not sure if this happens somewhere else in your code and how it is structured, but I have a sample code that might help you.

The DownloadDialogHandler should be initialized and the DialogMonitor should be started, before you call the Click action. Otherwise the dialog will not be added in list of dialogs in time and that will cause a failure. Please adjust the sample code to match your test scenario and try it again.

In case the issue persists, please share a sample project, against a publicly accessible application, that I can run and troubleshoot. I will try to help you find the best approach to handle such dialogs.

Thank you for your cooperation.

Regards,
Plamen Mitrev
Progress Telerik

 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Dafna
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Valentijn
Top achievements
Rank 1
Velin Koychev
Telerik team
Graham
Top achievements
Rank 1
Naveen
Top achievements
Rank 1
Plamen Mitrev
Telerik team
Share this question
or