From bd53ac426319e2c0a0c5707f75802ef99b051370 Mon Sep 17 00:00:00 2001 From: Tyler Bouchard Date: Thu, 4 May 2023 11:43:27 -0400 Subject: [PATCH 1/2] Added debug code that writes expected and actual in addition to comparison for debugging and image replacement purposes. Flag is "debug" which will support values "true" and "false". --- .../sentinel/steps/ImageVerificationSteps.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/dougnoel/sentinel/steps/ImageVerificationSteps.java b/src/main/java/com/dougnoel/sentinel/steps/ImageVerificationSteps.java index 7b26f01a..cb6f8a85 100644 --- a/src/main/java/com/dougnoel/sentinel/steps/ImageVerificationSteps.java +++ b/src/main/java/com/dougnoel/sentinel/steps/ImageVerificationSteps.java @@ -136,6 +136,19 @@ private static boolean checkIfImagesMatch(String elementName, boolean negate, St boolean didTheyMatch = comparisonResult.getImageComparisonState() == ImageComparisonState.MATCH; if(didTheyMatch == negate) { FileManager.saveImage(outputFolder, failureImageName, comparisonResult.getResult()); + String debugBoolean = Configuration.toString("debug"); + if(debugBoolean != null) { + try { + if(Boolean.parseBoolean(debugBoolean)) { + FileManager.saveImage(outputFolder, imageId + "_" + "EXPECTED" + appendToResult + ".png", comparisonImage); + FileManager.saveImage(outputFolder, imageId + "_" + "ACTUAL" + appendToResult + ".png", currentStateImage); + } + } + catch(Exception e) { + String errorMessage = SentinelStringUtils.format("Debug mode was enabled, but an exception occurred parsing the setting. Ensure the passed value is 'true' or 'false'. Passed value {}. Exception {}", debugBoolean, e.getMessage()); + log.error(errorMessage); + } + } } else { FileManager.saveImage(outputFolder, passedImageName, comparisonResult.getResult()); From ab1f471be9388e80763dd092f08cb338e304e113 Mon Sep 17 00:00:00 2001 From: Tyler Bouchard Date: Thu, 4 May 2023 12:21:03 -0400 Subject: [PATCH 2/2] Moved the debug code to the outside of the match check. This way it will always occur. Changed configuration to use toBoolean to handle the boolean conversion in the Configuration class. --- .../steps/ImageVerificationSteps.java | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/dougnoel/sentinel/steps/ImageVerificationSteps.java b/src/main/java/com/dougnoel/sentinel/steps/ImageVerificationSteps.java index cb6f8a85..e54ba4f4 100644 --- a/src/main/java/com/dougnoel/sentinel/steps/ImageVerificationSteps.java +++ b/src/main/java/com/dougnoel/sentinel/steps/ImageVerificationSteps.java @@ -134,26 +134,23 @@ private static boolean checkIfImagesMatch(String elementName, boolean negate, St //Write result to disk boolean didTheyMatch = comparisonResult.getImageComparisonState() == ImageComparisonState.MATCH; - if(didTheyMatch == negate) { + if(didTheyMatch == negate) FileManager.saveImage(outputFolder, failureImageName, comparisonResult.getResult()); - String debugBoolean = Configuration.toString("debug"); - if(debugBoolean != null) { - try { - if(Boolean.parseBoolean(debugBoolean)) { - FileManager.saveImage(outputFolder, imageId + "_" + "EXPECTED" + appendToResult + ".png", comparisonImage); - FileManager.saveImage(outputFolder, imageId + "_" + "ACTUAL" + appendToResult + ".png", currentStateImage); - } - } - catch(Exception e) { - String errorMessage = SentinelStringUtils.format("Debug mode was enabled, but an exception occurred parsing the setting. Ensure the passed value is 'true' or 'false'. Passed value {}. Exception {}", debugBoolean, e.getMessage()); - log.error(errorMessage); - } - } - } - else { + else FileManager.saveImage(outputFolder, passedImageName, comparisonResult.getResult()); + + boolean debugBoolean = Configuration.toBoolean("debug"); + if(debugBoolean) { + try { + FileManager.saveImage(outputFolder, imageId + "_" + "EXPECTED" + ".png", comparisonImage); + FileManager.saveImage(outputFolder, imageId + "_" + "ACTUAL" + ".png", currentStateImage); + } + catch(Exception e) { + String errorMessage = SentinelStringUtils.format("Debug mode was enabled, but an exception occurred parsing the setting. Ensure the passed value is 'true' or 'false'. Passed value {}. Exception {}", debugBoolean, e.getMessage()); + log.error(errorMessage); + } } - + return didTheyMatch; }