How do I mark a GenericDialog as Handled?

8 posts, 1 answers
  1. aplicaciones
    aplicaciones avatar
    34 posts
    Member since:
    Apr 2017

    Posted 22 Mar Link to this post

    Hello,

    Maybe this is a newbie question but I am not able to achieve what I want.

    I have created a custom Dialog inheriting from GenericDialog.
    I have overridden the Handle method and I am doing what I want to achieve with it but ( there is always a but) I am not able to mark or tell the consumer code that the handle has finished.

    Here is my code:

    My custom Class:
     public class PrintDialog : GenericDialog
        {

         ....

    public override void Handle()
            {
                if (this.HandlerDelegate != null)
                {
                    this.HandlerDelegate(this);
                }
                else
                {
                    try
                    {
                        System.Threading.Thread.Sleep(100);

                        InvokePrint.Invoke();

                        System.Threading.Thread.Sleep(100);

                        Window currentWindow = WindowManager.FindWindowRecursively(IntPtr.Zero, "Save Print Output As", false, 1500);
                        if (currentWindow != null)
                        {
                            currentWindow.SetFocus();
                            currentWindow.SetActive();

                            ArtOfTest.WebAii.Win32.Button saveButton = new ArtOfTest.WebAii.Win32.Button(currentWindow.Handle, ButtonAutomationId);

                            foreach (Window child in currentWindow.AllChildren)
                            {
                                if (child.ContainsControl(FileNameAutomationId))//FileNameText
                                {
                                    child.SetFocus();
                                    child.SetActive();
                                    SetFileName.Invoke();

                                    System.Threading.Thread.Sleep(500);
                                }
                            }

                            if (saveButton != null)
                            {
                                System.Threading.Thread.Sleep(500);

                                //ActionToPerform.Invoke();
                                saveButton.SetFocus();
                                saveButton.SetActive();
                                saveButton.Click();
                                InvokePrint.Invoke();
                            }

                            System.Threading.Thread.Sleep(5000);

                            InvokePrint.Invoke();
                        }

                        this.HandleCount = 0;

                        this.Window.Close();

                        // Make sure the dialog is knocked down.
                        this.Window.WaitForVisibility(false, 500);
                    }
                    catch (Exception ex)
                    {
                        // Do any custom handling and return error.
                        throw;
                    }
                }

    }
    The Consumer Method which is in another class:
    private void PrintTax()
            {
                try
                {
                    PrintDialog printDialog = new PrintDialog(ActiveBrowser, PrintDialogText, false, PrintDialogText);  // Click on the Print button

                    printDialog.InvokePrint = InvokePrint;
                    printDialog.SetFileName = EnviarPath;
                    

                    Manager.DialogMonitor.AddDialog(printDialog);

                    Manager.DialogMonitor.Start();

                    //Click the link that launches the security dialog
                    ImprimirTasaButton();

                    printDialog.WaitUntilHandled(20000);

                    Manager.DialogMonitor.Stop();
                }
                catch (Exception ex)
                {

                    //TODO: Log this exception
                    throw;
                }

            }

    Note: This code is still a Work in progress but I am getting a timeout exception as it seems as it has been never handled even though I have done all I wanted to do.

    I hope you could help me with this.
  2. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 27 Mar Link to this post

    Hi,

    The way the dialog is created in the method PrintTax() indicates that the dialog will be located by the exact title and text content which will be the same. Is this the case you have there?

    I suggest trying to use only the title and to enable partial title content:
    PrintDialog printDialog = new PrintDialog(ActiveBrowser, PrintDialogText, true, string.Empty);

    The other recommended approach to the problem is to follow the directions in those articles on how to create custom dialogs and dialog handlers

    I hope these directions help.

    Best Regards,
    Nikolay Petrov
    Progress Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  3. aplicaciones
    aplicaciones avatar
    34 posts
    Member since:
    Apr 2017

    Posted 28 Mar in reply to Nikolay Petrov Link to this post

    Hello,

    Yes, as the title is "Print" and the button to click is "Print". Is that what you were asking?
    I have attached an Image showing the first window. Then, I am handling the second system window that appears after I click the Print button, which is a "Save Dialog Window"

    But as I mentioned it doesn't seem that the Dialog is handled for the code that calls it.
  4. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 02 Apr Link to this post

    Hello,

    Thank you for the screenshot provided.

    Unfortunately, such browser print dialog cannot be handled directly using the dialog handlers available in the testing framework. I suggest here to use desktop actions like key combinations ("Ctrl" + "P" or "Enter" key press) or blind desktop click to handle the dialog.

    The following line can be used for a blind desktop Left click if X and Y coordinates are introduiced:
    Manager.Desktop.Mouse.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, x_coordinate, y_coordinate);

    I hope that helps.

    Best Regards,
    Nikolay Petrov
    Progress Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  5. aplicaciones
    aplicaciones avatar
    34 posts
    Member since:
    Apr 2017

    Posted 03 Apr in reply to Nikolay Petrov Link to this post

    Hello,

    Yes, I have followed a similar approach. 
    As you can see in my code, (I didn't include all my code in the post), I have a sentence:
    " InvokePrint.Invoke();" --> This is an Action that my class offers. And though this Action I am sending an "Enter".
    After that, I am Handling the following Dialog which is a Save Dialog Window as I am printing to a file.

    My issue is that  I am getting a "TimeoutException" as the Dialog(s) it seems not being handled for the code but it is actually doing what I want. That's showing the Print Dialog and then Saving the Pdf to a file. That job is being carried out but even though I am still getting an exception.

    I hope you can help me with this.

    Regards,
    Sebastian




  6. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    939 posts

    Posted 06 Apr Link to this post

    Hello Sebastian,

    Let me interfere into this thread as my colleague Nikolay is out of the office. 

    Please note he has mentioned in his previous reply that the Print dialog cannot be directly automated. The reason behind that is that the Print dialog is different from the Download and Save dialogs, etc. and is not being recognized as a dialog to handle. Probably this is the reason for the timeout exception you got. 

    Our recommendation is to use either blind clicks against the print dialog which could be quite tricky if you execute the test in different environments. The second option will be to use the Desktop Manager class to send keystrokes against the print dialog which will then trigger the Save dialog which I suspect could be handled successfully with Test Studio and its framework. 

    I hope the above notes will be useful to you! Thanks! 

    Regards,
    Elena Tsvetkova
    Progress Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  7. aplicaciones
    aplicaciones avatar
    34 posts
    Member since:
    Apr 2017

    Posted 11 Apr in reply to Elena Tsvetkova Link to this post

    Thanks for your reply. 

    Yes, I am doing something similar to what you have described. Honestly, I was looking to sort this out with a different approach than blind clicks or Keystrokes. 
    Thanks again for your help.
  8. Answer
    Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    939 posts

    Posted 16 Apr Link to this post

    Hi Sebastian,

    Thanks for getting back! 

    I am sorry we couldn't quite meet your expectations but the case you would like to automate is a specific one. This is what we currently have to provide as a solution. Though we will have this in mind as a possible scenario to extend Test Studio functionalities in the future. 

    Thank you once again for your understanding! 

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