public TerminalSnapshot getSnapshot() {
    lazyConnect();

    // clear the snapshot sequence is different from the session, clear it so it will re-build
    if (terminalSnapshot != null
        && terminalSnapshot.getSequence() != null
        && !terminalConnection.getSequence().equals(terminalSnapshot.getSequence())) {
      terminalSnapshot = null;
    }

    waitForNonEmptySnapshot();

    if (!isConnected()) {
      disconnect();
      throw (new OpenLegacyRuntimeException("Session is not connected"));
    }

    if (terminalSnapshot == null) {
      throw (new OpenLegacyProviderException(
          MessageFormat.format(
              "Current screen is empty for session after waiting for {0}", maxWaitOnEmptyScreen)));
    }
    return terminalSnapshot;
  }
  private int waitForNonEmptySnapshot() {
    int timer = 0;
    do {
      if (terminalSnapshot == null) {
        terminalSnapshot = terminalConnection.fetchSnapshot();
      }

      if (terminalSnapshot.getFields().size() == 0) {
        try {
          Thread.sleep(waitBetweenEmptyScreens);
          timer += waitBetweenEmptyScreens;
        } catch (InterruptedException e) {
          // do nothing
        }
        terminalSnapshot = null;
      }

    } while (isConnected() && terminalSnapshot == null && timer < maxWaitOnEmptyScreen);
    return timer;
  }
 private void assertSnapshot(TerminalSnapshot terminalSnapshot, String snapshotTextFile)
     throws IOException {
   byte[] expectedBytes = IOUtils.toByteArray(getClass().getResourceAsStream(snapshotTextFile));
   AssertUtils.assertContent(expectedBytes, terminalSnapshot.toString().getBytes());
 }