use of org.fest.swing.core.ComponentFinder in project android by JetBrains.
the class GuiTests method waitUntilFound.
/**
* Waits for a single AWT or Swing {@link Component} matched by {@code matcher} under {@code root}.
*/
@NotNull
public static <T extends Component> T waitUntilFound(@NotNull Robot robot, @Nullable Container root, @NotNull GenericTypeMatcher<T> matcher) {
AtomicReference<T> reference = new AtomicReference<>();
String typeName = matcher.supportedType().getSimpleName();
Wait.seconds(10).expecting("matching " + typeName).until(() -> {
ComponentFinder finder = robot.finder();
Collection<T> allFound = root != null ? finder.findAll(root, matcher) : finder.findAll(matcher);
boolean found = allFound.size() == 1;
if (found) {
reference.set(getFirstItem(allFound));
} else if (allFound.size() > 1) {
// Only allow a single component to be found, otherwise you can get some really confusing
// test failures; the matcher should pick a specific enough instance
fail("Found more than one " + matcher.supportedType().getSimpleName() + " which matches the criteria: " + allFound);
}
return found;
});
return reference.get();
}
use of org.fest.swing.core.ComponentFinder in project android by JetBrains.
the class ChooseGradleHomeDialogFixture method requireValidationError.
@NotNull
public ChooseGradleHomeDialogFixture requireValidationError(@NotNull final String errorText) {
Wait.seconds(1).expecting(String.format("error message '%1$s' to appear", errorText)).until(() -> {
ComponentFinder finder = robot().finder();
Collection<JPanel> errorTextPanels = finder.findAll(target(), new GenericTypeMatcher<JPanel>(JPanel.class) {
@Override
protected boolean isMatching(@NotNull JPanel panel) {
// ErrorText is a private inner class
return panel.isShowing() && panel.getClass().getSimpleName().endsWith("ErrorText");
}
});
if (errorTextPanels.size() != 1) {
return false;
}
JPanel errorTextPanel = getFirstItem(errorTextPanels);
Collection<JLabel> labels = finder.findAll(errorTextPanel, JLabelMatcher.withText(Pattern.compile(".*" + errorText + ".*")));
return labels.size() == 1;
});
// The label with the error message above also has HTML formatting, which makes the check for error not 100% reliable.
// To ensure that the shown error message is what we expect, we store the message as a client property in the dialog's
// TextFieldWithBrowseButton component.
TextFieldWithBrowseButton field = robot().finder().findByType(target(), TextFieldWithBrowseButton.class);
Object actual = field.getClientProperty(VALIDATION_MESSAGE_CLIENT_PROPERTY);
assertEquals("Error message", errorText, actual);
return this;
}
use of org.fest.swing.core.ComponentFinder in project intellij-community by JetBrains.
the class RunConfigurationComboBoxFixture method find.
@NotNull
static RunConfigurationComboBoxFixture find(@NotNull final IdeFrameFixture parent) {
ComponentFinder finder = parent.robot().finder();
ActionToolbarImpl toolbar = finder.find(parent.target(), new GenericTypeMatcher<ActionToolbarImpl>(ActionToolbarImpl.class) {
@Override
protected boolean isMatching(@NotNull ActionToolbarImpl toolbar) {
String place = field("myPlace").ofType(String.class).in(toolbar).get();
return MAIN_TOOLBAR.equals(place);
}
});
JButton button = finder.find(toolbar, new GenericTypeMatcher<JButton>(JButton.class) {
@Override
protected boolean isMatching(@NotNull JButton button) {
return button.getClass().getSimpleName().equals("ComboBoxButton");
}
});
return new RunConfigurationComboBoxFixture(parent.robot(), button);
}
Aggregations