Class AnimatedGifManager

java.lang.Object
com.shaft.gui.internal.image.AnimatedGifManager

public class AnimatedGifManager extends Object
Manages the creation, frame-appending, and finalisation of animated GIF files that visualise test execution steps in the SHAFT framework.

Each test thread gets its own GIF writer state through ThreadLocal fields, making this class safe for parallel test execution. A new GIF is started automatically when the first screenshot is captured; subsequent screenshots are appended as additional frames.

GIF creation is controlled by the SHAFT.Properties.visuals.createAnimatedGif() flag. When disabled, all methods in this class are effectively no-ops.

Example (managed automatically by the SHAFT framework):

AnimatedGifManager.startOrAppendToAnimatedGif(screenshotBytes);
// ... test steps ...
String gifPath = AnimatedGifManager.attachAnimatedGif();
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Finalises and attaches the current thread's animated GIF to the Allure report, then resets the thread-local GIF state so a new GIF can be started for the next test.
    static void
    startOrAppendToAnimatedGif(byte[] screenshot)
    Appends a screenshot frame to the current thread's animated GIF, or starts a new GIF if one has not yet been created for the current thread.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • attachAnimatedGif

      public static String attachAnimatedGif()
      Finalises and attaches the current thread's animated GIF to the Allure report, then resets the thread-local GIF state so a new GIF can be started for the next test.

      This method is a no-op when SHAFT.Properties.visuals.createAnimatedGif() is false or when no GIF has been started for the current thread.

      Example:

      String gifPath = AnimatedGifManager.attachAnimatedGif();
      
      Returns:
      the relative file-system path of the attached GIF, or an empty string if nothing was attached
    • startOrAppendToAnimatedGif

      public static void startOrAppendToAnimatedGif(byte[] screenshot)
      Appends a screenshot frame to the current thread's animated GIF, or starts a new GIF if one has not yet been created for the current thread.

      This method is a no-op when SHAFT.Properties.visuals.createAnimatedGif() is false.

      Example:

      byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
      AnimatedGifManager.startOrAppendToAnimatedGif(screenshot);
      
      Parameters:
      screenshot - the raw PNG screenshot bytes to append as the next GIF frame; if null the call is silently ignored