private TestResult GetTestResult(byte[] image, ScreenshotIdentity screenshotIdentity, BrowserPattern browserPattern, BrowserPattern newPattern) { var testResult = new TestResult { Pattern = newPattern ?? browserPattern, ScreenshotName = screenshotIdentity.ScreenshotName, Category = screenshotIdentity.Category, BrowserName = screenshotIdentity.BrowserName }; if (newPattern != null) { testResult.Status = TestResultStatus.NewPattern; } else if (browserPattern.MatchTo(image)) { testResult.Status = TestResultStatus.Passed; } else { testResult.Status = TestResultStatus.Failed; testResult.ErrorScreenshot = image; testResult.BlindRegionsSnapshot = browserPattern.GetCopyOfAllBlindRegions(); } return(testResult); }
private void CheckScreenshotWithPattern(Screenshot screenshot) { if (screenshot == null) { throw new ArgumentNullException(nameof(screenshot)); } byte[] image = screenshot.Data; ScreenshotIdentity screenshotIdentity = screenshot.Identity; try { Action finishNotification; using (var transaction = PersistanceEngine.GetSession().BeginTransaction()) { var project = this.GetProject(screenshotIdentity.ProjectName); var testCase = GetTestCase(project, screenshotIdentity); var activePattern = testCase.GetActivePatternForBrowser(screenshotIdentity.BrowserName); var newPattern = activePattern == null?testCase.AddNewPattern(image, screenshotIdentity.BrowserName) : null; var testResult = GetTestResult(image, screenshotIdentity, activePattern, newPattern); var testSession = GetCurrentTestSession(project); testSession.AddTestResult(testResult); finishNotification = () => { switch (testResult.Status) { case TestResultStatus.Failed: testRunnerAdapter.NotifyAboutTestFail(screenshotIdentity.FullName, testSession, activePattern, testResult.TestResultMessage); break; case TestResultStatus.Passed: testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, activePattern, testResult.TestResultMessage); break; case TestResultStatus.NewPattern: testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, newPattern, testResult.TestResultMessage); break; default: throw new ArgumentOutOfRangeException(); } }; transaction.Commit(); } finishNotification.Invoke(); } catch (Exception ex) { testRunnerAdapter.NotifyAboutError(ex); } }
public void CheckViewWithPattern(IBrowserCamera browserCamera, string viewName) { var screenshotIdentity = new ScreenshotIdentity(ProjectName, BrowserName, ScreenshotCategory, viewName); if (takenScreenshots.Contains(screenshotIdentity)) { throw new DuplicatedScreenshotInSession(screenshotIdentity); } var screenshot = browserCamera.TakeScreenshot(); takenScreenshots.Add(screenshotIdentity); CheckScreenshotWithPattern(screenshot, screenshotIdentity); }
private static TestCase GetTestCase(Project project, ScreenshotIdentity screenshotIdentity) { var testCaseCategory = project.TestCaseCategories.FirstOrDefault(x => x.Name == screenshotIdentity.Category); if (testCaseCategory == null) { testCaseCategory = project.AddTestCaseCategory(screenshotIdentity.Category); } var testCase = testCaseCategory.TestCases.FirstOrDefault(x => x.PatternScreenshotName == screenshotIdentity.ScreenshotName); if (testCase == null) { testCase = testCaseCategory.AddTestCase(screenshotIdentity.ScreenshotName); } return(testCase); }
private void CheckScreenshotWithPattern(byte[] image, ScreenshotIdentity screenshotIdentity) { try { Action finishNotification; using (var tx = PersistanceEngine.GetSession().BeginTransaction()) { var project = this.GetProject(screenshotIdentity.ProjectName); var testCase = GetTestCase(project, screenshotIdentity); var browserPattern = testCase.GetActivePatternForBrowser(screenshotIdentity.BrowserName); var testSession = GetCurrentTestSession(project); if (browserPattern == null) { var newPattern = testCase.AddNewPattern(image, screenshotIdentity.BrowserName); finishNotification = () => testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, newPattern); } else { var testResult = GetTestResult(image, screenshotIdentity, browserPattern); testSession.AddTestResult(testResult); finishNotification = () => { if (testResult.TestPassed) { testRunnerAdapter.NotifyAboutTestSuccess(screenshotIdentity.FullName, testSession, browserPattern); } else { testRunnerAdapter.NotifyAboutTestFail(screenshotIdentity.FullName, testSession, browserPattern); } }; } tx.Commit(); } finishNotification.Invoke(); } catch (Exception ex) { testRunnerAdapter.NotifyAboutError(ex); } }
private TestResult GetTestResult(byte[] image, ScreenshotIdentity screenshotIdentity, BrowserPattern browserPattern, BrowserPattern newPattern) { if (image == null) { throw new ArgumentNullException(nameof(image)); } if (screenshotIdentity == null) { throw new ArgumentNullException(nameof(screenshotIdentity)); } var testResult = new TestResult { Pattern = newPattern ?? browserPattern, ScreenshotName = screenshotIdentity.ScreenshotName, Category = screenshotIdentity.Category, BrowserName = screenshotIdentity.BrowserName }; if (newPattern != null) { testResult.Status = TestResultStatus.NewPattern; } var comparisonResult = screenshotComparisonStrategy.Compare(browserPattern, image, out var message); testResult.TestResultMessage = message; if (comparisonResult) { testResult.Status = TestResultStatus.Passed; } else { testResult.Status = TestResultStatus.Failed; testResult.ErrorScreenshot = image; testResult.BlindRegionsSnapshot = browserPattern.GetCopyOfAllBlindRegions(); } return(testResult); }
private TestResult GetTestResult(byte[] image, ScreenshotIdentity screenshotIdentity, BrowserPattern browserPattern) { var testResult = new TestResult { Pattern = browserPattern, ScreenshotName = screenshotIdentity.ScreenshotName, Category = screenshotIdentity.Category, BrowserName = screenshotIdentity.BrowserName }; if (browserPattern.MatchTo(image)) { testResult.TestPassed = true; } else { testResult.TestPassed = false; testResult.ErrorScreenshot = image; testResult.BlindRegionsSnapshot = browserPattern.GetCopyOfAllBlindRegions(); } return(testResult); }
public DuplicatedScreenshotInSession(ScreenshotIdentity screenshotIdentity) { this.screenshotIdentity = screenshotIdentity; }