1. public static class WindowCollisionHandler extends TestObjectExceptionHandler {
  2. public WindowCollisionHandler() {
  3. super(new ArrayList<Class<? extends Throwable>>() {
  4. private static final long serialVersionUID = 1L;
  5. {add(UnclosedBrowserWindowException.class);
  6. add(UnswitchableBrowserWindowException.class);
  7. add(UnhandledAlertException.class);}
  8. });
  9. }
  10. public Object handleException(Object googlePage, Method method,
  11. MethodProxy methodProxy, Object[] args, Throwable exception) throws Throwable {
  12. GooglePageObject victim = (GooglePageObject) googlePage;
  13. //о классе WindowSwitcher пока не буду рассказывать, возможно в
  14. //другой статье
  15. WindowSwitcher switcher = WindowSwitcher.get(victim.driverEncapsulation);
  16. UnhandledWindowChecker checker = UnhandledWindowChecker.getChecker(switcher);
  17. checker.killUnexpectedWindows();
  18. try
  19. {
  20. return methodProxy.invokeSuper(googlePage, args);
  21. }
  22. catch (Exception e)
  23. {
  24. if (throwableList.contains(e.getClass()))
  25. {
  26. return this.handleException(googlePage, method,
  27. methodProxy, args, e);
  28. }
  29. else
  30. {
  31. throw e;
  32. }
  33. }
  34. }
  35. }
Comments powered by Disqus