var file1 = new FileInfo("C:\\Users\\abaranov\\source\\repos\\gitlab-hemasource\\HSAutomatedTests\\HSAutomatedTests\\bin\\Debug\\SO642003_689445.pdf"); var file2 = new FileInfo("C:\\Users\\abaranov\\source\\repos\\gitlab-hemasource\\HSAutomatedTests\\HSAutomatedTests\\bin\\Debug\\SO642003_689455.pdf");
Comparator.Pdf.Compare(file1, file2);
Comparator executes without error, but all I see in the log is just saying there is data mismatch (see screenshot)
Is it all I should be hoping for?
I expected images of both files with highlighted regions showing where exactly mismatch is
Best regards,
Andrey
Best answer by abaranovhs
The issue I found is because TestSDK Comparator class “saves” result of comparison using Dummy method
I created my own class that runs report(s) and takes screenshot if PDF differs from the baseline file.
Putting code here just in case if someone else wants it (note, this requires installing Ghostscript on the computer where test runs, and specifying its location using MagicNET.SetGhostScriptDirectory method):
public class RunReport : Wrappers.ReportLauncher { public RunReport(string screenID) { base.ScreenId = screenID; base.ScreenUrl = $"/frames/reportlauncher.aspx?id={screenID}.rpx"; ToolBar = new PxToolBar(null); }
public c_parameters ReportParameters => Parameters;
var mi1 = new MagickImage(file1, MagickFormat.Pdf); var mi2 = new MagickImage(file2, MagickFormat.Pdf);
bool differencesFound = false;
using (var diffImage = new MagickImage() { ColorFuzz = new Percentage(10) }) { differencesFound = mi1.Compare(mi2, new CompareSettings() { Metric = ErrorMetric.Absolute }, diffImage) > 0; diffImage.Write(outputPicturePath, format: MagickFormat.Png); // Save the diff image to disk }
if (differencesFound) { Browser.WebDriver.Navigate().GoToUrl(outputPicturePath); Log.Error("Differences found"); } else { Log.Information($"Files are identical"); }
[TestDescription("\r\nThis test runs varios reports and compares them with the baseline pre-saved files")] internal class TestPDFReports : CheckExt { private string description;
//Specify path to the file saved in HSAutomatedTests project folder, that will be used as a baseline to compare generated report to string baselineFileName = @"ReportBaseLines\SO642003_689455.pdf";
//Specify path to the file saved in HSAutomatedTests project folder, that will be used as a baseline to compare generated report to string baselineFileName = @"ReportBaseLines\SO642003_689445.pdf";
The issue I found is because TestSDK Comparator class “saves” result of comparison using Dummy method
I created my own class that runs report(s) and takes screenshot if PDF differs from the baseline file.
Putting code here just in case if someone else wants it (note, this requires installing Ghostscript on the computer where test runs, and specifying its location using MagicNET.SetGhostScriptDirectory method):
public class RunReport : Wrappers.ReportLauncher { public RunReport(string screenID) { base.ScreenId = screenID; base.ScreenUrl = $"/frames/reportlauncher.aspx?id={screenID}.rpx"; ToolBar = new PxToolBar(null); }
public c_parameters ReportParameters => Parameters;
var mi1 = new MagickImage(file1, MagickFormat.Pdf); var mi2 = new MagickImage(file2, MagickFormat.Pdf);
bool differencesFound = false;
using (var diffImage = new MagickImage() { ColorFuzz = new Percentage(10) }) { differencesFound = mi1.Compare(mi2, new CompareSettings() { Metric = ErrorMetric.Absolute }, diffImage) > 0; diffImage.Write(outputPicturePath, format: MagickFormat.Png); // Save the diff image to disk }
if (differencesFound) { Browser.WebDriver.Navigate().GoToUrl(outputPicturePath); Log.Error("Differences found"); } else { Log.Information($"Files are identical"); }
[TestDescription("\r\nThis test runs varios reports and compares them with the baseline pre-saved files")] internal class TestPDFReports : CheckExt { private string description;
//Specify path to the file saved in HSAutomatedTests project folder, that will be used as a baseline to compare generated report to string baselineFileName = @"ReportBaseLines\SO642003_689455.pdf";
//Specify path to the file saved in HSAutomatedTests project folder, that will be used as a baseline to compare generated report to string baselineFileName = @"ReportBaseLines\SO642003_689445.pdf";