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();
}
}
}
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();
}
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);
}
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();
}
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);
}
}
Aggregations