mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[gui-test] add clickPathByNode for JTree
This commit is contained in:
+61
-13
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.testGuiFramework.fixtures.extended
|
||||
|
||||
import com.intellij.openapi.application.runInEdt
|
||||
import com.intellij.testGuiFramework.cellReader.ExtendedJTreeCellReader
|
||||
import com.intellij.testGuiFramework.cellReader.ProjectTreeCellReader
|
||||
import com.intellij.testGuiFramework.cellReader.SettingsTreeCellReader
|
||||
@@ -25,8 +26,10 @@ import org.fest.swing.core.MouseClickInfo
|
||||
import org.fest.swing.core.Robot
|
||||
import org.fest.swing.exception.LocationUnavailableException
|
||||
import org.fest.swing.fixture.JTreeFixture
|
||||
import org.fest.swing.timing.Pause
|
||||
import java.util.*
|
||||
import javax.swing.JTree
|
||||
import javax.swing.tree.DefaultMutableTreeNode
|
||||
import javax.swing.tree.TreePath
|
||||
|
||||
open class ExtendedTreeFixture(val robot: Robot, val tree: JTree) : JTreeFixture(robot, tree) {
|
||||
@@ -39,7 +42,7 @@ open class ExtendedTreeFixture(val robot: Robot, val tree: JTree) : JTreeFixture
|
||||
myCellReader = defineCellReader()
|
||||
}
|
||||
|
||||
fun hasXPath(vararg pathStrings: String): Boolean{
|
||||
fun hasXPath(vararg pathStrings: String): Boolean {
|
||||
return hasPath(pathStrings.toList())
|
||||
}
|
||||
|
||||
@@ -53,24 +56,25 @@ open class ExtendedTreeFixture(val robot: Robot, val tree: JTree) : JTreeFixture
|
||||
}
|
||||
}
|
||||
|
||||
fun clickPath(pathStrings: List<String>, mouseClickInfo: MouseClickInfo)
|
||||
= myDriver.clickPath(tree, pathStrings, mouseClickInfo)
|
||||
fun clickPath(pathStrings: List<String>, mouseClickInfo: MouseClickInfo) = myDriver.clickPath(tree, pathStrings, mouseClickInfo)
|
||||
|
||||
fun clickPath(vararg pathStrings: String, mouseClickInfo: MouseClickInfo)
|
||||
= myDriver.clickPath(tree, pathStrings.toList(), mouseClickInfo)
|
||||
fun clickPath(vararg pathStrings: String, mouseClickInfo: MouseClickInfo) = myDriver.clickPath(tree, pathStrings.toList(), mouseClickInfo)
|
||||
|
||||
fun clickPath(pathStrings: List<String>, button: MouseButton = MouseButton.LEFT_BUTTON, times: Int = 1)
|
||||
= myDriver.clickPath(tree, pathStrings, button, times)
|
||||
fun clickPath(pathStrings: List<String>, button: MouseButton = MouseButton.LEFT_BUTTON, times: Int = 1) = myDriver.clickPath(tree,
|
||||
pathStrings,
|
||||
button,
|
||||
times)
|
||||
|
||||
fun clickXPath(vararg xPathStrings: String)
|
||||
= myDriver.clickXPath(tree, xPathStrings.toList())
|
||||
fun clickXPath(vararg xPathStrings: String) = myDriver.clickXPath(tree, xPathStrings.toList())
|
||||
|
||||
fun clickXPath(xPathStrings: List<String>) {
|
||||
myDriver.clickXPath(tree, xPathStrings, MouseButton.LEFT_BUTTON, 1)
|
||||
}
|
||||
|
||||
fun clickPath(vararg pathStrings: String, button: MouseButton = MouseButton.LEFT_BUTTON, times: Int = 1)
|
||||
= myDriver.clickPath(tree, pathStrings.toList(), button, times)
|
||||
fun clickPath(vararg pathStrings: String, button: MouseButton = MouseButton.LEFT_BUTTON, times: Int = 1) = myDriver.clickPath(tree,
|
||||
pathStrings.toList(),
|
||||
button,
|
||||
times)
|
||||
|
||||
fun checkPathExists(pathStrings: List<String>) = myDriver.checkPathExists(tree, pathStrings)
|
||||
|
||||
@@ -140,7 +144,52 @@ open class ExtendedTreeFixture(val robot: Robot, val tree: JTree) : JTreeFixture
|
||||
return result
|
||||
}
|
||||
|
||||
private fun defineCellReader() : JTreeCellReader {
|
||||
/**
|
||||
* Find full path of the given node and click
|
||||
* Works fine for test tool window and settings
|
||||
* Works incorrect for npm/gulp.grunt tool windows
|
||||
* @param node - node full name
|
||||
*/
|
||||
fun clickPathByNode(node: String) {
|
||||
expandNodes()
|
||||
Pause.pause(1000) //Wait for EDT thread to finish expanding
|
||||
val result: MutableList<String> = mutableListOf()
|
||||
var currentNode = tree.model.root as DefaultMutableTreeNode
|
||||
val e = currentNode.preorderEnumeration()
|
||||
while (e.hasMoreElements()) {
|
||||
currentNode = e.nextElement() as DefaultMutableTreeNode
|
||||
if (currentNode.toString() == node) {
|
||||
break
|
||||
}
|
||||
}
|
||||
result.add(0, currentNode.toString())
|
||||
while (currentNode.parent != null) {
|
||||
currentNode = currentNode.parent as DefaultMutableTreeNode
|
||||
result.add(0, currentNode.toString())
|
||||
}
|
||||
//Test tool window JTree has root="[root]"
|
||||
//Settings JTree has root=""
|
||||
if (tree.model.root.toString() == "[root]") {
|
||||
result[0] = "Test Results"
|
||||
}else if (tree.model.root.toString() == ""){
|
||||
result.removeAt(0)
|
||||
}
|
||||
clickPath(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand nodes in given JTree
|
||||
* @param rowsCount - number of first rows to be expanded
|
||||
*/
|
||||
fun expandNodes(rowsCount: Int = 50) {
|
||||
runInEdt {
|
||||
for (i in 0 until rowsCount) {
|
||||
tree.expandRow(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun defineCellReader(): JTreeCellReader {
|
||||
var resultReader: JTreeCellReader
|
||||
when (tree.javaClass.name) {
|
||||
"com.intellij.openapi.options.newEditor.SettingsTreeView\$MyTree" -> resultReader = SettingsTreeCellReader()
|
||||
@@ -150,5 +199,4 @@ open class ExtendedTreeFixture(val robot: Robot, val tree: JTree) : JTreeFixture
|
||||
replaceCellReader(resultReader)
|
||||
return resultReader
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user