diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/FirstStart.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/FirstStart.kt index be05c232d6b0..62a4462fe156 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/FirstStart.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/FirstStart.kt @@ -12,7 +12,7 @@ import com.intellij.testGuiFramework.impl.FirstStart.Utils.button import com.intellij.testGuiFramework.impl.FirstStart.Utils.dialog import com.intellij.testGuiFramework.impl.FirstStart.Utils.radioButton import com.intellij.testGuiFramework.impl.FirstStart.Utils.waitFrame -import com.intellij.testGuiFramework.impl.GuiTestUtilKt.waitUntil +import com.intellij.testGuiFramework.impl.GuiTestUtilKt.silentWaitUntil import com.intellij.testGuiFramework.launcher.ide.IdeType import org.fest.swing.core.GenericTypeMatcher import org.fest.swing.core.Robot @@ -93,6 +93,8 @@ abstract class FirstStart(val ideType: IdeType) { var DEFAULT_TIMEOUT: Long = defaultTimeout } + + // In case we found WelcomeFrame we don't need to make completeInstallation. private fun completeFirstStart() { findWelcomeFrame()?.close() ?: let { completeInstallation() @@ -104,7 +106,7 @@ abstract class FirstStart(val ideType: IdeType) { } } - private val checkIsWelcomeFramePredicate: (Frame) -> Boolean = { frame -> + private val checkIsWelcomeFrame: (Frame) -> Boolean = { frame -> frame.javaClass.simpleName == "FlatWelcomeFrame" && frame.isShowing && frame.isEnabled @@ -114,15 +116,10 @@ abstract class FirstStart(val ideType: IdeType) { private fun findWelcomeFrame(seconds: Int = 5): Frame? { LOG.info("Waiting for a Welcome Frame") - return try { - waitUntil("Welcome Frame to show up", seconds) { - Frame.getFrames().any { checkIsWelcomeFramePredicate(it) } - } - Frame.getFrames().first { checkIsWelcomeFramePredicate(it) } - } - catch (e: WaitTimedOutError) { - null + silentWaitUntil("Welcome Frame to show up", seconds) { + Frame.getFrames().any { checkIsWelcomeFrame(it) } } + return Frame.getFrames().firstOrNull { checkIsWelcomeFrame(it) } } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestUtilKt.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestUtilKt.kt index 9b34904b4be4..b1ddcb027e50 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestUtilKt.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestUtilKt.kt @@ -74,7 +74,7 @@ object GuiTestUtilKt { return tree } - catch(e: Exception) { + catch (e: Exception) { throw Exception("Unable to build a tree from given data. Check indents and ") } } @@ -141,11 +141,17 @@ object GuiTestUtilKt { } fun findComponentByText(robot: Robot, container: Container, text: String): Component { - return withPauseWhenNull { robot.finder().findAll(container, ComponentMatcher { component -> - component!!.isShowing && component.isTextComponent() && component.getComponentText() == text }).firstOrNull() } + return withPauseWhenNull { + robot.finder().findAll(container, ComponentMatcher { component -> + component!!.isShowing && component.isTextComponent() && component.getComponentText() == text + }).firstOrNull() + } } - fun findBoundedComponentByText(robot: Robot, container: Container, text: String, componentType: Class): BoundedComponent { + fun findBoundedComponentByText(robot: Robot, + container: Container, + text: String, + componentType: Class): BoundedComponent { val componentWithText = findComponentByText(robot, container, text) if (componentWithText is JLabel && componentWithText.labelFor != null) { val labeledComponent = componentWithText.labelFor @@ -159,8 +165,9 @@ object GuiTestUtilKt { .sortedBy { it.bounds.x } .firstOrNull() } as BoundedComponent - } catch (e: WaitTimedOutError) { - throw ComponentLookupException("Unable to find component of type: ${componentType.simpleName} in $container by text: $text" ) + } + catch (e: WaitTimedOutError) { + throw ComponentLookupException("Unable to find component of type: ${componentType.simpleName} in $container by text: $text") } } @@ -169,7 +176,7 @@ object GuiTestUtilKt { val centerXAxis = this.bounds.height / 2 + this.locationOnScreen.y val sideCheck = if (onLeft) - textComponent.locationOnScreen.x < this.locationOnScreen.x + textComponent.locationOnScreen.x < this.locationOnScreen.x else textComponent.locationOnScreen.x > this.locationOnScreen.x return (textComponent.locationOnScreen.y <= centerXAxis) @@ -190,7 +197,7 @@ object GuiTestUtilKt { */ fun withPauseWhenNull(timeoutInSeconds: Int = 30, testWithPause: () -> ReturnType?): ReturnType { val ref = Ref() - Pause.pause(object: Condition("With pause...") { + Pause.pause(object : Condition("With pause...") { override fun test(): Boolean { val testWithPauseResult = testWithPause() if (testWithPauseResult != null) ref.set(testWithPauseResult) @@ -206,6 +213,15 @@ object GuiTestUtilKt { }, Timeout.timeout(timeoutInSeconds.toLong(), TimeUnit.SECONDS)) } + fun silentWaitUntil(condition: String, timeoutInSeconds: Int = 60, conditionalFunction: () -> Boolean) { + try { + Pause.pause(object : Condition("$timeoutInSeconds second(s) until $condition silently") { + override fun test() = conditionalFunction() + }, Timeout.timeout(timeoutInSeconds.toLong(), TimeUnit.SECONDS)) + } + catch (ignore: WaitTimedOutError) { } + } + fun findAllWithBFS(container: Container, clazz: Class): List { val result = LinkedList() val queue: Queue = LinkedList() @@ -216,7 +232,7 @@ object GuiTestUtilKt { } queue.add(container) - while(queue.isNotEmpty()) { + while (queue.isNotEmpty()) { val polled = queue.poll() check(polled) if (polled is Container) @@ -227,7 +243,10 @@ object GuiTestUtilKt { } - fun waitUntilGone(robot: Robot, timeoutInSeconds: Int = 30, root: Container? = null, matcher: GenericTypeMatcher) { + fun waitUntilGone(robot: Robot, + timeoutInSeconds: Int = 30, + root: Container? = null, + matcher: GenericTypeMatcher) { return GuiTestUtil.waitUntilGone(root, timeoutInSeconds, matcher) } @@ -235,7 +254,10 @@ object GuiTestUtilKt { waitProgressDialogUntilGone(this.robot(), dialogTitle, timeoutToAppearInSeconds, timeoutToGoneInSeconds) } - fun waitProgressDialogUntilGone(robot: Robot, progressTitle: String, timeoutToAppearInSeconds: Int = 5, timeoutToGoneInSeconds: Int = 60) { + fun waitProgressDialogUntilGone(robot: Robot, + progressTitle: String, + timeoutToAppearInSeconds: Int = 5, + timeoutToGoneInSeconds: Int = 60) { //wait dialog appearance. In a bad case we could pass dialog appearance. var dialog: JDialog? = null try { @@ -243,26 +265,28 @@ object GuiTestUtilKt { dialog = findProgressDialog(robot, progressTitle) dialog != null } - } catch (timeoutError: WaitTimedOutError) { return } + } + catch (timeoutError: WaitTimedOutError) { + return + } waitUntil("progress dialog with title $progressTitle will gone", timeoutToGoneInSeconds) { dialog == null || !dialog!!.isShowing } } fun findProgressDialog(robot: Robot, progressTitle: String): JDialog? { return robot.finder().findAll(typeMatcher(JDialog::class.java) { findAllWithBFS(it, EngravedLabel::class.java).filter { it.isShowing && it.text == progressTitle }.any() - } ).firstOrNull() + }).firstOrNull() } fun typeMatcher(componentTypeClass: Class, - matcher: (ComponentType) -> Boolean): GenericTypeMatcher { + matcher: (ComponentType) -> Boolean): GenericTypeMatcher { return object : GenericTypeMatcher(componentTypeClass) { override fun isMatching(component: ComponentType): Boolean = matcher(component) } } - fun computeOnEdt(query: () -> ReturnType): ReturnType? - = GuiActionRunner.execute(object : GuiQuery() { + fun computeOnEdt(query: () -> ReturnType): ReturnType? = GuiActionRunner.execute(object : GuiQuery() { override fun executeInEDT(): ReturnType = query() }) @@ -306,7 +330,7 @@ object GuiTestUtilKt { val errors = mutableListOf() for (errorMessage in freshErrorMessages) { val messageBuilder = StringBuilder(errorMessage.message ?: "") - val additionalInfo : String? = errorMessage.additionalInfo + val additionalInfo: String? = errorMessage.additionalInfo if (additionalInfo != null && additionalInfo.isNotEmpty()) messageBuilder.append(System.getProperty("line.separator")).append("Additional Info: ").append(additionalInfo) val error = Error(messageBuilder.toString(), errorMessage.throwable)