public final class WindowInterceptor extends Object
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(long)
) to make sure
that windows appear within a given time limit, and that modal windows are closed before the
end of the interception.Modifier and Type | Method and Description |
---|---|
static Window |
getModalDialog(Trigger trigger)
Performs a "quick and dirty" interception of a modal dialog.
|
static WindowInterceptor |
init(Trigger trigger)
Starts the interception of a modal dialog.
|
WindowInterceptor |
process(String title,
WindowHandler handler)
Processes a modal dialog after having checked its title first.
|
WindowInterceptor |
process(WindowHandler handler)
Processes a modal dialog.
|
WindowInterceptor |
process(WindowHandler[] handlers)
Processes a sequence of dialogs (one handler per dialog).
|
WindowInterceptor |
processTransientWindow()
Processes a dialog that will be closed automatically.
|
WindowInterceptor |
processTransientWindow(String title)
Processes a dialog that will be closed automatically, and checks its name.
|
WindowInterceptor |
processWithButtonClick(String buttonName)
Processes a dialog by clicking on a given button.
|
WindowInterceptor |
processWithButtonClick(String title,
String buttonName)
Processes a dialog by checking its title and clicking on a given button.
|
void |
run()
Starts the interception prepared with the
init(Trigger) /process(WindowHandler) call sequence. |
static Window |
run(Trigger trigger)
Intercepts a non-modal window by running a trigger and returning the displayed window.
|
public static WindowInterceptor init(Trigger trigger)
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();
process(WindowHandler)
public WindowInterceptor process(WindowHandler handler)
public WindowInterceptor process(String title, WindowHandler handler)
process(WindowHandler)
public WindowInterceptor process(WindowHandler[] handlers)
process(WindowHandler)
public WindowInterceptor processTransientWindow(String title)
public WindowInterceptor processTransientWindow()
public WindowInterceptor processWithButtonClick(String buttonName)
process(WindowHandler)
public WindowInterceptor processWithButtonClick(String title, String buttonName)
processWithButtonClick(String)
public void run()
init(Trigger)
/process(WindowHandler)
call sequence.
This method will fail if no window was shown by the trigger under the time limit.
defined with UISpec4J.setWindowInterceptionTimeLimit(long)
.public static Window run(Trigger trigger)
UISpec4J.setWindowInterceptionTimeLimit(long)
,
or if it is used with a modal dialog (modal dialogs should be intercepted using
init(Trigger)
). Note: the trigger is run in the current thread.
public static Window getModalDialog(Trigger trigger)
Performs a "quick and 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 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.
Copyright © 2004–2016. All rights reserved.