[rdct-tests] improve troubleshooting logging for focus requests with no projects

(cherry picked from commit b29244d1300e2a37a1b1d70818ac6858835b0399)

IJ-CR-148486

GitOrigin-RevId: 22937d238c77f85d2f274de781253c3584daac54
This commit is contained in:
Anastasia Katsman
2024-11-04 16:27:51 +01:00
committed by intellij-monorepo-bot
parent 5cf9b397f6
commit 2d157fdb49

View File

@@ -402,7 +402,8 @@ open class DistributedTestHost(coroutineScope: CoroutineScope) {
}
private suspend fun requestFocusWithProject(projectIdeFrame: JFrame, project: Project, frameName: String, silent: Boolean): Boolean {
LOG.info("Requesting project focus for '$frameName'")
val logPrefix = "Requesting project focus for '$frameName'"
LOG.info(logPrefix)
AppIcon.getInstance().requestFocus(projectIdeFrame)
ProjectUtil.focusProjectWindow(project, stealFocusIfAppInactive = true)
@@ -411,22 +412,24 @@ open class DistributedTestHost(coroutineScope: CoroutineScope) {
projectIdeFrame.isFocusAncestor() || projectIdeFrame.isFocused
}.also {
if (!it && !silent) {
val keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager()
LOG.error("Couldn't wait for focus in project '$frameName'," +
LOG.error("$logPrefix: Couldn't wait for focus," +
"component isFocused=" + projectIdeFrame.isFocused + " isFocusAncestor=" + projectIdeFrame.isFocusAncestor() +
"\nActual focused component: " +
"\nfocusedWindow is " + keyboardFocusManager.focusedWindow +
"\nfocusOwner is " + keyboardFocusManager.focusOwner +
"\nactiveWindow is " + keyboardFocusManager.activeWindow +
"\npermanentFocusOwner is " + keyboardFocusManager.permanentFocusOwner)
"\n" + getFocusStateDescription()
)
}
else {
LOG.info("$logPrefix is successful: $it")
}
}
}
private suspend fun requestFocusNoProject(silent: Boolean): Boolean {
val logPrefix = "Request for focus (no opened project case)"
LOG.info(logPrefix)
val visibleWindows = Window.getWindows().filter { it.isShowing }
if (visibleWindows.size > 1) {
LOG.info("There are multiple windows, will focus them all. All windows: ${visibleWindows.joinToString(", ")}")
LOG.info("$logPrefix There are multiple windows, will focus them all. All windows: ${visibleWindows.joinToString(", ")}")
}
visibleWindows.forEach {
AppIcon.getInstance().requestFocus(it)
@@ -435,11 +438,25 @@ open class DistributedTestHost(coroutineScope: CoroutineScope) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().focusOwner != null
}.also {
if (!it && !silent) {
LOG.error("Couldn't wait for focus in case there is no project")
LOG.error("$logPrefix: Couldn't wait for focus" +
"\n" + getFocusStateDescription())
}
else {
LOG.info("$logPrefix is successful: $it")
}
}
}
private fun getFocusStateDescription(): String {
val keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager()
return "Actual focused component: " +
"\nfocusedWindow is " + keyboardFocusManager.focusedWindow +
"\nfocusOwner is " + keyboardFocusManager.focusOwner +
"\nactiveWindow is " + keyboardFocusManager.activeWindow +
"\npermanentFocusOwner is " + keyboardFocusManager.permanentFocusOwner
}
private fun screenshotFile(actionName: String, suffix: String, timeStamp: LocalTime): File {
val fileName = getArtifactsFileName(actionName, suffix, "png", timeStamp)