use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class GuiTestUtil method waitForIdeToStart.
// Called by IdeTestApplication via reflection.
@SuppressWarnings("UnusedDeclaration")
public static void waitForIdeToStart() {
GuiActionRunner.executeInEDT(false);
Robot robot = null;
try {
robot = BasicRobot.robotWithCurrentAwtHierarchy();
final MyProjectManagerListener listener = new MyProjectManagerListener();
//[ACCEPT IntelliJ IDEA Privacy Policy Agreement]
acceptAgreementIfNeeded(robot);
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(LONG_TIMEOUT.duration()).using(robot);
if (listener.myActive) {
Pause.pause(new Condition("Project to be opened") {
@Override
public boolean test() {
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;
}
}, LONG_TIMEOUT);
}
} finally {
GuiActionRunner.executeInEDT(true);
if (robot != null) {
robot.cleanUpWithoutDisposingWindows();
}
}
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class NewProjectWizardFixture method selectSdkPath.
public NewProjectWizardFixture selectSdkPath(@NotNull File sdkPath, String sdkType) {
final SelectSdkDialogFixture sdkDialogFixture = SelectSdkDialogFixture.find(robot(), sdkType);
sdkDialogFixture.selectPathToSdk(sdkPath).clickOk();
pause(new Condition("Waiting for the returning of focus to dialog: " + target().getTitle()) {
@Override
public boolean test() {
return target().isFocused();
}
}, GuiTestUtil.SHORT_TIMEOUT);
return this;
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class GuiTestBase method closeAllProjects.
@SuppressWarnings("UnusedDeclaration")
protected // Called by GuiTestRunner via reflection.
void closeAllProjects() {
pause(new Condition("Close all projects") {
@Override
public boolean test() {
final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
TransactionGuard.submitTransaction(ApplicationManager.getApplication(), () -> {
for (Project project : openProjects) {
assertTrue("Failed to close project " + quote(project.getName()), closeAndDispose(project));
}
});
}
});
return ProjectManager.getInstance().getOpenProjects().length == 0;
}
}, SHORT_TIMEOUT);
//noinspection ConstantConditions
boolean welcomeFrameShown = execute(new GuiQuery<Boolean>() {
@Override
protected Boolean executeInEDT() throws Throwable {
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
if (openProjects.length == 0) {
WelcomeFrame.showNow();
WindowManagerImpl windowManager = (WindowManagerImpl) WindowManager.getInstance();
windowManager.disposeRootFrame();
return true;
}
return false;
}
});
if (welcomeFrameShown) {
pause(new Condition("'Welcome' frame to show up") {
@Override
public boolean test() {
for (Frame frame : Frame.getFrames()) {
if (frame == WelcomeFrame.getInstance() && frame.isShowing()) {
return true;
}
}
return false;
}
}, SHORT_TIMEOUT);
}
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class EditorFixture method waitUntilFileIsLoaded.
/**
* An Editor could load files async, sometimes we should wait a bit when the virtual
* file for a current editor will be set.
*
* @return FileFixture for loaded virtual file
*/
@NotNull
public FileFixture waitUntilFileIsLoaded() {
Ref<VirtualFile> virtualFileReference = new Ref<>();
pause(new Condition("Wait when virtual file is created...") {
@Override
public boolean test() {
virtualFileReference.set(execute(new GuiQuery<VirtualFile>() {
@Override
protected VirtualFile executeInEDT() throws Throwable {
return getCurrentFile();
}
}));
return virtualFileReference.get() != null;
}
}, THIRTY_SEC_TIMEOUT);
return new FileFixture(myFrame.getProject(), virtualFileReference.get());
}
use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.
the class ActionLinkFixture method findByActionId.
@NotNull
public static ActionLinkFixture findByActionId(@NotNull final String actionId, @NotNull final Robot robot, @NotNull final Container container) {
final Ref<ActionLink> actionLinkRef = new Ref<ActionLink>();
pause(new Condition("Find ActionLink with ID '" + actionId + "'") {
@Override
public boolean test() {
Collection<ActionLink> found = robot.finder().findAll(container, new GenericTypeMatcher<ActionLink>(ActionLink.class) {
@Override
protected boolean isMatching(@NotNull ActionLink actionLink) {
if (actionLink.isVisible()) {
AnAction action = actionLink.getAction();
String id = ActionManager.getInstance().getId(action);
return actionId.equals(id);
}
return false;
}
});
if (found.size() == 1) {
actionLinkRef.set(getFirstItem(found));
return true;
}
return false;
}
}, SHORT_TIMEOUT);
ActionLink actionLink = actionLinkRef.get();
if (actionLink == null) {
throw new ComponentLookupException("Failed to find ActionLink with ID '" + actionId + "'");
}
return new ActionLinkFixture(robot, actionLink);
}
Aggregations