diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/driver/ExtendedJTreeDriver.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/driver/ExtendedJTreeDriver.kt index 487d2ed5de75..a7bbc55ea778 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/driver/ExtendedJTreeDriver.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/driver/ExtendedJTreeDriver.kt @@ -55,20 +55,36 @@ open class ExtendedJTreeDriver(robot: Robot) : JTreeDriver(robot) { private val pathFinder = ExtendedJTreePathFinder() private val location = JTreeLocation() + private val DEFAULT_FIND_PATH_ATTEMPTS: Int = 3 fun clickPath(tree: JTree, pathStrings: List, mouseClickInfo: MouseClickInfo) = clickPath(tree, pathStrings, mouseClickInfo.button(), mouseClickInfo.times()) - fun clickPath(tree: JTree, pathStrings: List, button: MouseButton = MouseButton.LEFT_BUTTON, times: Int = 1) { + + fun clickPath(tree: JTree, pathStrings: List, button: MouseButton = MouseButton.LEFT_BUTTON, times: Int = 1, attempts: Int = DEFAULT_FIND_PATH_ATTEMPTS) { val point = scrollToPath(tree, pathStrings) robot.click(tree, point, button, times) + //check that path is selected or click it again + if (!checkPathIsSelected(tree, pathStrings)) { + if (attempts == 0) throw Exception("Unable to click path in $DEFAULT_FIND_PATH_ATTEMPTS attempts due to it high mutability. Maybe this path is loading async.") + clickPath(tree, pathStrings, button, times, attempts - 1) + } } //XPath contains order number of similar nodes: clickXPath("test(1)", "Java") - here (1) means the first node - fun clickXPath(tree: JTree, xPathStrings: List, button: MouseButton = MouseButton.LEFT_BUTTON, times: Int = 1) { + fun clickXPath(tree: JTree, + xPathStrings: List, + button: MouseButton = MouseButton.LEFT_BUTTON, + times: Int = 1, + attempts: Int = 3) { val point = scrollToXPath(tree, xPathStrings) robot.click(tree, point, button, times) + //check that path is selected or click it again + if (!checkPathIsSelected(tree, xPathStrings, false)) { + if (attempts == 0) throw Exception("Unable to click path in $DEFAULT_FIND_PATH_ATTEMPTS attempts due to it high mutability. Maybe this path is loading async.") + clickXPath(tree, xPathStrings, button, times, attempts - 1) + } } fun checkPathExists(tree: JTree, pathStrings: List) { @@ -87,6 +103,16 @@ open class ExtendedJTreeDriver(robot: Robot) : JTreeDriver(robot) { rightClick(tree, p) } + //works only if one item has been selected + private fun checkPathIsSelected(tree: JTree, pathStrings: List, isUniquePath: Boolean = true): Boolean { + val selectedPaths = tree.selectionPaths + if (selectedPaths.size > 1) throw Exception("More than one row has been selected") + if (selectedPaths.isEmpty()) throw Exception("No one row has been selected at all") + val selectedPath = selectedPaths.first() + val matchedPath = matchingPathFor(tree = tree, pathStrings = pathStrings, isUniquePath = isUniquePath) + return matchedPath.lastPathComponent == selectedPath.lastPathComponent + } + fun expandPath(tree: JTree, pathStrings: List) { val info = scrollToMatchingPathAndGetToggleInfo(tree, pathStrings) if (!info.first) toggleCell(tree, info.second!!, info.third) @@ -255,7 +281,7 @@ open class ExtendedJTreeDriver(robot: Robot) : JTreeDriver(robot) { try { node = traverseChildren(tree, node, pathString) ?: throw pathNotFound(pathStrings) } - catch(e: LoadingNodeException) { //if we met loading node let's tell it to caller and probably expand path to clarify this node + catch (e: LoadingNodeException) { //if we met loading node let's tell it to caller and probably expand path to clarify this node e.treePath = TreePath(newPathValues.toTypedArray()) throw e } @@ -455,7 +481,10 @@ open class ExtendedJTreeDriver(robot: Robot) : JTreeDriver(robot) { /** * we are trying to find TreePath for a tree, if we met loading node (LoadingTreeNode) */ - protected fun matchingPathFor(tree: JTree, pathStrings: List, countDownAttempts: Int = 30, isUniquePath: Boolean = true): TreePath { + protected fun matchingPathFor(tree: JTree, + pathStrings: List, + countDownAttempts: Int = 30, + isUniquePath: Boolean = true): TreePath { if (countDownAttempts == 0) throw Exception("Unable to find path($pathStrings) for tree: $tree, attempts count exceeded") try { return computeOnEdtWithTry {