Search in sources :

Example 1 with WaitTimedOutError

use of org.fest.swing.exception.WaitTimedOutError in project ats-framework by Axway.

the class SwingElementLocator method getContainerFixture.

/**
     * Change container by specified name or title.
     * For internal use
     * @param driver
     * @param containerProperties property with name inside
     * @return the {@link ContainerFinxture}
     */
public static ContainerFixture<?> getContainerFixture(SwingDriverInternal driver, UiElementProperties containerProperties) {
    String containerName = containerProperties.getProperty("name");
    final String containerTitle = containerProperties.getProperty("title");
    if (StringUtils.isNullOrEmpty(containerName) && StringUtils.isNullOrEmpty(containerTitle)) {
        throw new IllegalArgumentException("Illegal name/title (empty/null string) passed to search for container");
    }
    ContainerFixture<?> containerFixture = driver.getActiveContainerFixture();
    ContainerFixture<?> windowsFixture = driver.getWindowFixture();
    Robot robot = null;
    if (containerFixture != null) {
        // use the current robot instance
        robot = containerFixture.robot;
    } else {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
    }
    if (!StringUtils.isNullOrEmpty(containerName)) {
        try {
            Container cont = BasicComponentFinder.finderWithCurrentAwtHierarchy().findByName(windowsFixture.component(), containerName, Container.class);
            return new ContainerFixture<Container>(robot, cont) {
            };
        } catch (WaitTimedOutError wtoe) {
            throw new ElementNotFoundException("Unable to find container with name '" + containerName + "' under current window/dialog. If needed change current window first with swingEngineInstance.setActiveWindow()");
        }
    } else {
        try {
            Container cont = BasicComponentFinder.finderWithCurrentAwtHierarchy().find(windowsFixture.component(), new GenericTypeMatcher<Container>(Container.class, true) {

                @Override
                protected boolean isMatching(Container component) {
                    if (component instanceof Dialog) {
                        return ((Dialog) component).getTitle().equals(containerTitle);
                    } else if (component instanceof Frame) {
                        return ((Frame) component).getTitle().equals(containerTitle);
                    } else if (component instanceof JInternalFrame) {
                        return ((JInternalFrame) component).getTitle().equals(containerTitle);
                    }
                    return false;
                }
            });
            return new ContainerFixture<Container>(robot, cont) {
            };
        } catch (WaitTimedOutError wtoe) {
            throw new ElementNotFoundException("Unable to find container with title '" + containerName + "' under current window/dialog. If needed change current window first with swingEngineInstance.setActiveWindow()");
        }
    }
}
Also used : Frame(java.awt.Frame) JInternalFrame(javax.swing.JInternalFrame) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) WaitTimedOutError(org.fest.swing.exception.WaitTimedOutError) Container(java.awt.Container) Dialog(java.awt.Dialog) ContainerFixture(org.fest.swing.fixture.ContainerFixture) Robot(org.fest.swing.core.Robot) BasicRobot(org.fest.swing.core.BasicRobot) JInternalFrame(javax.swing.JInternalFrame)

Example 2 with WaitTimedOutError

use of org.fest.swing.exception.WaitTimedOutError in project ats-framework by Axway.

the class SwingElementLocator method findFixture.

public static ComponentFixture<? extends Component> findFixture(UiElement uiElement) {
    SwingDriverInternal driver = (SwingDriverInternal) uiElement.getUiDriver();
    ContainerFixture<?> containerFixture = (ContainerFixture<?>) driver.getActiveContainerFixture();
    Class<? extends Component> componentClass = componentsMap.get(uiElement.getClass());
    try {
        if (componentClass.equals(JButton.class)) {
            return (ComponentFixture<? extends Component>) new JButtonFixture(containerFixture.robot, (JButton) findElement(uiElement));
        } else if (componentClass.equals(JTextComponent.class)) {
            return (ComponentFixture<? extends Component>) new JTextComponentFixture(containerFixture.robot, (JTextComponent) findElement(uiElement));
        } else if (componentClass.equals(JMenuItem.class)) {
            if (uiElement.getElementProperty("path") != null) {
                return containerFixture.menuItemWithPath(uiElement.getElementProperty("path").split("[\\,\\/]+"));
            } else {
                return (ComponentFixture<? extends Component>) new JMenuItemFixture(containerFixture.robot, (JMenuItem) findElement(uiElement));
            }
        } else if (componentClass.equals(JPopupMenu.class)) {
            return (ComponentFixture<? extends Component>) new JPopupMenuFixture(containerFixture.robot, (JPopupMenu) findElement(uiElement));
        } else if (componentClass.equals(JTree.class)) {
            return (ComponentFixture<? extends Component>) new JTreeFixture(containerFixture.robot, (JTree) findElement(uiElement));
        } else if (componentClass.equals(JList.class)) {
            return (ComponentFixture<? extends Component>) new JListFixture(containerFixture.robot, (JList) findElement(uiElement));
        } else if (componentClass.equals(JCheckBox.class)) {
            return (ComponentFixture<? extends Component>) new JCheckBoxFixture(containerFixture.robot, (JCheckBox) findElement(uiElement));
        } else if (componentClass.equals(JToggleButton.class)) {
            return (ComponentFixture<? extends Component>) new JToggleButtonFixture(containerFixture.robot, (JToggleButton) findElement(uiElement));
        } else if (componentClass.equals(JComboBox.class)) {
            return (ComponentFixture<? extends Component>) new JComboBoxFixture(containerFixture.robot, (JComboBox) findElement(uiElement));
        } else if (componentClass.equals(JRadioButton.class)) {
            return (ComponentFixture<? extends Component>) new JRadioButtonFixture(containerFixture.robot, (JRadioButton) findElement(uiElement));
        } else if (componentClass.equals(JTable.class)) {
            return (ComponentFixture<? extends Component>) new JTableFixture(containerFixture.robot, (JTable) findElement(uiElement));
        } else if (componentClass.equals(JSpinner.class)) {
            return (ComponentFixture<? extends Component>) new JSpinnerFixture(containerFixture.robot, (JSpinner) findElement(uiElement));
        } else if (componentClass.equals(JTabbedPane.class)) {
            return (ComponentFixture<? extends Component>) new JTabbedPaneFixture(containerFixture.robot, (JTabbedPane) findElement(uiElement));
        } else if (componentClass.equals(JOptionPane.class)) {
            return (ComponentFixture<? extends Component>) containerFixture.optionPane();
        } else if (componentClass.equals(JLabel.class)) {
            return (ComponentFixture<? extends Component>) new JLabelFixture(containerFixture.robot, (JLabel) findElement(uiElement));
        } else if (componentClass.equals(Component.class)) {
            return new ComponentFixture<Component>(containerFixture.robot, findElement(uiElement)) {
            };
        } else if (componentClass.equals(JFileChooser.class)) {
            // TODO - might be searched by name too
            return containerFixture.fileChooser(Timeout.timeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()));
        } else {
            throw new ElementNotFoundException(uiElement.toString() + " not found. No such Fixture");
        }
    } catch (ComponentLookupException cle) {
        throw new ElementNotFoundException(uiElement.toString() + " not found.", cle);
    } catch (WaitTimedOutError exc) {
        // thrown for OptionPane search, wait for Window (BasicRobot.waitForWindow), AbstractJTableCellWriter, JTreeDriver.waitForChildrenToShowUp, each Pause wait
        throw new ElementNotFoundException(uiElement.toString() + " not found.", exc);
    }
}
Also used : JTreeFixture(org.fest.swing.fixture.JTreeFixture) JRadioButton(javax.swing.JRadioButton) SwingDriverInternal(com.axway.ats.uiengine.internal.driver.SwingDriverInternal) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JTextComponent(javax.swing.text.JTextComponent) JSpinnerFixture(org.fest.swing.fixture.JSpinnerFixture) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) WaitTimedOutError(org.fest.swing.exception.WaitTimedOutError) JLabelFixture(org.fest.swing.fixture.JLabelFixture) JTabbedPaneFixture(org.fest.swing.fixture.JTabbedPaneFixture) JButtonFixture(org.fest.swing.fixture.JButtonFixture) JToggleButtonFixture(org.fest.swing.fixture.JToggleButtonFixture) JComboBoxFixture(org.fest.swing.fixture.JComboBoxFixture) JTableFixture(org.fest.swing.fixture.JTableFixture) JToggleButton(javax.swing.JToggleButton) JTextComponentFixture(org.fest.swing.fixture.JTextComponentFixture) ComponentFixture(org.fest.swing.fixture.ComponentFixture) JMenuItemFixture(org.fest.swing.fixture.JMenuItemFixture) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) JMenuItem(javax.swing.JMenuItem) JTextComponentFixture(org.fest.swing.fixture.JTextComponentFixture) JRadioButtonFixture(org.fest.swing.fixture.JRadioButtonFixture) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) JOptionPane(javax.swing.JOptionPane) JPopupMenu(javax.swing.JPopupMenu) JCheckBox(javax.swing.JCheckBox) JTree(javax.swing.JTree) JPopupMenuFixture(org.fest.swing.fixture.JPopupMenuFixture) JListFixture(org.fest.swing.fixture.JListFixture) ContainerFixture(org.fest.swing.fixture.ContainerFixture) JTable(javax.swing.JTable) JSpinner(javax.swing.JSpinner) JCheckBoxFixture(org.fest.swing.fixture.JCheckBoxFixture) JList(javax.swing.JList)

Example 3 with WaitTimedOutError

use of org.fest.swing.exception.WaitTimedOutError in project ats-framework by Axway.

the class SwingElementLocator method getWindowFixture.

/**
     * Change window by specified name.
     * For internal use
     * @param driver Swing driver
     * @param windowTitle if null look for any visible window
     * @param isDialog
     * @return the {@link ContainerFinxture}
     */
public static WindowFixture<?> getWindowFixture(SwingDriverInternal driver, final String windowTitle, boolean isDialog) throws ElementNotFoundException {
    WindowFixture<?> windowFixture = driver.getWindowFixture();
    Robot robot = null;
    if (windowFixture != null) {
        // use the current robot instance
        robot = windowFixture.robot;
    } else {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
    }
    try {
        if (windowTitle != null) {
            if (isDialog) {
                windowFixture = WindowFinder.findDialog(new GenericTypeMatcher<Dialog>(Dialog.class) {

                    protected boolean isMatching(Dialog dialog) {
                        return windowTitle.equals(dialog.getTitle()) && dialog.isShowing();
                    }
                }).withTimeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()).using(robot);
            } else {
                windowFixture = WindowFinder.findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

                    protected boolean isMatching(Frame frame) {
                        return windowTitle.equals(frame.getTitle()) && frame.isShowing();
                    }
                }).withTimeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()).using(robot);
            }
        } else {
            if (isDialog) {
                windowFixture = WindowFinder.findDialog(new GenericTypeMatcher<Dialog>(Dialog.class) {

                    protected boolean isMatching(Dialog dialog) {
                        return dialog.isShowing();
                    }
                }).withTimeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()).using(robot);
            } else {
                windowFixture = WindowFinder.findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

                    protected boolean isMatching(Frame frame) {
                        if (log.isTraceEnabled()) {
                            log.trace("WindowFinder isMatching(): Title: " + frame.getTitle() + ", Frame + " + frame + ", Owner: " + frame.getOwner());
                        }
                        // owner == null - top frame. Two independent frames are both considered a top ones
                        return frame.isShowing() && frame.getOwner() == null;
                    }
                }).withTimeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()).using(robot);
            }
        }
        return windowFixture;
    } catch (WaitTimedOutError wtoe) {
        throw new ElementNotFoundException("Unable to find " + (isDialog ? "dialog" : "frame") + (windowTitle != null ? " with title '" + windowTitle + "'" : " without title specified (null passed)"), wtoe);
    }
}
Also used : Frame(java.awt.Frame) JInternalFrame(javax.swing.JInternalFrame) Dialog(java.awt.Dialog) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) WaitTimedOutError(org.fest.swing.exception.WaitTimedOutError) Robot(org.fest.swing.core.Robot) BasicRobot(org.fest.swing.core.BasicRobot) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher)

Example 4 with WaitTimedOutError

use of org.fest.swing.exception.WaitTimedOutError in project intellij-community by JetBrains.

the class GuiTestUtil method acceptAgreementIfNeeded.

private static void acceptAgreementIfNeeded(Robot robot) {
    final String policyAgreement = "Privacy Policy Agreement";
    Pair<PrivacyPolicy.Version, String> policy = PrivacyPolicy.getContent();
    boolean showPrivacyPolicyAgreement = !PrivacyPolicy.isVersionAccepted(policy.getFirst());
    if (!showPrivacyPolicyAgreement) {
        LOG.info(policyAgreement + " dialog should be skipped on this system.");
        return;
    }
    try {
        final DialogFixture privacyDialogFixture = findDialog(new GenericTypeMatcher<JDialog>(JDialog.class) {

            @Override
            protected boolean isMatching(@NotNull JDialog dialog) {
                if (dialog.getTitle() == null)
                    return false;
                return dialog.getTitle().contains(policyAgreement) && dialog.isShowing();
            }
        }).withTimeout(LONG_TIMEOUT.duration()).using(robot);
        String buttonText = "Accept";
        JButton acceptButton = privacyDialogFixture.button(new GenericTypeMatcher<JButton>(JButton.class) {

            @Override
            protected boolean isMatching(@NotNull JButton button) {
                if (button.getText() == null)
                    return false;
                return button.getText().equals(buttonText);
            }
        }).target();
        //we clicking this button to avoid NPE org.fest.util.Preconditions.checkNotNull(Preconditions.java:71)
        execute(new GuiTask() {

            @Override
            protected void executeInEDT() throws Throwable {
                EdtInvocationManager.getInstance().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        acceptButton.doClick();
                    }
                });
            }
        });
    } catch (WaitTimedOutError we) {
        LOG.warn("Timed out waiting for \"" + policyAgreement + "\" JDialog. Continue...");
    }
}
Also used : WaitTimedOutError(org.fest.swing.exception.WaitTimedOutError) NotNull(org.jetbrains.annotations.NotNull) Assert.assertNotNull(org.junit.Assert.assertNotNull) GuiTask(org.fest.swing.edt.GuiTask)

Example 5 with WaitTimedOutError

use of org.fest.swing.exception.WaitTimedOutError in project android by JetBrains.

the class NlPropertyInspectorFixture method findPropertyComponent.

@Nullable
private Component findPropertyComponent(@NotNull String name, @Nullable Icon icon) {
    try {
        JBLabel label = waitUntilFound(robot(), myPanel, new GenericTypeMatcher<JBLabel>(JBLabel.class) {

            @Override
            protected boolean isMatching(@NotNull JBLabel label) {
                return name.equals(label.getText()) && label.getIcon() == icon;
            }
        });
        Container parent = label.getParent();
        Component[] components = parent.getComponents();
        for (int i = 0; i < components.length; i++) {
            if (label == components[i]) {
                return components[i + 1];
            }
        }
        return null;
    } catch (WaitTimedOutError ex) {
        return null;
    }
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) WaitTimedOutError(org.fest.swing.exception.WaitTimedOutError) Nullable(com.android.annotations.Nullable)

Aggregations

WaitTimedOutError (org.fest.swing.exception.WaitTimedOutError)5 ElementNotFoundException (com.axway.ats.uiengine.exceptions.ElementNotFoundException)3 Dialog (java.awt.Dialog)2 Frame (java.awt.Frame)2 JInternalFrame (javax.swing.JInternalFrame)2 BasicRobot (org.fest.swing.core.BasicRobot)2 Robot (org.fest.swing.core.Robot)2 ContainerFixture (org.fest.swing.fixture.ContainerFixture)2 Nullable (com.android.annotations.Nullable)1 SwingDriverInternal (com.axway.ats.uiengine.internal.driver.SwingDriverInternal)1 JBLabel (com.intellij.ui.components.JBLabel)1 Component (java.awt.Component)1 Container (java.awt.Container)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JList (javax.swing.JList)1 JMenuItem (javax.swing.JMenuItem)1 JOptionPane (javax.swing.JOptionPane)1