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

How do I mark a GenericDialog as Handled?

7 Answers 89 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
aplicaciones
Top achievements
Rank 1
aplicaciones asked on 22 Mar 2018, 05:40 PM

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 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);

                        (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 it has been never handled even though I have done all I wanted to do.

I hope you could help me with this.

7 Answers, 1 is accepted

Sort by
0
Nikolay Petrov
Telerik team
answered on 27 Mar 2018, 10:36 AM
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
 
0
aplicaciones
Top achievements
Rank 1
answered on 28 Mar 2018, 11:37 AM
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.
0
Nikolay Petrov
Telerik team
answered on 02 Apr 2018, 06:47 AM
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
 
0
aplicaciones
Top achievements
Rank 1
answered on 03 Apr 2018, 07:00 AM

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




0
Elena
Telerik team
answered on 06 Apr 2018, 08:20 AM
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
 
0
aplicaciones
Top achievements
Rank 1
answered on 11 Apr 2018, 07:37 AM
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.
0
Accepted
Elena
Telerik team
answered on 16 Apr 2018, 07:39 AM
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
 
Tags
General Discussions
Asked by
aplicaciones
Top achievements
Rank 1
Answers by
Nikolay Petrov
Telerik team
aplicaciones
Top achievements
Rank 1
Elena
Telerik team
Share this question
or