Search in sources :

Example 6 with Robot

use of org.fest.swing.core.Robot in project android by JetBrains.

the class GuiTests method waitForIdeToStart.

// Called by IdeTestApplication via reflection.
@SuppressWarnings("UnusedDeclaration")
public static void waitForIdeToStart() {
    GuiActionRunner.executeInEDT(false);
    Robot robot = null;
    try {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
        MyProjectManagerListener listener = new MyProjectManagerListener();
        findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

            @Override
            protected boolean isMatching(@NotNull Frame frame) {
                if (frame instanceof IdeFrame) {
                    if (frame instanceof IdeFrameImpl) {
                        listener.myActive = true;
                        ProjectManager.getInstance().addProjectManagerListener(listener);
                    }
                    return true;
                }
                return false;
            }
        }).withTimeout(TimeUnit.MINUTES.toMillis(2)).using(robot);
        // we attempt to clear here. All other events, including those posted by the Robot, will go through the IDE event queue.
        try {
            if (SYSTEM_EVENT_QUEUE.peekEvent() != null) {
                SYSTEM_EVENT_QUEUE.getNextEvent();
            }
        } catch (InterruptedException ex) {
        // Ignored.
        }
        if (listener.myActive) {
            Wait.seconds(1).expecting("project to be opened").until(() -> {
                boolean notified = listener.myNotified;
                if (notified) {
                    ProgressManager progressManager = ProgressManager.getInstance();
                    boolean isIdle = !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
                    if (isIdle) {
                        ProjectManager.getInstance().removeProjectManagerListener(listener);
                    }
                    return isIdle;
                }
                return false;
            });
        }
    } finally {
        GuiActionRunner.executeInEDT(true);
        if (robot != null) {
            robot.cleanUpWithoutDisposingWindows();
        }
    }
}
Also used : IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) IdeFrame(com.intellij.openapi.wm.IdeFrame) WindowFinder.findFrame(org.fest.swing.finder.WindowFinder.findFrame) ProgressManager(com.intellij.openapi.progress.ProgressManager) Robot(org.fest.swing.core.Robot) BasicRobot(org.fest.swing.core.BasicRobot) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 7 with Robot

use of org.fest.swing.core.Robot in project android by JetBrains.

the class NlComponentFixture method invokeContextMenuAction.

public void invokeContextMenuAction(String actionLabel) {
    rightClick();
    Robot robot = myRobot;
    JMenuItem found = robot.finder().find(myIdeFrame.target(), Matchers.byText(JMenuItem.class, actionLabel));
    new ComponentDriver(robot).click(found);
    robot.waitForIdle();
}
Also used : ComponentDriver(org.fest.swing.driver.ComponentDriver) Robot(org.fest.swing.core.Robot)

Example 8 with Robot

use of org.fest.swing.core.Robot in project ats-framework by Axway.

the class SwingElementLocator method useComponentInspector.

/**
     * Log the clicked element (its type, properties and index in the component hierarchy from the current container)
     *
     * @param driver {@link SwingDriverInternal} instance
     */
public static void useComponentInspector(final SwingDriverInternal driver) {
    // long eventMask = AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK;
    long eventMask = AWTEvent.MOUSE_EVENT_MASK;
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

        public void eventDispatched(AWTEvent e) {
            if (e.getID() == MouseEvent.MOUSE_PRESSED && e.getSource() instanceof Component) {
                Component component = (Component) e.getSource();
                Class<?> swingClass = findSwingClass(component.getClass());
                if (swingClass == null) {
                    swingClass = component.getClass();
                    log.warn("Can't find swing class of type \"" + swingClass.getName() + "\"");
                }
                String logEntry = "\t[INSPECTOR] " + getProperties(component).replaceFirst("\\[", " [") + " index=" + calculateIndex(component, swingClass);
                if (!component.getClass().getName().equals(swingClass.getName())) {
                    logEntry += "\t(extends " + swingClass.getName() + ")";
                }
                System.out.println(logEntry);
            }
        }

        private String getProperties(Component c) {
            String properties = Formatting.inEdtFormat(c);
            if (c instanceof JButton) {
                String tooltip = ((JButton) c).getToolTipText();
                if (!StringUtils.isNullOrEmpty(tooltip)) {
                    int lastBrIndex = properties.lastIndexOf(']');
                    if (lastBrIndex > 0) {
                        properties = properties.substring(0, lastBrIndex) + ", tooltip='" + tooltip + "'" + properties.substring(lastBrIndex);
                    } else {
                        return c.getClass().getName() + " [tooltip='" + tooltip + "']";
                    }
                }
            }
            return properties;
        }

        private Class<?> findSwingClass(Class<?> clazz) {
            if (clazz == null) {
                return null;
            }
            if (clazz.getName().startsWith("javax.swing")) {
                return clazz;
            }
            return findSwingClass(clazz.getSuperclass());
        }

        @SuppressWarnings("unchecked")
        private int calculateIndex(final Component component, Class<?> swingClass) {
            ContainerFixture<?> containerFixture = driver.getActiveContainerFixture();
            Robot robot = null;
            if (containerFixture != null) {
                // use the current robot instance
                robot = containerFixture.robot;
            } else {
                robot = BasicRobot.robotWithCurrentAwtHierarchy();
            }
            List<Component> found = SwingElementFinder.find(robot.hierarchy(), ((containerFixture != null) ? containerFixture.component() : null), new GenericTypeMatcher<Component>((Class<Component>) swingClass, true) {

                @Override
                protected boolean isMatching(Component c) {
                    return true;
                }
            });
            return found.indexOf(component);
        }
    }, eventMask);
}
Also used : AWTEventListener(java.awt.event.AWTEventListener) JButton(javax.swing.JButton) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) ContainerFixture(org.fest.swing.fixture.ContainerFixture) AWTEvent(java.awt.AWTEvent) List(java.util.List) JList(javax.swing.JList) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) Robot(org.fest.swing.core.Robot) BasicRobot(org.fest.swing.core.BasicRobot)

Example 9 with Robot

use of org.fest.swing.core.Robot in project ats-framework by Axway.

the class SwingElementLocator method getComponentHierarchy.

/**
     *
     * @param driver Swing driver
     * @return the component hierarchy as {@link String}
     */
public static String getComponentHierarchy(SwingDriverInternal driver) {
    ContainerFixture<?> containerFixture = driver.getActiveContainerFixture();
    Robot robot = null;
    if (containerFixture != null) {
        // use the current robot instance
        robot = containerFixture.robot;
    } else {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
    }
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    robot.printer().printComponents(new PrintStream(outputStream), ((containerFixture != null) ? containerFixture.component() : null));
    return outputStream.toString();
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Robot(org.fest.swing.core.Robot) BasicRobot(org.fest.swing.core.BasicRobot)

Example 10 with Robot

use of org.fest.swing.core.Robot 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)

Aggregations

Robot (org.fest.swing.core.Robot)13 BasicRobot (org.fest.swing.core.BasicRobot)7 ElementNotFoundException (com.axway.ats.uiengine.exceptions.ElementNotFoundException)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 IdeFrame (com.intellij.openapi.wm.IdeFrame)2 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)2 Dialog (java.awt.Dialog)2 Frame (java.awt.Frame)2 JInternalFrame (javax.swing.JInternalFrame)2 GenericTypeMatcher (org.fest.swing.core.GenericTypeMatcher)2 WaitTimedOutError (org.fest.swing.exception.WaitTimedOutError)2 WindowFinder.findFrame (org.fest.swing.finder.WindowFinder.findFrame)2 ContainerFixture (org.fest.swing.fixture.ContainerFixture)2 JButtonFixture (org.fest.swing.fixture.JButtonFixture)2 Condition (org.fest.swing.timing.Condition)2 AWTEvent (java.awt.AWTEvent)1 Component (java.awt.Component)1 Container (java.awt.Container)1 AWTEventListener (java.awt.event.AWTEventListener)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1