Class ImageProcessingActions

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

public class ImageProcessingActions extends Object
  • Method Details

    • compareImageFolders

      public static void compareImageFolders(String referenceFolderPath, String testFolderPath, double threshold)
    • highlightElementInScreenshot

      public static byte[] highlightElementInScreenshot(byte[] targetScreenshot, org.openqa.selenium.Rectangle elementLocation, Color highlightColor)
    • findImageWithinCurrentPage

      public static List<Integer> findImageWithinCurrentPage(String referenceImagePath, byte[] currentPageScreenshot)
    • formatElementLocatorToImagePath

      public static String formatElementLocatorToImagePath(org.openqa.selenium.By elementLocator)
      Formats a Selenium locator into the stable visual-baseline file-name hash used by SHAFT.
      Parameters:
      elementLocator - locator of the element being compared
      Returns:
      stable hashed baseline file name without extension
    • formatElementLocatorToImagePath

      public static String formatElementLocatorToImagePath(String elementLocatorName)
      Formats a backend-neutral locator description into the stable visual-baseline file-name hash used by SHAFT.
      Parameters:
      elementLocatorName - stable element locator description
      Returns:
      stable hashed baseline file name without extension
    • getReferenceImage

      public static byte[] getReferenceImage(org.openqa.selenium.By elementLocator)
      Reads the existing reference image for a Selenium locator, when present.
      Parameters:
      elementLocator - locator of the element being compared
      Returns:
      encoded reference image bytes, or null when no baseline exists
    • getReferenceImage

      public static byte[] getReferenceImage(String elementLocatorName)
      Reads the existing reference image for a backend-neutral locator, when present.
      Parameters:
      elementLocatorName - stable element locator description
      Returns:
      encoded reference image bytes, or null when no baseline exists
    • getShutterbugDifferencesImage

      public static byte[] getShutterbugDifferencesImage(org.openqa.selenium.By elementLocator)
    • getShutterbugDifferencesImage

      public static byte[] getShutterbugDifferencesImage(String elementLocatorName)
      Reads a generated Shutterbug differences image for a backend-neutral locator, when present.
      Parameters:
      elementLocatorName - stable element locator description
      Returns:
      encoded differences image bytes, or an empty byte array when no differences image exists
    • compareAgainstBaseline

      public static Boolean compareAgainstBaseline(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, byte[] elementScreenshot, ImageProcessingActions.VisualValidationEngine visualValidationEngine)
    • compareAgainstBaseline

      public static Boolean compareAgainstBaseline(String elementLocatorName, byte[] elementScreenshot, ImageProcessingActions.VisualValidationEngine visualValidationEngine)
      Compares backend-neutral screenshot bytes against the visual baseline for the supplied locator description.
      Parameters:
      elementLocatorName - stable element locator description
      elementScreenshot - encoded screenshot bytes
      visualValidationEngine - requested visual validation engine
      Returns:
      true when the comparison passes or creates a new baseline
    • compareScreenshotAgainstBaseline

      public static VisualProcessingProvider.ScreenshotComparisonResult compareScreenshotAgainstBaseline(org.openqa.selenium.By elementLocator, byte[] actualScreenshot, List<int[]> maskRects, Integer maxDiffPixels, Double maxDiffPixelRatio)
      Compares an element's actual screenshot against its visual-regression baseline using a pixel-level diff. Saves the actual screenshot as the new baseline when none exists yet, or when -Dshaft.updateSnapshots=true.
      Parameters:
      elementLocator - locator of the element being compared
      actualScreenshot - encoded screenshot bytes of the current state
      maskRects - pixel-space [x, y, width, height] regions to exclude from comparison, or null
      maxDiffPixels - maximum allowed differing pixel count, or null to ignore this budget
      maxDiffPixelRatio - maximum allowed differing pixel ratio (0.0-1.0), or null to ignore this budget
      Returns:
      the comparison result
    • compareScreenshotAgainstBaseline

      public static VisualProcessingProvider.ScreenshotComparisonResult compareScreenshotAgainstBaseline(String baselineKey, byte[] actualScreenshot, List<int[]> maskRects, Integer maxDiffPixels, Double maxDiffPixelRatio)
      Compares a backend-neutral actual screenshot (e.g. a full-page capture) against its visual-regression baseline using a pixel-level diff. Saves the actual screenshot as the new baseline when none exists yet, or when -Dshaft.updateSnapshots=true.
      Parameters:
      baselineKey - stable backend-neutral baseline description
      actualScreenshot - encoded screenshot bytes of the current state
      maskRects - pixel-space [x, y, width, height] regions to exclude from comparison, or null
      maxDiffPixels - maximum allowed differing pixel count, or null to ignore this budget
      maxDiffPixelRatio - maximum allowed differing pixel ratio (0.0-1.0), or null to ignore this budget
      Returns:
      the comparison result
    • loadOpenCV

      public static void loadOpenCV()
    • loadOpenCVIfAvailable

      public static void loadOpenCVIfAvailable()
      Loads the optional visual processing provider when it is available. Engine startup uses this method so installations that do not include shaft-visual remain quiet until a visual operation is requested.