use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class ToolWindowFixture method getContent.
@Nullable
protected Content getContent(@NotNull final TextMatcher displayNameMatcher, @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 matching " + displayNameMatcher.formattedValues()) {
@Override
public boolean test() {
Content[] contents = getContents();
for (Content content : contents) {
String displayName = content.getDisplayName();
if (displayNameMatcher.isMatching(displayName)) {
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 IdeFrameFixture method find.
@NotNull
public static IdeFrameFixture find(@NotNull final Robot robot, @Nullable final File projectPath, @Nullable final String projectName) {
final GenericTypeMatcher<IdeFrameImpl> matcher = new GenericTypeMatcher<IdeFrameImpl>(IdeFrameImpl.class) {
@Override
protected boolean isMatching(@NotNull IdeFrameImpl frame) {
Project project = frame.getProject();
if (projectPath == null && project != null)
return true;
if (project != null && PathManager.getAbsolutePath(projectPath.getPath()).equals(PathManager.getAbsolutePath(project.getBasePath()))) {
return projectName == null || projectName.equals(project.getName());
}
return false;
}
};
Pause.pause(new Condition("IdeFrame " + (projectPath != null ? quote(projectPath.getPath()) : "") + " to show up") {
@Override
public boolean test() {
Collection<IdeFrameImpl> frames = robot.finder().findAll(matcher);
return !frames.isEmpty();
}
}, GuiTestUtil.LONG_TIMEOUT);
IdeFrameImpl ideFrame = robot.finder().find(matcher);
return new IdeFrameFixture(robot, ideFrame, new File(ideFrame.getProject().getBasePath()));
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class IdeFrameFixture method requireEditorNotification.
@NotNull
public EditorNotificationPanelFixture requireEditorNotification(@NotNull final String message) {
final Ref<EditorNotificationPanel> notificationPanelRef = new Ref<EditorNotificationPanel>();
pause(new Condition("Notification with message '" + message + "' shows up") {
@Override
public boolean test() {
EditorNotificationPanel notificationPanel = findNotificationPanel(message);
notificationPanelRef.set(notificationPanel);
return notificationPanel != null;
}
});
EditorNotificationPanel notificationPanel = notificationPanelRef.get();
assertNotNull(notificationPanel);
return new EditorNotificationPanelFixture(robot(), notificationPanel);
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class IdeFrameFixture method closeProject.
public void closeProject() {
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
closeAndDispose(getProject());
RecentProjectsManager.getInstance().updateLastProjectPath();
WelcomeFrame.showIfNoProjectOpened();
}
});
pause(new Condition("Waiting for 'Welcome' page to show up") {
@Override
public boolean test() {
for (Frame frame : Frame.getFrames()) {
if (frame == WelcomeFrame.getInstance() && frame.isShowing()) {
return true;
}
}
return false;
}
});
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class JBPopupFixture method invokeAction.
public void invokeAction(String... actionPath) {
boolean assertion = false;
final MenuElement[] elements = myContextMenu.getSubElements();
if (actionPath.length > 1) {
//actionGroup
for (MenuElement element : elements) {
if (element instanceof ActionMenu) {
final ActionMenu actionMenu = (ActionMenu) element;
if (actionMenu.getText().toLowerCase().contains(actionPath[0].toLowerCase())) {
final Point locationOnScreen = myContextMenu.getLocationOnScreen();
final Rectangle bounds = actionMenu.getBounds();
final Point point = new Point(locationOnScreen.x + bounds.x + bounds.width / 2, locationOnScreen.y + bounds.y + bounds.height / 2);
robot().click(point, MouseButton.LEFT_BUTTON, 1);
//invoke action for a new JBPopupMenu
final String actionName = actionPath[1];
final JBPopupFixture fixture = new JBPopupFixture(waitUntilFoundMenu(actionName), myRobot);
fixture.invokeAction(ArrayUtil.remove(actionPath, 0));
return;
}
}
}
} else {
//actionMenuItem
for (MenuElement element : elements) {
if (element instanceof ActionMenuItem) {
final ActionMenuItem actionMenuItem = (ActionMenuItem) element;
if (actionMenuItem.getText().toLowerCase().contains(actionPath[0].toLowerCase())) {
pause(new Condition("Waiting to showing JBPopupMenu on screen") {
@Override
public boolean test() {
try {
myContextMenu.getLocationOnScreen();
return true;
} catch (IllegalComponentStateException e) {
return false;
}
}
}, SHORT_TIMEOUT);
final Point locationOnScreen = myContextMenu.getLocationOnScreen();
final Rectangle bounds = actionMenuItem.getBounds();
final Point point = new Point(locationOnScreen.x + bounds.x + bounds.width / 2, locationOnScreen.y + bounds.y + bounds.height / 2);
robot().click(point, MouseButton.LEFT_BUTTON, 1);
return;
}
}
}
}
}
Aggregations