- public static class WindowCollisionHandler extends TestObjectExceptionHandler {
- public WindowCollisionHandler() {
- super(new ArrayList<Class<? extends Throwable>>() {
- private static final long serialVersionUID = 1L;
- {add(UnclosedBrowserWindowException.class);
- add(UnswitchableBrowserWindowException.class);
- add(UnhandledAlertException.class);}
- });
- }
- public Object handleException(Object googlePage, Method method,
- MethodProxy methodProxy, Object[] args, Throwable exception) throws Throwable {
- GooglePageObject victim = (GooglePageObject) googlePage;
- //о классе WindowSwitcher пока не буду рассказывать, возможно в
- //другой статье
- WindowSwitcher switcher = WindowSwitcher.get(victim.driverEncapsulation);
- UnhandledWindowChecker checker = UnhandledWindowChecker.getChecker(switcher);
- checker.killUnexpectedWindows();
- try
- {
- return methodProxy.invokeSuper(googlePage, args);
- }
- catch (Exception e)
- {
- if (throwableList.contains(e.getClass()))
- {
- return this.handleException(googlePage, method,
- methodProxy, args, e);
- }
- else
- {
- throw e;
- }
- }
- }
- }