use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class SelectSdkDialogFixture method selectPathToSdk.
public SelectSdkDialogFixture selectPathToSdk(@NotNull File pathToSdk) {
final JTextField textField = myRobot.finder().findByType(JTextField.class);
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
textField.setText(pathToSdk.getPath());
}
});
final Tree tree = myRobot.finder().findByType(myDialog, Tree.class);
final AbstractTreeBuilder builder = AbstractTreeBuilder.getBuilderFor(tree);
pause(new Condition("Wait until path is updated") {
@Override
public boolean test() {
//noinspection ConstantConditions
return execute(new GuiQuery<Boolean>() {
@Override
protected Boolean executeInEDT() throws Throwable {
return (textField.getText().equals(pathToSdk.getPath()) && !builder.getUi().getUpdater().hasNodesToUpdate());
}
});
}
}, SHORT_TIMEOUT);
return this;
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class ToolWindowFixture method getContent.
@Nullable
protected Content getContent(@NotNull final String displayName, @NotNull Timeout timeout) {
long now = System.currentTimeMillis();
long budget = timeout.duration();
activateAndWaitUntilIsVisible(Timeout.timeout(budget));
long revisedNow = System.currentTimeMillis();
budget -= (revisedNow - now);
final Ref<Content> contentRef = new Ref<>();
pause(new Condition("finding content with display name " + displayName) {
@Override
public boolean test() {
Content[] contents = getContents();
for (Content content : contents) {
if (displayName.equals(content.getDisplayName())) {
contentRef.set(content);
return true;
}
}
return false;
}
}, Timeout.timeout(budget));
return contentRef.get();
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class ToolWindowFixture method activate.
public void activate() {
if (isActive()) {
return;
}
final Callback callback = new Callback();
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
myToolWindow.activate(callback);
}
});
pause(new Condition("Wait for ToolWindow '" + myToolWindowId + "' to be activated") {
@Override
public boolean test() {
return callback.finished;
}
}, GuiTestUtil.SHORT_TIMEOUT);
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class GuiTestUtil method waitUntilFound.
/**
* Waits for a first component which passes the given matcher under the given root to become visible.
*/
@NotNull
public static <T extends Component> T waitUntilFound(@NotNull final Robot robot, @Nullable final Container root, @NotNull final GenericTypeMatcher<T> matcher, @NotNull Timeout timeout) {
final AtomicReference<T> reference = new AtomicReference<T>();
Pause.pause(new Condition("Find component using " + matcher.toString()) {
@Override
public boolean test() {
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;
}
}, timeout);
return reference.get();
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class GuiTestUtil method findButton.
@NotNull
public static JButton findButton(@NotNull ContainerFixture<? extends Container> container, @NotNull final String text, Robot robot) {
GenericTypeMatcher<JButton> matcher = new GenericTypeMatcher<JButton>(JButton.class) {
@Override
protected boolean isMatching(@NotNull JButton button) {
String buttonText = button.getText();
if (buttonText != null) {
return buttonText.trim().equals(text) && button.isShowing();
}
return false;
}
};
Pause.pause(new Condition("Finding for a button with text \"" + text + "\"") {
@Override
public boolean test() {
Collection<JButton> buttons = robot.finder().findAll(matcher);
return !buttons.isEmpty();
}
}, SHORT_TIMEOUT);
return robot.finder().find(container.target(), matcher);
}
Aggregations