Package generic.test
Class AbstractGuiTest
java.lang.Object
generic.test.AbstractGTest
generic.test.AbstractGenericTest
generic.test.AbstractGuiTest
- Direct Known Subclasses:
AbstractDockingTest
Base class for tests that need swing support methods. Tests that don't involve Swing/Gui elements
should use AbstractGenericTest instead
-
Nested Class Summary
-
Field Summary
Fields inherited from class generic.test.AbstractGenericTest
concurrentTestExceptionRule, DEFAULT_TEST_TOOL_NAME, DEFAULT_TOOL_NAME, repeatedRule, ruleChain, TESTDATA_DIRECTORY_NAME, watchman
Fields inherited from class generic.test.AbstractGTest
BATCH_MODE, DEFAULT_WAIT_DELAY, DEFAULT_WAIT_TIMEOUT, DEFAULT_WINDOW_TIMEOUT, PARALLEL_MODE, PRIVATE_LONG_WAIT_TIMEOUT, testName
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
assertColorsEqual
(Color expected, Color actual) Asserts that the two colors have the same rgb values (handles GColor)static void
clickListRange
(JList<?> list, int row, int count) Clicks a range of items in a list (simulates holding SHIFT and selecting each item in the range in-turn)static void
clickMouse
(Component comp, int button, int x, int y, int clickCount, int modifiers) Simulates click the mouse button.static void
clickMouse
(Component comp, int button, int x, int y, int clickCount, int modifiers, boolean popupTrigger) Simulates click the mouse button.static void
clickTableCell
(JTable table, int row, int col, int clickCount) static void
clickTableRange
(JTable table, int row, int count) Clicks a range of items in a table (simulates holding SHIFT and selecting each item in the range)protected ApplicationConfiguration
static void
doubleClick
(JComponent comp, int x, int y) static void
Simulates a mouse drag actionstatic TableCellEditor
static void
executeOnSwingWithoutBlocking
(Runnable runnable) Launches the runnable on a new thread so as to not block the calling thread.static AbstractButton
findAbstractButtonByName
(Container container, String name) Searches the sub-components of the given container and returns the AbstractButton that has the specified name.static AbstractButton
findAbstractButtonByText
(Container container, String text) Searches the sub-components of the given container and returns the AbstractButton that has the specified text.static JButton
findButtonByIcon
(Container container, Icon icon) static AbstractButton
findButtonByName
(Container container, String name) Searches the sub-components of the given container and returns the AbstractButton that has the specified name.static JButton
findButtonByText
(Container container, String text) Searches the subcomponents of the the given container and returns the JButton that has the specified text.static <T extends Component>
TfindComponent
(Container parent, Class<T> desiredClass) static <T extends Component>
TfindComponent
(Container parent, Class<T> desiredClass, boolean checkOwnedWindows) static Component
findComponentByName
(Container container, String componentName) Searches the subcomponents of the indicated container and returns the component with the specified name.static Component
findComponentByName
(Container container, String componentName, boolean checkOwnedWindows) findComponents
(Container parent, Class<T> desiredClass) findComponents
(Container parent, Class<T> desiredClass, boolean checkOwnedWindows) static void
findOwnedWindows
(Window win, Set<Window> winList) protected static TreePath
findPathToText
(JTree tree, TreePath startTreePath, String text) Performs a depth first search for the named tree node.static TreePath
findTreePathToText
(JTree tree, String text) Finds the path of a tree node in the indicated tree with the specified text.static void
fixupGUI()
InvokefixupGUI
at the beginning of your JUnit test or in its setup() method to make your GUI for the JUnit test appear using the system Look and Feel.Gets all windows in the system (including Frames).static String
getRenderedTableCellValue
(JTable table, int row, int column) Gets the rendered value for the specified table cell.static <T> T
Returns the value from the givenSupplier
, invoking the call in the Swing thread.static String
getText
(JTextComponent field) static void
leftClick
(JComponent comp, int x, int y) static void
middleClick
(JComponent comp, int x, int y) static void
Fire a mouse moved event for the given component.static void
static void
pressButton
(AbstractButton button) Programmatically presses the indicated button.static void
pressButton
(AbstractButton button, boolean waitForCompletion) Programmatically presses the indicated button.static void
pressButtonByName
(Container container, String buttonName) Finds the button with the indicated NAME that is a subcomponent of the indicated container, and then programmatically presses the button.static void
pressButtonByName
(Container container, String buttonName, boolean waitForCompletion) Finds the button with the indicated NAME that is a subcomponent of the indicated container, and then programmatically presses the button.static void
pressButtonByText
(Container container, String buttonText) Finds the button with the indicated TEXT that is a sub-component of the indicated container, and then programmatically presses the button.static void
pressButtonByText
(Container container, String buttonText, boolean waitForCompletion) Finds the button with the indicated TEXT that is a sub-component of the indicated container, and then programmatically presses the button.static void
static void
Deprecated.This is not a test writer's method, but instead an infrastructure method.static void
rightClick
(JComponent comp, int x, int y) static void
Run the given code snippet on the Swing thread and wait for it to finishstatic void
static <T> T
Returns the value from the givenSupplier
, invoking the call in the Swing thread.void
Run the given code snippet on the Swing thread later, not blocking the current thread.static <E extends Exception>
voidrunSwingWithException
(ExceptionalCallback<E> callback) Call this version ofrunSwing(Runnable)
when you expect your runnable may throw exceptionsstatic <T> void
setComboBoxSelection
(JComboBox<T> comboField, T selection) static void
setText
(JTextComponent field, String text) static void
Deprecated, for removal: This API element is subject to removal in a future version.UsewaitForSwing()
insteadstatic boolean
Waits for the Swing thread to process any pending events.static void
Waits for all system tasks to complete.static void
waitForTasks
(long timeout) protected static void
Methods inherited from class generic.test.AbstractGenericTest
createApplicationLayout, createStackTraceForAllThreads, createTempDirectory, createTempFile, createTempFile, createTempFileForTest, createTempFileForTest, createTempFilePath, createTempFilePath, deleteMatchingTempFiles, deleteSimilarTempFiles, findTestDataFile, getDebugFileDirectory, getFontMetrics, getInstanceField, getInstanceFieldByClassType, getTestDataDir, getTestDataDirectory, getTestDataFile, hasTestFailed, initializeLayout, initializeSystemProperties, invokeConstructor, invokeInstanceMethod, invokeInstanceMethod, loadTextResource, loadTextResource, resetLogging, setErrorsExpected, setInstanceField, setLogLevel, setLogLevel, testFailed, toString, windowForComponent
Methods inherited from class generic.test.AbstractGTest
assertArraysEqualOrdered, assertArraysEqualUnordered, assertArraysEqualUnordered, assertContainsExactly, assertContainsExactly, assertContainsString, assertContainsStringIgnoringCase, assertListEqualOrdered, assertListEqualOrdered, assertListEqualsArrayOrdered, assertListEqualsArrayUnordered, assertListEqualUnordered, bytes, failWithException, getName, getRandomInt, getRandomInt, getRandomString, getRandomString, getTestDirectoryPath, sleep, waitFor, waitFor, waitFor, waitFor, waitFor, waitForCondition, waitForCondition, waitForCondition, waitForConditionWithoutFailing, waitForValue, waitForValueWithoutFailing
-
Constructor Details
-
AbstractGuiTest
public AbstractGuiTest()
-
-
Method Details
-
createApplicationConfiguration
- Overrides:
createApplicationConfiguration
in classAbstractGenericTest
-
getAllWindows
Gets all windows in the system (including Frames).- Returns:
- all windows
-
waitForTasks
public static void waitForTasks()Waits for all system tasks to complete. These tasks are tracked by the SystemUtilities during testing only.- Throws:
junit.framework.AssertionFailedError
- if the timeout period expires while waiting for tasks
-
waitForTasks
public static void waitForTasks(long timeout) -
waitForPostedSwingRunnables
Deprecated, for removal: This API element is subject to removal in a future version.UsewaitForSwing()
instead -
findComponent
-
findComponent
-
findComponents
-
findComponents
-
findOwnedWindows
-
pressButtonByText
Finds the button with the indicated TEXT that is a sub-component of the indicated container, and then programmatically presses the button.
The following is a sample JUnit test use:env.showTool(); OptionDialog dialog = (OptionDialog) env.waitForDialog(OptionDialog.class, 1000); assertNotNull(dialog); pressButtonByText(dialog, "OK");
- Parameters:
container
- the container to search. (Typically a dialog.)buttonText
- the text on the desired JButton.- Throws:
AssertionError
- if the button isn't found, isn't showing or isn't enabled
-
pressButtonByText
public static void pressButtonByText(Container container, String buttonText, boolean waitForCompletion) Finds the button with the indicated TEXT that is a sub-component of the indicated container, and then programmatically presses the button.- Parameters:
container
- the container to search. (Typically a dialog.)buttonText
- the text on the desired JButton.waitForCompletion
- if true wait for action to complete before returning, otherwise schedule action to be performed and return immediately.- Throws:
AssertionError
- if the button isn't found, isn't showing or isn't enabled
-
pressButtonByName
Finds the button with the indicated NAME that is a subcomponent of the indicated container, and then programmatically presses the button.- Parameters:
container
- the container to search. (Typically a dialog)buttonName
- the name on the desired AbstractButton (see Component.setName())
-
pressButtonByName
public static void pressButtonByName(Container container, String buttonName, boolean waitForCompletion) Finds the button with the indicated NAME that is a subcomponent of the indicated container, and then programmatically presses the button.- Parameters:
container
- the container to search. (Typically a dialog.)buttonName
- the name on the desired AbstractButton (see Component.setName()).waitForCompletion
- if true wait for action to complete before returning, otherwise schedule action to be performed and return immediately
-
pressButton
Programmatically presses the indicated button.- Parameters:
button
- the button
-
pressButton
Programmatically presses the indicated button.- Parameters:
button
- the buttonwaitForCompletion
- if true wait for action to complete before returning, otherwise schedule action to be performed and return immediately.
-
findComponentByName
Searches the subcomponents of the indicated container and returns the component with the specified name.- Parameters:
container
- the container to searchcomponentName
- the name of the desired component- Returns:
- the component, or null if not found
-
findComponentByName
-
findButtonByIcon
-
findButtonByText
Searches the subcomponents of the the given container and returns the JButton that has the specified text.- Parameters:
container
- the container to searchtext
- the button text- Returns:
- the JButton, or null the button was not found
-
findButtonByName
Searches the sub-components of the given container and returns the AbstractButton that has the specified name.- Parameters:
container
- container to searchname
- the button name- Returns:
- null if the button was not found
-
findAbstractButtonByText
Searches the sub-components of the given container and returns the AbstractButton that has the specified text.This differs from
findButtonByText(Container, String)
in that this method will find buttons that do not extend fromJButton
. That method is convenient when you do not wish to cast the result from AbstractButton to JButton. Other than that, this method can handle all cases the other method cannot.- Parameters:
container
- container to searchtext
- button text- Returns:
- null if the button was not found
-
findAbstractButtonByName
Searches the sub-components of the given container and returns the AbstractButton that has the specified name.- Parameters:
container
- container to searchname
- the button name (you must set this manually).- Returns:
- null if the button was not found
-
leftClick
-
middleClick
-
rightClick
-
doubleClick
-
clickMouse
public static void clickMouse(Component comp, int button, int x, int y, int clickCount, int modifiers, boolean popupTrigger) Simulates click the mouse button.- Parameters:
comp
- the component to click on.button
- the mouse button (1, 2, or 3)x
- the x coordinate of the click locationy
- the y coordinate of the click locationclickCount
- the number of clicks (2 = double click)modifiers
- additional modifiers (e.g. MouseEvent.SHIFT_MASK)popupTrigger
- a boolean, true if this event is a trigger for a popup menu
-
clickMouse
public static void clickMouse(Component comp, int button, int x, int y, int clickCount, int modifiers) Simulates click the mouse button.- Parameters:
comp
- the component to click on.button
- the mouse button (1, 2, or 3)x
- the x coordinate of the click locationy
- the y coordinate of the click locationclickCount
- the number of clicks (2 = double click)modifiers
- additional modifiers (e.g. MouseEvent.SHIFT_MASK)
-
dragMouse
public static void dragMouse(Component comp, int button, int startX, int startY, int endX, int endY, int modifiers) Simulates a mouse drag action- Parameters:
comp
- the component to drag on.button
- the mouse button (1, 2, or 3)startX
- the x coordinate of the start drag locationstartY
- the y coordinate of the start drag locationendX
- the x coordinate of the end drag locationendY
- the y coordinate of the end drag locationmodifiers
- additional modifiers (e.g. MouseEvent.SHIFT_MASK)
-
moveMouse
Fire a mouse moved event for the given component.- Parameters:
comp
- source of the event.x
- x position relative to the componenty
- y position relative to the component
-
postEvent
-
getSwing
Returns the value from the givenSupplier
, invoking the call in the Swing thread. This is useful when you may have values that are being changed on the Swing thread and you need the test thread to see the changes.- Parameters:
s
- the supplier- Returns:
- the value returned by the supplier
-
runSwing
Returns the value from the givenSupplier
, invoking the call in the Swing thread. This is useful when you may have values that are being changed on the Swing thread and you need the test thread to see the changes.- Parameters:
s
- the supplier- Returns:
- the value returned by the supplier
- See Also:
-
runSwing
Run the given code snippet on the Swing thread and wait for it to finish- Parameters:
r
- the runnable code snippet
-
runSwingLater
Run the given code snippet on the Swing thread later, not blocking the current thread. Use this if the code snippet causes a blocking operation.This is a shortcut for
runSwing(r, false);
.- Parameters:
r
- the runnable code snippet
-
runSwingWithException
public static <E extends Exception> void runSwingWithException(ExceptionalCallback<E> callback) throws Exception Call this version ofrunSwing(Runnable)
when you expect your runnable may throw exceptions- Parameters:
callback
- the runnable code snippet to call- Throws:
Exception
- any exception that is thrown on the Swing thread
-
runSwing
-
executeOnSwingWithoutBlocking
Launches the runnable on a new thread so as to not block the calling thread. This is very useful for performing actions on the Swing thread that show modal dialogs, which would otherwise block the calling thread, such as a testing thread.- Parameters:
runnable
- The runnable that will be executed in a new Thread that will place the runnable on the Swing thread.
-
clickTableCell
-
clickListRange
Clicks a range of items in a list (simulates holding SHIFT and selecting each item in the range in-turn)- Parameters:
list
- the list to select fromrow
- the initial indexcount
- the number of rows to select
-
clickTableRange
Clicks a range of items in a table (simulates holding SHIFT and selecting each item in the range)- Parameters:
table
- the table to selectrow
- the starting row indexcount
- the number of rows to select
-
editCell
-
getRenderedTableCellValue
Gets the rendered value for the specified table cell. The actual value at the cell may not be a String. This method will get the String display value, as created by the table.- Parameters:
table
- the table to queryrow
- the row to querycolumn
- the column to query- Returns:
- the String value
- Throws:
IllegalArgumentException
- if there is no renderer or the rendered component is something from which this method can get a String (such as a JLabel)
-
setComboBoxSelection
-
setText
-
getText
-
findTreePathToText
Finds the path of a tree node in the indicated tree with the specified text. The matching tree node is determined by comparing the specified text with the string returned by the tree node's toString() method.
Note: This method affects the expansion state of the tree. It will expand nodes starting at the root until a match is found or all of the tree is checked.- Parameters:
tree
- the treetext
- the tree node's text- Returns:
- the tree path
-
findPathToText
Performs a depth first search for the named tree node.- Parameters:
tree
- the tree to searchstartTreePath
- path indicating node to begin searching from in the treetext
- the name of the node to find- Returns:
- the path to the named node or null if it can't be found.
-
fixupGUI
InvokefixupGUI
at the beginning of your JUnit test or in its setup() method to make your GUI for the JUnit test appear using the system Look and Feel. The system look and feel is the default that Ghidra uses. This will also change the default fonts for the JUnit test to be the same as those in Ghidra.- Throws:
InterruptedException
- if we're interrupted while waiting for the event dispatching thread to finish excecutingdoRun.run()
InvocationTargetException
- if an exception is thrown while runningdoRun
-
assertColorsEqual
Asserts that the two colors have the same rgb values (handles GColor)- Parameters:
expected
- the expected coloractual
- the actual color
-
printMemory
public static void printMemory() -
waitForSwing
public static boolean waitForSwing()Waits for the Swing thread to process any pending events. This method also waits for anySwingUpdateManager
s that have pending events to be flushed.- Returns:
- true if the any
SwingUpdateManager
s were busy.
-
privatewaitForSwing_SwingSafe
Deprecated.This is not a test writer's method, but instead an infrastructure method.This is only for internal use. If you need to wait for the Swing thread from your test, then usewaitForSwing()
. -
yieldToSwing
protected static void yieldToSwing()
-