| java.lang.Object org.uispec4j.interception.WindowInterceptor
WindowInterceptor | final public class WindowInterceptor (Code) | | Intercepts popped-up windows such as JFrame or JDialog.
There are two main usage scenarios for this class: intercepting "frames", i.e. non-modal windows,
and intercepting modal dialogs.
Non-modal windows can be intercepted and used directly from within the test using the following
construct:
Window window = WindowInterceptor.run(panel.getButton("open").triggerClick());
Modal dialogs cannot be intercepted this way, because the thread from which the test is run
will likely be blocked in the production code until the dialog is closed.
To intercept a sequence of popped-up windows, use the following construct:
WindowInterceptor
.init(new Trigger() {
public void run() throws Exception {
// ... trigger something that will cause the first window to be shown ...
}
})
.process(new WindowHandler("first dialog") {
public Trigger process(Window window) {
// ... perform some operations on the first window ...
return window.getButton("OK").triggerClick(); // return a trigger that will close it
}
})
.process(new WindowHandler("second dialog") {
public Trigger process(Window window) {
// ... perform some operations on the second window ...
return window.getButton("OK").triggerClick(); // return a trigger that will close it
}
})
.run();
This class uses a timeout (see
UISpec4J.setWindowInterceptionTimeLimit ) to make sure
that windows appear within a given time limit, and that modal windows are closed before the
end of the interception.
See Also: Intercepting windows |
getModalDialog | public static Window getModalDialog(Trigger trigger)(Code) | | Performs a "quick&dirty" interception of a modal dialog.
Warning: This method should be handled with care and especially avoided in cases
where the application code is blocked while the dialog is displayed,
because it could result in deadlocks.
Modal dialogs should rather be intercepted using
WindowInterceptor.init(Trigger)
This method will fail if no window was shown by the trigger under the time limit, or if it is
used with a non-modal window.
|
init | public static WindowInterceptor init(Trigger trigger)(Code) | | Starts the interception of a modal dialog. The returned interceptor must be used for
processing the displayed window, for instance:
WindowInterceptor
.init(new Trigger() {
public void run() throws Exception {
// ... trigger something that will cause the first window to be shown ...
}
})
.process(new WindowHandler("my dialog") {
public Trigger process(Window window) {
// ... perform some operations on the shown window ...
return window.getButton("OK").triggerClick(); // return a trigger that will close it
}
})
.run();
See Also: WindowInterceptor.process(WindowHandler) |
process | public WindowInterceptor process(WindowHandler handler)(Code) | | Processes a modal dialog. The provided WindowHandler must return a trigger that will cause
the window to be closed, in order to prevent the application to be stopped.
|
processTransientWindow | public WindowInterceptor processTransientWindow(String title)(Code) | | Processes a dialog that will be closed automatically, and checks its name.
|
processTransientWindow | public WindowInterceptor processTransientWindow()(Code) | | Processes a dialog that will be closed automatically.
|
|
|