[gui-test] check that path is selected

It could be dangerous to select path in async tree when the tree path may change (has been expanded for example) during mouse moving to the previously calculated location. So we are checking that finally selected row is intended and if is not calling clickPath again while it will be selected or attempts count will exhaust.
This commit is contained in:
Sergey Karashevich
2017-09-12 16:52:35 +03:00
parent 44b50308e9
commit 64312eb0a9
@@ -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<String>, mouseClickInfo: MouseClickInfo)
= clickPath(tree, pathStrings, mouseClickInfo.button(), mouseClickInfo.times())
fun clickPath(tree: JTree, pathStrings: List<String>, button: MouseButton = MouseButton.LEFT_BUTTON, times: Int = 1) {
fun clickPath(tree: JTree, pathStrings: List<String>, 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<String>, button: MouseButton = MouseButton.LEFT_BUTTON, times: Int = 1) {
fun clickXPath(tree: JTree,
xPathStrings: List<String>,
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<String>) {
@@ -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<String>, 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<String>) {
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<String>, countDownAttempts: Int = 30, isUniquePath: Boolean = true): TreePath {
protected fun matchingPathFor(tree: JTree,
pathStrings: List<String>,
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 {