public void replay()
      throws InterruptedException, UnknownEventException, IOException,
          ScreenshotDifferentException {
    long preOffset = 0;
    if (eventSequence != null) {
      for (Event event : eventSequence) {
        if (event instanceof MouseEvent) {
          replayMouseEvent(event, preOffset);
          preOffset = ((MouseEvent) event).getOffset();
        } else if (event instanceof KeyboardEvent) {
          replayKeyboardEvent(event, preOffset);
          preOffset = ((KeyboardEvent) event).getOffset();
        } else if (event instanceof ScreenshotEvent) {
          screenshotTaker.takeScreenshot();
          ScreenshotEvent screenshotEvent = (ScreenshotEvent) event;
          preOffset = screenshotEvent.getOffset();

          if (!screenshotComparator.areScreenshotsIdentical(
              screenshotEvent, screenshotTaker.getScreenshotFoler())) {
            throw new ScreenshotDifferentException(
                "Screenshot_" + screenshotEvent.getIndex() + " is not identical.");
          }
        } else {
          throw new UnknownEventException("Unknown event: " + event.toString());
        }
      }
    }
  }
 public ActionReplayer(List<Event> eventSequence, ScreenshotTaker screenshotTaker) {
   this.setEventSequence(eventSequence);
   this.keyboardEventPlayer = new KeyboardEventPlayer();
   this.mouseEventPlayer = new MouseEventPlayer();
   this.screenshotComparator = ScreenshotComparator.getInstance();
   setScreenshotTaker(screenshotTaker);
 }