public class AutoTest
extends java.lang.Object
For an overview of
Automated Testing in Smart GWT, see the documentation here
.
autoTestLocators
- identifier strings which can reliably identify an
interactive element in a Smart GWT application. These locators are designed to work across browsers, Smart GWT
versions, and even major changes to your application's UI. They do not rely on the DOM structure, and are intended to be
able to identify the target element reliably without requiring pervasive explicitly specified component IDs
.
Note that AutoTest locators are the only supported way to identify Smart GWT generated DOM elements when recording tests for automated testing tools. Using XPath DOM locators to identify elements is not a supported approach. The DOM structure and DOM element attributes generated by Smart GWT components are not guaranteed to be identical for functionally equivalent elements across different Smart GWT builds, different browsers, and for dynamically generated components, could even change across page reloads.
The primary APIs for working with AutoTest locators are as follows:
getLocator()
to retrieve a locator for an elementgetElement()
to resolve a stored locator back to an elementinstallLocatorShortcut()
method which allows you to retreive
locators via a simple key combo + mouseDown event on the target element. See the AutoTestLocator overview
documentation for details on how locators are
structured.
See the Reliable AutoTestLocators overview
documentation for best practices for generating high quality locators.
setVariable()
: Set up a named variable for later usestoreLocatorResult()
: Resolve a locator against the
current environment and store it as a variablegetVariable()
: Retrieves the value of a previously defined variablescreen
, the testRoot
may be used to reliably identify the widget hierarchy in question wherever it is rendered inside a larger application.
redraws that fire on
system idle
, for example), and asynchronous RPC operations
. waitForElement()
: this method will wait for asynchronous operations
to complete before resolving an AutoTestLocator
to an element and firing a
callback function. This allows recorded tests to reference elements that are blocked or unavailable until some
asynchronous action(s) complete.waitForSystemDone()
: this method will wait for any outstanding asynchronous system operations to complete and
then fire the specified callback.isSystemDone()
:
this method may be called to check whether there are currently any outstanding asynchronous system
operations.Cypress
and Selenium
automatically makes use of these APIs.AutoTest overview and related methods
Constructor and Description |
---|
AutoTest() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getFullPathLocator()
Convenience method to generate a
AutoTestLocator with no search segments and an
explicit path from the locator root to the target. |
static java.lang.String |
getFullPathLocator(com.google.gwt.dom.client.Element target) |
static java.lang.String |
getFullPathLocator(com.google.gwt.dom.client.Element target,
boolean checkForNativeHandling) |
static java.lang.String |
getFullPathLocator(com.google.gwt.dom.client.Element target,
boolean checkForNativeHandling,
java.lang.String[] coords)
Convenience method to generate a
AutoTestLocator with no search segments and an
explicit path from the locator root to the target. |
static QualityIndicatedLocator |
getLocatorWithIndicators(com.google.gwt.dom.client.Element DOMElement)
Returns the
QualityIndicatedLocator associated with some DOM element in a Smart GWT
application page. |
static QualityIndicatedLocator |
getLocatorWithIndicators(com.google.gwt.dom.client.Element DOMElement,
boolean checkForNativeHandling) |
static QualityIndicatedLocator |
getLocatorWithIndicators(com.google.gwt.dom.client.Element DOMElement,
boolean checkForNativeHandling,
java.lang.String[] coords)
Returns the
QualityIndicatedLocator associated with some DOM element in a Smart GWT
application page. |
static java.lang.String |
getMinimalLocator()
Convenience method to generate a
AutoTestLocator that is as compact as possible. |
static java.lang.String |
getMinimalLocator(com.google.gwt.dom.client.Element target) |
static java.lang.String |
getMinimalLocator(com.google.gwt.dom.client.Element target,
boolean checkForNativeHandling) |
static java.lang.String |
getMinimalLocator(com.google.gwt.dom.client.Element target,
boolean checkForNativeHandling,
java.lang.String[] coords)
Convenience method to generate a
AutoTestLocator that is as compact as possible. |
static Canvas |
getTestRoot()
Gets the implicit root canvas available in scLocators starting "//testRoot[]".
|
static void |
installLocatorShortcut()
This method allows developers to retrieve locators for elements on the page via a key-combo plus mouseDown on the
element in question.
It may be invoked from a bookmarklet stored in the browser, giving developers a one-click way to retrieve locators for any Smart GWT application |
static java.lang.Boolean |
isCanvasDone(Canvas canvas)
Returns whether the canvas is in a consistent state with no pending operations.
|
static java.lang.Boolean |
isElementClickable(Canvas canvas)
Returns whether the instance is ready to be clicked on by a Selenium test.
|
static java.lang.Boolean |
isElementClickable(FormItem item)
Returns whether the instance is ready to be clicked on by a Selenium test.
|
static java.lang.Boolean |
isElementReadyForKeyPresses(Canvas canvas)
Given a DOM element, returns whether the associated Smart GWT Canvas or FormItem is ready to receive keyPress events
from a Selenium test.
|
static java.lang.Boolean |
isElementReadyForKeyPresses(FormItem item)
Given a DOM element, returns whether the associated Smart GWT Canvas or FormItem is ready to receive keyPress events
from a Selenium test.
|
static java.lang.Boolean |
isFormDone(Canvas canvas)
Returns whether the DynamicForm is in a consistent state with no pending operations.
|
static java.lang.Boolean |
isGridDone(Canvas canvas)
Returns whether the ListGrid supplied or containing the supplied canvas is in a consistent state with no pending
operations.
|
static java.lang.Boolean |
isItemDone(FormItem item)
Returns whether the FormItem is in a consistent state with no pending operations.
|
static boolean |
isSystemDone()
Returns a boolean to indicate whether the current application is fully loaded with no pending operations, and is ready
for user interaction.
|
static boolean |
isSystemDone(boolean options)
Returns a boolean to indicate whether the current application is fully loaded with no pending operations, and is ready
for user interaction.
|
static boolean |
isSystemDone(SystemDoneConfig options)
Returns a boolean to indicate whether the current application is fully loaded with no pending operations, and is ready
for user interaction.
|
static java.lang.Boolean |
isTileGridDone(Canvas canvas)
Returns whether the TileGrid is in a consistent state with no pending operations.
|
static java.lang.Boolean |
isTileLayoutDone(Canvas canvas)
Returns whether the TileLayout is in a consistent state with no pending operations.
|
static Canvas |
locateCanvasFromDOMElement(com.google.gwt.dom.client.Element element)
Given an element in the DOM, returns the canvas containing this element, or null if the element is not contained in any
canvas handle.
|
static void |
setTestRoot(Canvas canvas)
Sets the implicit root canvas available in scLocators starting "//testRoot[]".
|
static void |
uninstallLocatorShortcut()
Uninstalls the locator shortcut installed by
installLocatorShortcut() |
static void |
waitForElement(java.lang.String locator,
java.lang.String callback)
Waits for any in-progress actions to complete and then returns the element for the specified locator.
|
static void |
waitForElement(java.lang.String locator,
java.lang.String callback,
ElementWaitConfig options)
Waits for any in-progress actions to complete and then returns the element for the specified locator.
|
static void |
waitForSystemDone(java.lang.String callback)
Fires the provided callback when
isSystemDone() returns true. |
static void |
waitForSystemDone(java.lang.String callback,
SystemWaitConfig options)
Fires the provided callback when
isSystemDone() returns true. |
public static java.lang.String getFullPathLocator()
AutoTestLocator
with no search segments and an
explicit path from the locator root to the target. This method sets getLocator()
with the following configuration settings:
AutoTestLocator
public static java.lang.String getFullPathLocator(com.google.gwt.dom.client.Element target)
getFullPathLocator()
public static java.lang.String getFullPathLocator(com.google.gwt.dom.client.Element target, boolean checkForNativeHandling)
getFullPathLocator()
public static java.lang.String getFullPathLocator(com.google.gwt.dom.client.Element target, boolean checkForNativeHandling, java.lang.String[] coords)
AutoTestLocator
with no search segments and an
explicit path from the locator root to the target. This method sets getLocator()
with the following configuration settings:
target
- Target within the page. This may be a DOM element, a Canvas
or a FormItem
. If null, a locator for the last mouse event target DOM element will
be generated.checkForNativeHandling
- If this parameter is passed in, check whether the target element responds to native browser events directly rather than
going through the Smart GWT widget/event handling model. If we detect this case, return null rather than a live
locator. This allows us to differentiate between (for example) an event on a Canvas handle, and an event occurring
directly on a simple <a href=...>
tag written inside a Canvas handle.coords
- X, Y page positionAutoTestLocator
public static QualityIndicatedLocator getLocatorWithIndicators(com.google.gwt.dom.client.Element DOMElement)
QualityIndicatedLocator
associated with some DOM element in a Smart GWT
application page. If coords, representing the page position, is passed in, the locator may be generated with a specific
trailing "target area" identifer that will map back to the appropriate, potentially different, physical coordinates,
even if the widget is moved. The coords argument will only have an effect in cases where the mouse position over the
target could potentially change behavior.DOMElement
- DOM element within in the page. If null the locator for the last mouse event target will be generatedpublic static QualityIndicatedLocator getLocatorWithIndicators(com.google.gwt.dom.client.Element DOMElement, boolean checkForNativeHandling)
public static QualityIndicatedLocator getLocatorWithIndicators(com.google.gwt.dom.client.Element DOMElement, boolean checkForNativeHandling, java.lang.String[] coords)
QualityIndicatedLocator
associated with some DOM element in a Smart GWT
application page. If coords, representing the page position, is passed in, the locator may be generated with a specific
trailing "target area" identifer that will map back to the appropriate, potentially different, physical coordinates,
even if the widget is moved. The coords argument will only have an effect in cases where the mouse position over the
target could potentially change behavior.DOMElement
- DOM element within in the page. If null the locator for the last mouse event target will be generatedcheckForNativeHandling
- If this parameter is passed in, check whether the target element responds to native browser events directly rather than
going through the Smart GWT widget/event handling model. If we detect this case, return null rather than a live
locator. This allows us to differentiate between (for example) an event on a Canvas handle, and an event occurring
directly on a simple <a href=...>
tag written inside a Canvas handle.coords
- X, Y page positionpublic static java.lang.String getMinimalLocator()
AutoTestLocator
that is as compact as possible.
This method sets getLocator()
with the following configuration
settings:
AutoTestLocator
public static java.lang.String getMinimalLocator(com.google.gwt.dom.client.Element target)
getMinimalLocator()
public static java.lang.String getMinimalLocator(com.google.gwt.dom.client.Element target, boolean checkForNativeHandling)
getMinimalLocator()
public static java.lang.String getMinimalLocator(com.google.gwt.dom.client.Element target, boolean checkForNativeHandling, java.lang.String[] coords)
AutoTestLocator
that is as compact as possible.
This method sets getLocator()
with the following configuration
settings:
target
- Target within the page. This may be a DOM element, a Canvas
or a FormItem
. If null, a locator for the last mouse event target DOM element will
be generated.checkForNativeHandling
- If this parameter is passed in, check whether the target element responds to native browser events directly rather than
going through the Smart GWT widget/event handling model. If we detect this case, return null rather than a live
locator. This allows us to differentiate between (for example) an event on a Canvas handle, and an event occurring
directly on a simple <a href=...>
tag written inside a Canvas handle.coords
- X, Y page positionAutoTestLocator
public static void installLocatorShortcut()
When installLocatorShortcut() is invoked, it will register a
Page-level mouseDown
handler which, if the Shift+Ctrl or Shift+Meta key-combo are being held down will
display the locator for the element under the mouse in a text-box and also copy it to clipboard.
As with the isc.showConsole()
method, developers may wish to create a bookmark in their browser
to quickly enable this functionality on any Smart GWT application, without any changes to the application code:
To uninstall the locator
shortcut, call uninstallLocatorShortcut()
public static java.lang.Boolean isCanvasDone(Canvas canvas)
canvas
- canvas to testpublic static java.lang.Boolean isElementClickable(Canvas canvas)
implicitNetworkWait
) isCanvasDone()
isTileGridDone()
isTileLayoutDone()
isGridDone()
isFormDone()
canvas
- instance to testpublic static java.lang.Boolean isElementClickable(FormItem item)
implicitNetworkWait
) isCanvasDone()
isTileGridDone()
isTileLayoutDone()
isGridDone()
isFormDone()
item
- instance to testpublic static java.lang.Boolean isElementReadyForKeyPresses(Canvas canvas)
TextItem
, FileItem
, or TextAreaItem
,
it has native focus, isElementClickable()
canvas
- DOM element to test (element obtained from canvas, form item, or Smart GWT locator if provided)public static java.lang.Boolean isElementReadyForKeyPresses(FormItem item)
TextItem
, FileItem
, or TextAreaItem
,
it has native focus, isElementClickable()
item
- DOM element to test (element obtained from canvas, form item, or Smart GWT locator if provided)public static java.lang.Boolean isFormDone(Canvas canvas)
DynamicForm
. Otherwise, returns true or false
according as the conditions below are all satisfied: isItemDone()
canvas
- canvas to testpublic static java.lang.Boolean isGridDone(Canvas canvas)
canvas
- canvas to testpublic static java.lang.Boolean isItemDone(FormItem item)
FormItem
. Otherwise, returns true or false according as
the conditions below are all satisfied: isCanvasDone()
(or isGridDone()
, etc., as appropriate) SelectItem
or
ComboBoxItem
) cannot have any pending row fetches FormItem
s must satisfy isItemDone()
themselves
Canvas
must satisfy isCanvasDone()
(or isGridDone()
, etc., as appropriate) item
- canvas to testpublic static boolean isSystemDone()
isGridDone()
isTileGridDone()
isTileLayoutDone()
isFormDone()
isCanvasDone()
options
parameter allows developers to check additional criteria as documented under
SystemDoneConfig
. Note: waitForSystemDone()
will poll this method repeatedly to check for all pending actions being complete. The SystemWaitConfig
parameter of that method allow the user to speciofy which actions to wait
for. By default waitForSystemDone()
will wait for all
actions to complete, including queued redraws, timers, network requests, as well as page load and comopnent level
isComponentDone
checks.
Depending on your application configuration, it is possible that this method will not be able to determine whether it is truly in a busy state. Some examples include:
SystemDoneConfig.includeTimers
is true and the application
has a constantly running background timer to perform some ongoing polling action or similar, this method may
return false
even though the application is ready for interaction SystemDoneConfig.includeRedraws
is true, and the
application is using messaging, or some other mechanism to periodically refresh component(s) such that they
are repeatedly marked as dirty, this method may return false
even though the application is ready for
interaction true
even when the application is waiting on a response from this third-party
tool. public static boolean isSystemDone(SystemDoneConfig options)
isGridDone()
isTileGridDone()
isTileLayoutDone()
isFormDone()
isCanvasDone()
options
parameter allows developers to check additional criteria as documented under
SystemDoneConfig
. Note: waitForSystemDone()
will poll this method repeatedly to check for all pending actions being complete. The SystemWaitConfig
parameter of that method allow the user to speciofy which actions to wait
for. By default waitForSystemDone()
will wait for all
actions to complete, including queued redraws, timers, network requests, as well as page load and comopnent level
isComponentDone
checks.
Depending on your application configuration, it is possible that this method will not be able to determine whether it is truly in a busy state. Some examples include:
SystemDoneConfig.includeTimers
is true and the application
has a constantly running background timer to perform some ongoing polling action or similar, this method may
return false
even though the application is ready for interaction SystemDoneConfig.includeRedraws
is true, and the
application is using messaging, or some other mechanism to periodically refresh component(s) such that they
are repeatedly marked as dirty, this method may return false
even though the application is ready for
interaction true
even when the application is waiting on a response from this third-party
tool. options
- This parameter determines what specific outstanding actions are required to be completed before the system is
considered "done" with current processing. If passed as a boolean rather than a SystemDoneConfig object, this
determines whether the system should wait for pending redraws
.public static boolean isSystemDone(boolean options)
isGridDone()
isTileGridDone()
isTileLayoutDone()
isFormDone()
isCanvasDone()
options
parameter allows developers to check additional criteria as documented under
SystemDoneConfig
. Note: waitForSystemDone()
will poll this method repeatedly to check for all pending actions being complete. The SystemWaitConfig
parameter of that method allow the user to speciofy which actions to wait
for. By default waitForSystemDone()
will wait for all
actions to complete, including queued redraws, timers, network requests, as well as page load and comopnent level
isComponentDone
checks.
Depending on your application configuration, it is possible that this method will not be able to determine whether it is truly in a busy state. Some examples include:
SystemDoneConfig.includeTimers
is true and the application
has a constantly running background timer to perform some ongoing polling action or similar, this method may
return false
even though the application is ready for interaction SystemDoneConfig.includeRedraws
is true, and the
application is using messaging, or some other mechanism to periodically refresh component(s) such that they
are repeatedly marked as dirty, this method may return false
even though the application is ready for
interaction true
even when the application is waiting on a response from this third-party
tool. options
- This parameter determines what specific outstanding actions are required to be completed before the system is
considered "done" with current processing. If passed as a boolean rather than a SystemDoneConfig object, this
determines whether the system should wait for pending redraws
.public static java.lang.Boolean isTileGridDone(Canvas canvas)
isTileLayoutDone()
canvas
- TileGrid to testpublic static java.lang.Boolean isTileLayoutDone(Canvas canvas)
isCanvasDone()
canvas
- TileLayout to testpublic static Canvas locateCanvasFromDOMElement(com.google.gwt.dom.client.Element element)
element
- DOM element within in the pagepublic static void setTestRoot(Canvas canvas)
canvas
- the implicit rootpublic static void uninstallLocatorShortcut()
installLocatorShortcut()
public static void waitForElement(java.lang.String locator, java.lang.String callback)
By default
this method will wait for the system to be done
before calling
getElement()
with the specified locator. The waitStyle
attribute of the options parameter may be used to
instead wait for the locator to resolve to a clickable
element
.
locator
- locator for the element to retrieve.
See AutoTestLocator
callback
- callback to fire when the element has been retrieved - takes two parameters: Callback
public static void waitForElement(java.lang.String locator, java.lang.String callback, ElementWaitConfig options)
By default
this method will wait for the system to be done
before calling
getElement()
with the specified locator. The waitStyle
attribute of the options parameter may be used to
instead wait for the locator to resolve to a clickable
element
.
locator
- locator for the element to retrieve.
See AutoTestLocator
callback
- callback to fire when the element has been retrieved - takes two parameters: Callback
options
- Options to configure the waitpublic static void waitForSystemDone(java.lang.String callback)
isSystemDone()
returns true. By default this will wait for the following system actions to complete:
RPC and DataSource requests
queued redraws
isSystemDone()
The options
parameter gives developers
finer grained control over what to wait for.
public static void waitForSystemDone(java.lang.String callback, SystemWaitConfig options)
isSystemDone()
returns true. By default this will wait for the following system actions to complete:
RPC and DataSource requests
queued redraws
isSystemDone()
The options
parameter gives developers
finer grained control over what to wait for.
callback
- Action to fire. This will take a single parameter "done" which will be set to false if the method timed out waiting for
isSystemDone() to return true;.
See Callback
options
- options to configure the waitpublic static Canvas getTestRoot()