Class Screenshots

java.lang.Object
io.klib.swtbot.support.Screenshots

public final class Screenshots extends Object
Captures screenshots using an explicitly supplied, existing application Display. Does not create a Display or change workbench state. Shell suppliers run on that Display's UI thread. Scope instances to a test/session: diagnosed throwables are retained for duplicate suppression. Keep shells visible until capture completes.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Test action that may throw any original test failure.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Screenshots(CaptureOptions options, String testId, Supplier<org.eclipse.swt.widgets.Display> displaySupplier)
    Creates isolated artifact directories without obtaining or creating a Display.
  • Method Summary

    Modifier and Type
    Method
    Description
    capture(String checkpoint, CaptureMode mode, Supplier<org.eclipse.swt.widgets.Shell> shellSupplier)
    Captures one PNG, returning skipped/failed outcomes when evidence is unavailable.
    checkpoint(String checkpoint, Supplier<org.eclipse.swt.widgets.Shell> shell)
    Captures each configured mode sequentially, with a separate timeout per mode.
    Returns the directory containing this instance's artifacts.
    void
    failure(String checkpoint, Supplier<org.eclipse.swt.widgets.Shell> shell, Throwable original)
    Diagnoses an original failure at most once by identity within this instance.
    void
    guard(String checkpoint, Supplier<org.eclipse.swt.widgets.Shell> shell, Screenshots.Action action)
    Runs an action on the calling thread; diagnoses failures before caller teardown and rethrows the same original throwable, never a replacement diagnostic error.
    void
    requireCheckpoint(String checkpoint, Supplier<org.eclipse.swt.widgets.Shell> shell)
    Captures all configured modes and requires every outcome to be captured.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Screenshots

      public Screenshots(CaptureOptions options, String testId, Supplier<org.eclipse.swt.widgets.Display> displaySupplier) throws IOException
      Creates isolated artifact directories without obtaining or creating a Display.
      Parameters:
      options - non-null capture settings
      testId - non-null test identity used for a sanitized directory name
      displaySupplier - non-null supplier of the existing application Display; may return null
      Throws:
      IOException - if artifact directories cannot be created
      NullPointerException - if an argument is null
  • Method Details

    • directory

      public Path directory()
      Returns the directory containing this instance's artifacts.
      Returns:
      the absolute artifact directory for this instance
    • checkpoint

      public List<CaptureResult> checkpoint(String checkpoint, Supplier<org.eclipse.swt.widgets.Shell> shell)
      Captures each configured mode sequentially, with a separate timeout per mode.
      Parameters:
      checkpoint - artifact label, sanitized and bounded during allocation
      shell - supplier evaluated on the application UI thread
      Returns:
      immutable outcomes in configured mode order
    • requireCheckpoint

      public void requireCheckpoint(String checkpoint, Supplier<org.eclipse.swt.widgets.Shell> shell)
      Captures all configured modes and requires every outcome to be captured.
      Parameters:
      checkpoint - artifact label
      shell - supplier evaluated on the application UI thread
      Throws:
      IllegalStateException - if any capture was skipped or failed
    • guard

      public void guard(String checkpoint, Supplier<org.eclipse.swt.widgets.Shell> shell, Screenshots.Action action) throws Throwable
      Runs an action on the calling thread; diagnoses failures before caller teardown and rethrows the same original throwable, never a replacement diagnostic error.
      Parameters:
      checkpoint - failure artifact label
      shell - supplier evaluated on the application UI thread during capture
      action - test action
      Throws:
      Throwable - the original action failure
    • failure

      public void failure(String checkpoint, Supplier<org.eclipse.swt.widgets.Shell> shell, Throwable original)
      Diagnoses an original failure at most once by identity within this instance. Logs outcomes and attaches capture problems as suppressed exceptions instead of throwing them. Invoke while application UI still exists.
      Parameters:
      checkpoint - failure artifact label
      shell - supplier evaluated on the application UI thread
      original - non-null original failure to preserve
    • capture

      public CaptureResult capture(String checkpoint, CaptureMode mode, Supplier<org.eclipse.swt.widgets.Shell> shellSupplier)
      Captures one PNG, returning skipped/failed outcomes when evidence is unavailable. Runs immediately on the UI thread or queues bounded work otherwise. Timeout or interruption cancels queued work without interrupting executing native work; interruption status is restored. Screen modes can include occlusion/private pixels. Native images and graphics contexts are disposed after capture.
      Parameters:
      checkpoint - artifact label, sanitized and bounded during allocation
      mode - non-null region to capture
      shellSupplier - supplier of a visible live shell on the application Display
      Returns:
      capture outcome, including PNG path/dimensions on success
      Throws:
      NullPointerException - if mode is null