private void Checkpoint() { if (mEyes == null) { mAct.Error = "Applitools Eyes is not opened"; mAct.ExInfo = "You require to add Eyes.Open Action on step before."; return; } SetEyesMatchLevel(); AppImage response = mEyes.CheckImage(mDriver.GetScreenShot()); mAct.AddOrUpdateReturnParamActual("ExactMatches", response.IsMatch.ToString()); bool FailActionOnMistmach = Boolean.Parse(mAct.GetInputParamValue(ApplitoolsAnalyzer.FailActionOnMistmach)); if (response.IsMatch == true || !FailActionOnMistmach) { mAct.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed; if (!FailActionOnMistmach) { mAct.ExInfo = "Created new baseline in Applitools or Mismatch between saved baseline and target checkpoint image"; } } else if (response.IsMatch == false) { mAct.Error = "Created new baseline in Applitools or Mismatch between saved baseline and target checkpoint image"; } }
void IVisualAnalyzer.Compare() { MagickImage magickBaseImg = new MagickImage(mAct.baseImage); MagickImage magickTargetImg = new MagickImage(mAct.targetImage); var diffImg = new MagickImage(); double percentageDifference; // TODO: add combo with list of options for user to choose the Error Matic and Cahnnels ActInputValue AIV = mAct.GetOrCreateInputParam(ActVisualTesting.Fields.ErrorMetric); //TODO: fix me - removed hard code //caused build problem on build machine so temp fix for now ErrorMetric EM = ErrorMetric.Fuzz; percentageDifference = magickBaseImg.Compare(magickTargetImg, EM, diffImg, Channels.Red); percentageDifference = percentageDifference * 100; percentageDifference = Math.Round(percentageDifference, 2); Bitmap ImgToSave = diffImg.ToBitmap(); mAct.CompareResult = ImgToSave; mAct.AddOrUpdateReturnParamActual("Percentage Difference", percentageDifference + ""); mAct.AddScreenShot(ImgToSave, "Compare Result"); }
void IVisualAnalyzer.Compare() { //TODO: use interface on the driver to get elements if (mDriver is IVisualTestingDriver) { IVisualTestingDriver d = (IVisualTestingDriver)mDriver; string filename = mAct.GetFullFilePath(mAct.BaselineInfoFile); VisualElementsInfo VE1 = VisualElementsInfo.Load(filename); VE1.Bitmap = mAct.baseImage; VisualElementsInfo VE2 = d.GetVisualElementsInfo(); VE1.Compare(VE2); IEnumerable <VisualElement> listwithnomatch = from x in VE1.Elements where x.Text != "" && x.MatchingElement == null select x; // Create compare bitmap for VE1 Bitmap bmp = new Bitmap(VE1.Bitmap); // mark element with no match foreach (VisualElement VE in listwithnomatch) { using (Graphics gr = Graphics.FromImage(bmp)) { gr.SmoothingMode = SmoothingMode.AntiAlias; //TODO: check the -3 or + 6 will not go out of bitmap Rectangle rect = new Rectangle(VE.X - 3, VE.Y - 3, VE.Width + 6, VE.Height + 6); gr.FillRectangle(Brushes.Transparent, rect); using (Pen thick_pen = new Pen(Color.HotPink, 2)) { gr.DrawRectangle(thick_pen, rect); } } } mAct.CompareResult = bmp; // Add output of mismatch mAct.AddOrUpdateReturnParamActual("Mismatch elements in target", listwithnomatch.Count() + ""); //TODO: if output each mismatch then do output mAct.AddScreenShot(bmp, "Compare Result"); //TODO: add small bitmap of mismatch elem } }
private void CloseEyes() { try { TestResults TR = mEyes.Close(false); // Update results info into outputs SaveApplitoolsImages(TR); mAct.ExInfo = "URL to view results: " + TR.Url; mAct.AddOrUpdateReturnParamActual("ResultsURL", TR.Url + ""); mAct.AddOrUpdateReturnParamActual("Steps", TR.Steps + ""); mAct.AddOrUpdateReturnParamActual("Mismatches", TR.Mismatches + ""); mAct.AddOrUpdateReturnParamActual("ExactMatches", TR.ExactMatches + ""); mAct.AddOrUpdateReturnParamActual("StrictMatches", TR.StrictMatches + ""); mAct.AddOrUpdateReturnParamActual("ContentMatches", TR.ContentMatches + ""); mAct.AddOrUpdateReturnParamActual("LayoutMatches", TR.LayoutMatches + ""); mAct.AddOrUpdateReturnParamActual("ExactMatches", TR.ExactMatches + ""); mAct.AddOrUpdateReturnParamActual("IsNew", TR.IsNew + ""); if (!TR.IsNew) { foreach (StepInfo step in TR.StepsInfo) { if (!step.HasCurrentImage) { mAct.AddOrUpdateReturnParamActual(step.Name, "Failed with Missing Image" + ""); } else { mAct.AddOrUpdateReturnParamActual(step.Name, step.IsDifferent ? "Failed" : "Passed" + ""); } } } mAct.AddOrUpdateReturnParamActual("IsNew", TR.IsNew + ""); if ((TR.Mismatches == 0 || TR.IsNew) && TR.Missing == 0) { mAct.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Passed; if (TR.IsNew) { mAct.ExInfo = "Created new baseline in Applitools."; } else { mAct.ExInfo = TR.Matches + " steps Matched with saved baseline in Applitools."; } } else { mAct.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; if (TR.Mismatches != 0) { mAct.Error = TR.Mismatches + " steps Mismatched with saved baseline image in Applitools. "; } if (TR.Missing != 0) { mAct.Error += TR.Missing + " steps missing current images."; } } } catch (Exception ex) { mAct.Error += "Eyes Close operation failed, Error: " + ex.Message; } finally { mEyes.AbortIfNotClosed(); } }