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