3

I have a scenario to verify Print Properties dialog (Windows component) opening up correctly after clicking on Print link. Aware of Robot utility class in Java which can emulate keyboard events like Escape/Enter etc. to operate on that window.

Is there any way we can verify the new dialog opened up is a Print dialog - something to verify dialog title i.e. Print or retrieve text from that windows dialog or something else which will confirm dialog to be a Print dialog.

Print Window dialog

Sitam Jana
  • 3,123
  • 2
  • 21
  • 40
  • Propably a duplicate: http://stackoverflow.com/questions/11537103/how-to-handle-print-dialog-in-selenium – Spindizzy Feb 25 '14 at 13:11
  • 1
    @Spindizzy This question addresses other aspect of dealing with Print window dialog. Here I want something to confirm that the new window opens a print window (May be by verifying Window title or some elements from the print dialog etc.). http://stackoverflow.com/questions/11537103/how-to-handle-print-dialog-in-selenium addresses how to handle that dialog and doesn't serve my purpose! – Sitam Jana Feb 25 '14 at 13:15

2 Answers2

1

The print dialog comes from the os, which selenium can't handle (yet). Therefore you won't be able to check for existence. The only way to I can think of is using a java.awt.Robot, send VK_ESCAPE and assert that the test continues.

As a starter you could try out this:

     Runnable r = new Runnable() {

        @Override
        public void run() {

            try {
                Robot r = new Robot();
                r.delay(1000);
                r.keyPress(KeyEvent.VK_ESCAPE);
                r.keyRelease(KeyEvent.VK_ESCAPE);
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }
    };

    Actions actions = new Actions(getDriver());
    actions.sendKeys(Keys.CONTROL).sendKeys("p");

    Thread t = new Thread(r);
    t.start();

    actions.perform();

    //some stupid asserts that we reached here
Spindizzy
  • 7,244
  • 1
  • 19
  • 33
1

If you are operating in windows (which I am going to assume you are) you can use the inspect.exe tool that comes along with visual studio. It will allow you to interact with the dialogue box and even send any information that you want accurately including selecting elements from the drop down or any other interaction needed. This even works if you wish to save files using selenium, but to answer your question, you can even use it to detect if that window is indeed there. How you want to proceed from there is your call.

 //using System.Windows.Automation;
 //using System.Windows.Forms;

 AutomationElement desktop = AutomationElement.RootElement;
 AutomationElement Firefox = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "MozillaWindowClass"));
 AutomationElement PrinterComboBox = PrintForm1.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "1139"));
 SelectionPattern selectPrinterComboBox = (SelectionPattern)PrinterComboBox.GetCurrentPattern(SelectionPattern.Pattern);
 AutomationElement ItemInDropdown = PrinterComboBox.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "SelectPrintMethod"));
 SelectionItemPattern ItemInDropdownSelectItem = (SelectionItemPattern)ItemInDropdown.GetCurrentPattern(SelectionItemPattern.Pattern);
 ItemInDropdownSelectItem.Select();
 AutomationElement OKButton = PrintForm1.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "1"));
 InvokePattern ClickOK = (InvokePattern)OKButton.GetCurrentPattern(InvokePattern.Pattern);
 ClickOK.Invoke();
Ben
  • 667
  • 6
  • 13