public final class TestUtils
- Object
- TestUtils
Various utility classes to automate UI testing
Methods
Inherited methods
Method details
setVerboseMode
public static void setVerboseMode(boolean v)Activates/deactivates the verbose test mode
Parameters
vboolean- true for verbosity
waitFor
public static void waitFor(int millis)Waits for the given number of milliseconds even if the waiting is on the EDT thread
Parameters
millisint- the number of milliseconds to wait
findByName
public static Component findByName(String componentName)Finds a component with the given name, works even with UI’s that weren’t created with the GUI builder
Parameters
componentNameString- the name of the component to find
Returns
the component with the given name within the tree
selectInList
public static void selectInList(String listName, int offset)Selects the given offset in a list
Parameters
listNameString- the name of the list component
offsetint- the offset to select
selectInList
public static void selectInList(int[] path, int offset)Selects the given offset in a list
Parameters
pathint[]- Not documented.
offsetint- the offset to select
findLabelText
public static Label findLabelText(String text)Finds a component with the given name, works even with UI’s that weren’t created with the GUI builder
Parameters
textString- the text of the label/button
Returns
the component with the given label text within the tree
clickButtonByLabel
public static void clickButtonByLabel(String text)Clicks the button with the given label
Parameters
textString- the text on the button
clickButtonByName
public static void clickButtonByName(String name)Clicks the button with the given label
Parameters
nameString- the name of the button
clickButtonByPath
public static void clickButtonByPath(int[] path)Clicks the button with the given component path
Parameters
pathint[]- the path
goBack
public static void goBack()Executes the back command for the current form, similarly to pressing the back button
clickMenuItem
public static void clickMenuItem(String name)Executes a menu command with the given name
Parameters
nameString- the name of the command
getToolbarCommands
public static Command[] getToolbarCommands()Returns all the command objects from the toolbar in the order of left, right, overflow & sidemenu
Returns
the set of commands
executeToolbarCommandAtOffset
public static void executeToolbarCommandAtOffset(int offset)Executes a command from the offset returned by
#getToolbarCommands()Parameters
offsetint- the offset of the command we want to execute
ensureVisible
public static void ensureVisible(Component c)Scrolls to show the component in case it is invisible currently
Parameters
cComponent- the component
ensureVisible
public static void ensureVisible(String componentName)Scrolls to show the component in case it is invisible currently
Parameters
componentNameString- the component
ensureVisible
public static void ensureVisible(int[] path)Scrolls to show the component in case it is invisible currently
Parameters
pathint[]- the path to the component
waitForFormTitle
public static void waitForFormTitle(String title, long timeout)Waits for a form change and if no form change occurred after a given timeout then fail the test
Parameters
titleString- the title of the form to wait for
timeoutlong- Timeout in ms.
waitForFormTitle
public static void waitForFormTitle(String title)Waits for a form change and if no form change occurred after a given timeout then fail the test. Timeout is 90 seconds.
Parameters
titleString- the title of the form to wait for
waitForFormName
public static void waitForFormName(String name, long timeout)Waits for a form change and if no form change occurred after a given timeout then fail the test
Parameters
nameString- the name of the form to wait for
timeoutlong- Timeout in ms
waitForFormName
public static void waitForFormName(String name)Waits for a form change and if no form change occurred after a given timeout then fail the test. Timeout is 90 seconds.
Parameters
nameString- the name of the form to wait for
waitForUnnamedForm
public static void waitForUnnamedForm(long timeout)Waits for a form change and if no form change occurred after a given timeout then fail the test
Parameters
timeoutlong- Timeout in milliseconds.
waitForUnnamedForm
public static void waitForUnnamedForm()Waits for a form change and if no form change occurred after a given timeout then fail the test
screenshotTest
public static boolean screenshotTest(String screenshotName)The screenshot test takes a screenshot of the screen and compares it to a prior screenshot, if both are 100% identical the test passes. If not the test fails.
If this is the first time the test is run then the screenshot is taken and saved under the given name in the devices storage. The test passes for this case but a warning is printed to the console. The name will have .png appended to it so it will be identified.
This test will only work on devices that support the ImageIO API with PNG file format.
Parameters
screenshotNameString- the name to use for the storage, must be unique!
Returns
true if the screenshots are identical or no prior screenshot exists
or if the test can’t be run on this device. False if a screenshot exists and
it isn’t 100% identical.
log
public static void log(String t)Log to the test log
Parameters
tString- the string to log
log
public static void log(Throwable t)Log to the test log
Parameters
tThrowable- exception to log
keyPress
public static void keyPress(int keyCode)Simulates a device key press
Parameters
keyCodeint- the keycode
keyRelease
public static void keyRelease(int keyCode)Simulates a device key release
Parameters
keyCodeint- the keycode
gameKeyPress
public static void gameKeyPress(int gameKey)Simulates a game key press
Parameters
gameKeyint- the game key (arrows etc.)
gameKeyRelease
public static void gameKeyRelease(int gameKey)Simulates a game key release
Parameters
gameKeyint- the game key (arrows etc.)
pointerPress
public static void pointerPress(float x, float y, String componentName)A component press on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place. E.g. For a 100x100 component a press within 10,5 would be 0.1f, 0.05f.
Parameters
xfloat- the offset within the component as a number between 0 and 1
yfloat- the offset within the component as a number between 0 and 1
componentNameString- the name of the component
pointerRelease
public static void pointerRelease(float x, float y, String componentName)A component release on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place. E.g. For a 100x100 component a press within 10,5 would be 0.1f, 0.05f.
Parameters
xfloat- the offset within the component as a number between 0 and 1
yfloat- the offset within the component as a number between 0 and 1
componentNameString- the name of the component
pointerDrag
public static void pointerDrag(float x, float y, String componentName)A component drag on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place. E.g. For a 100x100 component a press within 10,5 would be 0.1f, 0.05f.
Parameters
xfloat- the offset within the component as a number between 0 and 1
yfloat- the offset within the component as a number between 0 and 1
componentNameString- the name of the component
pointerPress
public static void pointerPress(float x, float y, int[] path)A component press on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place. E.g. For a 100x100 component a press within 10,5 would be 0.1f, 0.05f.
Parameters
xfloat- the offset within the component as a number between 0 and 1
yfloat- the offset within the component as a number between 0 and 1
pathint[]- the path to the component
pointerRelease
public static void pointerRelease(float x, float y, int[] path)A component release on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place. E.g. For a 100x100 component a press within 10,5 would be 0.1f, 0.05f.
Parameters
xfloat- the offset within the component as a number between 0 and 1
yfloat- the offset within the component as a number between 0 and 1
pathint[]- the path to the component
pointerDrag
public static void pointerDrag(float x, float y, int[] path)A component drag on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place. E.g. For a 100x100 component a press within 10,5 would be 0.1f, 0.05f.
Parameters
xfloat- the offset within the component as a number between 0 and 1
yfloat- the offset within the component as a number between 0 and 1
pathint[]- the path to the component
getComponentByPath
public static Component getComponentByPath(int[] path)Gets the component from the current form based on its path. A path is a
set of offsets starting from the content pane and moving inwards so a path
of { 0, 3 } would mean that the first component within the Content pane (by
index) is a Container whose 3rd component (again by index) is the component we
want.
Parameters
pathint[]- an array
Returns
a component
setText
public static void setText(String name, String text)Sets the text for the given component
Parameters
nameString- the name of the component
textString- the text to set
setText
public static void setText(int[] path, String text)Sets the text for the given component
Parameters
pathint[]- the path to the component
textString- the text to set
assertBool
public static void assertBool(boolean b)Assertions allow for simpler test code
Parameters
bboolean- must be true, otherwise an exception is thrown thus failing the test
assertBool
public static void assertBool(boolean b, String errorMessage)Assertions allow for simpler test code
Parameters
bboolean- must be true, otherwise an exception is thrown thus failing the test
errorMessageString- Not documented.
fail
public static void fail()An assertion that always fails a test.
fail
public static void fail(String errorMessage)An assertion that always fails a test.
Parameters
errorMessageString- is a string describing the failure
assertTrue
public static void assertTrue(boolean value)Asserts that the given expression evaluates to true
assertTrue
public static void assertTrue(boolean value, String errorMessage)Asserts that the given expression evaluates to true
Parameters
valueboolean- Not documented.
errorMessageString- is a string describing the failure
assertFalse
public static void assertFalse(boolean value)Asserts that the given expression evaluates to false
assertFalse
public static void assertFalse(boolean value, String errorMessage)Asserts that the given expression evaluates to false
Parameters
valueboolean- Not documented.
errorMessageString- is a string describing the failure
assertNull
public static void assertNull(Object object)Asserts that the given expression evaluates to null
assertNull
public static void assertNull(Object object, String errorMessage)Asserts that the given expression evaluates to null
Parameters
objectObject- Not documented.
errorMessageString- is a string describing the failure
assertNotNull
public static void assertNotNull(Object object)Asserts that the given expression does not evaluate to null
assertNotNull
public static void assertNotNull(Object object, String errorMessage)Asserts that the given expression does not evaluate to null
Parameters
objectObject- Not documented.
errorMessageString- is a string describing the failure
assertSame
public static void assertSame(Object expected, Object actual)Asserts that the given parameters reference the same object
assertSame
public static void assertSame(Object expected, Object actual, String errorMessage)Asserts that the given parameters reference the same object
Parameters
expectedObject- Not documented.
actualObject- Not documented.
errorMessageString- is a string describing the failure
assertNotSame
public static void assertNotSame(Object expected, Object actual)Asserts that the given parameters do not reference the same object
assertNotSame
public static void assertNotSame(Object expected, Object actual, String errorMessage)Asserts that the given parameters do not reference the same object
Parameters
expectedObject- Not documented.
actualObject- Not documented.
errorMessageString- is a string describing the failure
assertEqual
public static void assertEqual(byte expected, byte actual)Asserts that the given bytes are equal
assertEqual
public static void assertEqual(byte expected, byte actual, String errorMessage)Asserts that the given bytes are equal
Parameters
expectedbyte- Not documented.
actualbyte- Not documented.
errorMessageString- is a string describing the failure
assertEqual
public static void assertEqual(short expected, short actual)Asserts that the given shorts are equal
assertEqual
public static void assertEqual(short expected, short actual, String errorMessage)Asserts that the given shorts are equal
Parameters
expectedshort- Not documented.
actualshort- Not documented.
errorMessageString- is a string describing the failure
assertEqual
public static void assertEqual(int expected, int actual)Asserts that the given ints are equal
assertEqual
public static void assertEqual(int expected, int actual, String errorMessage)Asserts that the given ints are equal
Parameters
expectedint- Not documented.
actualint- Not documented.
errorMessageString- is a string describing the failure
assertEqual
public static void assertEqual(long expected, long actual)Asserts that the given longs are equal
assertEqual
public static void assertEqual(long expected, long actual, String errorMessage)Asserts that the given longs are equal
Parameters
expectedlong- Not documented.
actuallong- Not documented.
errorMessageString- is a string describing the failure
assertEqual
public static void assertEqual(float expected, float actual, double maxRelativeError)Asserts that the given floats are equal
Parameters
expectedfloat- Not documented.
actualfloat- Not documented.
maxRelativeErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
assertEqual
public static void assertEqual(float expected, float actual, double maxRelativeError, String errorMessage)Asserts that the given floats are equal
Parameters
expectedfloat- Not documented.
actualfloat- Not documented.
maxRelativeErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
errorMessageString- is a string describing the failure
assertEqual
public static void assertEqual(double expected, double actual, double maxRelativeError)Asserts that the given doubles are equal
Parameters
expecteddouble- Not documented.
actualdouble- Not documented.
maxRelativeErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
assertRange
public static void assertRange(double expected, double actual, double absoluteError)Asserts that the given doubles are equal
Parameters
expecteddouble- Expected value
actualdouble- Actual value
absoluteErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
assertEqual
public static void assertEqual(double expected, double actual, double maxRelativeError, String errorMessage)Asserts that the given doubles are equal
Parameters
expecteddouble- Not documented.
actualdouble- Not documented.
maxRelativeErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
errorMessageString- is a string describing the failure
assertRange
public static void assertRange(double expected, double actual, double maxAbsoluteError, String errorMessage)Asserts that the given doubles are equal
Parameters
expecteddouble- Not documented.
actualdouble- Not documented.
maxAbsoluteErrordouble- Not documented.
errorMessageString- is a string describing the failure
assertEqual
public static void assertEqual(Object expected, Object actual)Asserts that the given objects are equal using the first object’s .equal() method
assertEqual
public static void assertEqual(Object expected, Object actual, String errorMessage)Asserts that the given objects are equal using the first object’s .equal() method
Parameters
expectedObject- Not documented.
actualObject- Not documented.
errorMessageString- is a string describing the failure
assertNotEqual
public static void assertNotEqual(byte expected, byte actual)Asserts that the given bytes are not equal
assertNotEqual
public static void assertNotEqual(byte expected, byte actual, String errorMessage)Asserts that the given bytes are not equal
Parameters
expectedbyte- Not documented.
actualbyte- Not documented.
errorMessageString- is a string describing the failure
assertNotEqual
public static void assertNotEqual(short expected, short actual)Asserts that the given shorts are not equal
assertNotEqual
public static void assertNotEqual(short expected, short actual, String errorMessage)Asserts that the given shorts are not equal
Parameters
expectedshort- Not documented.
actualshort- Not documented.
errorMessageString- is a string describing the failure
assertNotEqual
public static void assertNotEqual(int expected, int actual)Asserts that the given ints are not equal
assertNotEqual
public static void assertNotEqual(int expected, int actual, String errorMessage)Asserts that the given ints are not equal
Parameters
expectedint- Not documented.
actualint- Not documented.
errorMessageString- is a string describing the failure
assertNotEqual
public static void assertNotEqual(long expected, long actual, double minRelativeError)Asserts that the given longs are not equal
assertNotEqual
public static void assertNotEqual(long expected, long actual, double minRelativeError, String errorMessage)Asserts that the given longs are not equal
Parameters
expectedlong- Not documented.
actuallong- Not documented.
minRelativeErrordouble- is the minimum allowed error, a value of 1 represents a 1% error.
errorMessageString- is a string describing the failure
assertNotEqual
public static void assertNotEqual(double expected, double actual, double minRelativeError)Asserts that the given doubles are not equal
Parameters
expecteddouble- Not documented.
actualdouble- Not documented.
minRelativeErrordouble- is the minimum allowed error, a value of 1 represents a 1% error.
assertNotEqual
public static void assertNotEqual(double expected, double actual, double minRelativeError, String errorMessage)Asserts that the given doubles are not equal
Parameters
expecteddouble- Not documented.
actualdouble- Not documented.
minRelativeErrordouble- is the minimum allowed error, a value of 1 represents a 1% error.
errorMessageString- is a string describing the failure
assertNotEqual
public static void assertNotEqual(Object expected, Object actual)Asserts that the given objects are not equal using the first object’s .equal() method
assertNotEqual
public static void assertNotEqual(Object expected, Object actual, String errorMessage)Asserts that the given objects are not equal using the first object’s .equal() method
Parameters
expectedObject- Not documented.
actualObject- Not documented.
errorMessageString- is a string describing the failure
assertArrayEqual
public static void assertArrayEqual(byte[] expected, byte[] actual)Asserts that the given byte arrays are equal
assertArrayEqual
public static void assertArrayEqual(byte[] expected, byte[] actual, String errorMessage)Asserts that the given byte arrays are equal
Parameters
expectedbyte[]- Not documented.
actualbyte[]- Not documented.
errorMessageString- is a string describing the failure
assertArrayEqual
public static void assertArrayEqual(short[] expected, short[] actual)Asserts that the given short arrays are equal
assertArrayEqual
public static void assertArrayEqual(short[] expected, short[] actual, String errorMessage)Asserts that the given short arrays are equal
Parameters
expectedshort[]- Not documented.
actualshort[]- Not documented.
errorMessageString- is a string describing the failure
assertArrayEqual
public static void assertArrayEqual(int[] expected, int[] actual)Asserts that the given int arrays are equal
assertArrayEqual
public static void assertArrayEqual(int[] expected, int[] actual, String errorMessage)Asserts that the given int arrays are equal
Parameters
expectedint[]- Not documented.
actualint[]- Not documented.
errorMessageString- is a string describing the failure
assertArrayEqual
public static void assertArrayEqual(long[] expected, long[] actual, double maxRelativeError)Asserts that the given long arrays are equal
Parameters
expectedlong[]- Not documented.
actuallong[]- Not documented.
maxRelativeErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
assertArrayEqual
public static void assertArrayEqual(long[] expected, long[] actual, double maxRelativeError, String errorMessage)Asserts that the given long arrays are equal
Parameters
expectedlong[]- Not documented.
actuallong[]- Not documented.
maxRelativeErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
errorMessageString- is a string describing the failure
assertArrayEqual
public static void assertArrayEqual(float[] expected, float[] actual, double maxRelativeError)Asserts that the given float arrays are equal
Parameters
expectedfloat[]- Not documented.
actualfloat[]- Not documented.
maxRelativeErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
assertArrayEqual
public static void assertArrayEqual(float[] expected, float[] actual, double maxRelativeError, String errorMessage)Asserts that the given double arrays are equal
Parameters
expectedfloat[]- Not documented.
actualfloat[]- Not documented.
maxRelativeErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
errorMessageString- is a string describing the failure
assertArrayEqual
public static void assertArrayEqual(double[] expected, double[] actual, double maxRelativeError)Asserts that the given double arrays are equal
Parameters
expecteddouble[]- Not documented.
actualdouble[]- Not documented.
maxRelativeErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
assertArrayEqual
public static void assertArrayEqual(double[] expected, double[] actual, double maxRelativeError, String errorMessage)Asserts that the given double arrays are equal
Parameters
expecteddouble[]- Not documented.
actualdouble[]- Not documented.
maxRelativeErrordouble- is the maximum allowed error, a value of 1 represents a 1% error.
errorMessageString- is a string describing the failure
assertArrayEqual
public static void assertArrayEqual(Object[] expected, Object[] actual)Asserts that the given object arrays are equal
assertArrayEqual
public static void assertArrayEqual(Object[] expected, Object[] actual, String errorMessage)Asserts that the given object arrays are equal
Parameters
expectedObject[]- Not documented.
actualObject[]- Not documented.
errorMessageString- is a string describing the failure
assertException
public static void assertException(RuntimeException exception, Runnable expression)Asserts that a certain exception is raised
assertException
public static void assertException(RuntimeException exception, Runnable expression, String errorMessage)Asserts that a certain exception is raised
assertNoException
public static void assertNoException(Runnable expression)Asserts that no exception is raised
assertNoException
public static void assertNoException(Runnable expression, String errorMessage)Asserts that no exception is raised
assertTitle
public static void assertTitle(String title)Verifies the current title is the same otherwise throws an exception
Parameters
titleString- the tile to verify
assertLabel
public static void assertLabel(String name, String text)Asserts that we have a label with the given text baring the given name
Parameters
nameString- the name of the label
textString- the text of the label
assertLabel
public static void assertLabel(int[] path, String text)Asserts that we have a label with the given text baring the given name
Parameters
pathint[]- the path of the label
textString- the text of the label
assertLabel
public static void assertLabel(String text)Asserts that we have a label with the given text baring the given name
Parameters
textString- the text of the label
assertTextArea
public static void assertTextArea(String name, String text)Asserts that we have a TextArea with the given text and the given name
Parameters
nameString- the name of the TextArea
textString- the text of the TextArea
assertTextAreaContaining
public static void assertTextAreaContaining(String name, String text)Asserts that we have a TextArea with the a text contains the given text and with the given name
Parameters
nameString- the name of the TextArea
textString- the sequence to search for in the TextArea
assertTextAreaStartingWith
public static void assertTextAreaStartingWith(String name, String text)Asserts that we have a TextArea with the a text starting with the given text and with the given name
Parameters
nameString- the name of the TextArea
textString- the prefix to search for in the TextArea
assertTextAreaEndingWith
public static void assertTextAreaEndingWith(String name, String text)Asserts that we have a TextArea with the a text ending with the given text and with the given name
Parameters
nameString- the name of the TextArea
textString- the suffix to search for in the TextArea
assertTextArea
public static void assertTextArea(int[] path, String text)Asserts that we have a label with the given text baring the given name
Parameters
pathint[]- the path to the text area
textString- the text of the label
assertTextArea
public static void assertTextArea(String text)Asserts that we have a label with the given text baring the given name
Parameters
textString- the text of the label
findTextAreaText
public static TextArea findTextAreaText(String text)Finds a component with the given name, works even with UI’s that weren’t created with the GUI builder
Parameters
textString- the text of the label/button
Returns
the component with the given TextArea text within the tree