Save Downloaded file

37 posts, 1 answers
  1. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 15 Jul 2014 Link to this post

    Hello Ganga,

    All right. Let's find out of this problem is specific to your application or your computer. Please try running the attached test, which downloads a file from a different website. This test works 100% of the time on my computer. How well does it work on yours?

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

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

    Hi Cody,

    I test works 100% of the time on my computer with "Unexpected dialog encountered. Taking no action." error. 

    I have noticed, when I run the test on public web site, I got a different download dialog, but If I run the test on our application, I got toolbar type download. (please see the attached).

    Regards,
    Ganga S
  3. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 16 Jul 2014 Link to this post

    Hello,

    I recognize you're dealing with trying to download a PDF file. Can you try this test which also downloads a PDF from a different website.

    [TestMethod]
    public void PDFDownloadFileTest()
    {
        Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
        ActiveBrowser.NavigateTo("http://palefaceranch.org/");
     
        DownloadDialogsHandler DownloadHandler = new DownloadDialogsHandler(Manager.Current.ActiveBrowser, DialogButton.SAVE, "F:\\approvalrequest.pdf", Manager.Current.Desktop);
        Manager.DialogMonitor.Start();
     
        HtmlAnchor a = Find.ByAttributes<HtmlAnchor>("title=PRAI ACC Request for Construction Approval Form");
        a.Click();
     
        DownloadHandler.WaitUntilHandled(40000);
        Manager.Current.DialogMonitor.Stop();
    }

    If this works reliably it means the problem is specific to your application. We'll need a way of getting access to your application so we can see problem. Sometimes we can use a Fiddler trace to simulate your website to reproduce problems.

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

    Posted 20 Jul 2014 Link to this post

    Hi Cody,

    I am really appreciate your support for us to debugging the issue.

    It is working all the time with “Unexpected dialog encountered. Taking no action.” error, but my app does not work all the time.

    I can’t provide any information, due to our company security policy…

    In addition, failed to download, if a machine is “Locked” (Public or our web site).

    Regards,
    Ganga S
  5. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 21 Jul 2014 Link to this post

    Hi Ganga,

    We can safely ignore "Unexpected dialog encountered. Taking no action.".

    It is expected for the test to fail on a locked machine. There are a few work arounds, all of them a bit cumbersome to use. Basically the problem is that access to the keyboard and mouse (which is required to handle the dialog) is blocked by Windows when the machine is in a locked state. There is no "fixing" this.

    I can’t provide any information, due to our company security policy…

    That is very unfortunate. Until I can reproduce your problem on my machine, there is nothing more I can do to help you. If it helps we're willing to sign a non-disclosure agreement.

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

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

    Hi Cody,

    I am very satisfied with your support….

    I can simply accomplished file download issue with this workaround. It is working for me all the time without any failures in our CI environment.

    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();
     
                    //Wait until dialog is handled
                   //dlgHandler.WaitUntilHandled(18000000); // It is not working for our application......I can able to run my test 100% of the time, If                 commented this line
                                   
                  // 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{}         
    }
     
    Regards,
    Ganga S
  7. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 22 Jul 2014 Link to this post

    Hi Ganga,

    Excellent! I'm glad you found a working solution.

    Regards,
    Cody
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top