Example #1
0
        /// <summary>
        /// Configure the actor for Selenium reporting and returns an object that allows to retrieve the report. This is similar to using:
        /// - <see cref="Tranquire.ActorExtensions.WithReporting(Actor, IObserver{Reporting.ActionNotification}, ICanNotify)"/>
        /// - <see cref="TakeScreenshots(Actor, string, IObserver{ScreenshotInfo}, ITakeScreenshotStrategy)"/>
        /// </summary>
        /// <param name="actor">The actor</param>
        /// <param name="configuration">The reporting configuration</param>
        /// <param name="seleniumReporter">A <see cref="ISeleniumReporter"/> object that can be used to save the screenshots and retrieve the report at the end of the run</param>
        /// <returns></returns>
        public static Actor WithSeleniumReporting(
            this Actor actor,
            SeleniumReportingConfiguration configuration,
            out ISeleniumReporter seleniumReporter)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var xmlDocumentObserver = new XmlDocumentObserver();
            var textObservers       = new CompositeObserver <string>(configuration.TextOutputObservers.ToArray());
            var reportingObserver   = new CompositeObserver <ActionNotification>(
                xmlDocumentObserver,
                new RenderedReportingObserver(textObservers, RenderedReportingObserver.DefaultRenderer)
                );
            var saveScreenshotObserver = new SaveScreenshotsToFileOnComplete(configuration.ScreenshotDirectory);
            var screenshotObserver     = new CompositeObserver <ScreenshotInfo>(
                saveScreenshotObserver,
                new ScreenshotInfoToActionAttachmentObserverAdapter(xmlDocumentObserver),
                new RenderedScreenshotInfoObserver(textObservers)
                );

            seleniumReporter = new SeleniumReporter(xmlDocumentObserver, saveScreenshotObserver);
            return(configuration.ApplyWithReporting(actor, reportingObserver)
                   .TakeScreenshots(configuration.ScreenshotNameOrFormat,
                                    screenshotObserver,
                                    configuration.TakeScreenshotStrategy));
        }
Example #2
0
 public static void AfterScenario()
 {
     if (ScenarioContext.Current.TestError != null)
     {
         SeleniumReporter.TakeScreenshot(TestContext.CurrentContext.Test.Name);
     }
 }
Example #3
0
 public void SaveScreenshots_ShouldCallOnCompleted(
     SeleniumReporter sut)
 {
     // arrange
     // act
     sut.SaveScreenshots();
     // assert
     Mock.Get(sut.ScreenshotInfoObserver).Verify(s => s.OnCompleted());
 }
Example #4
0
        private static void TestWithSeleniumReporting(
            ISeleniumReporter actualSeleniumReporter,
            Actor actual,
            Actor actor,
            IActor iactor,
            string screenshotDirectory,
            string screenshotName,
            IObserver <string>[] observers,
            ICanNotify canNotify,
            ITakeScreenshotStrategy takeScreenshotStrategy)
        {
            // assert
            var xmlDocumentObserver    = new XmlDocumentObserver();
            var takeScreenshot         = actual.InnerActorBuilder(iactor).Should().BeOfType <TakeScreenshot>().Which;
            var expectedTakeScreenshot = ActorExtensions.TakeScreenshots(
                actor,
                screenshotName,
                new CompositeObserver <ScreenshotInfo>(
                    new ScreenshotInfoToActionAttachmentObserverAdapter(xmlDocumentObserver),
                    new RenderedScreenshotInfoObserver(new CompositeObserver <string>(observers)),
                    new SaveScreenshotsToFileOnComplete(screenshotDirectory)
                    ),
                takeScreenshotStrategy
                )
                                         .InnerActorBuilder(iactor) as TakeScreenshot;

            takeScreenshot.Should().BeEquivalentTo(expectedTakeScreenshot, o => o.Excluding(a => a.Actor)
                                                   .Excluding(a => a.NextScreenshotName)
                                                   .RespectingRuntimeTypes());
            var actualScreenshotNames   = Enumerable.Range(0, 10).Select(_ => takeScreenshot.NextScreenshotName());
            var expectedScreenshotNames = Enumerable.Range(0, 10).Select(_ => expectedTakeScreenshot.NextScreenshotName());

            actualScreenshotNames.Should().BeEquivalentTo(expectedScreenshotNames);

            var reportingActor         = takeScreenshot.Actor.Should().BeOfType <ReportingActor>().Which;
            var expectedReportingActor = actor.WithReporting(
                new CompositeObserver <ActionNotification>(
                    xmlDocumentObserver,
                    new RenderedReportingObserver(
                        new CompositeObserver <string>(observers),
                        RenderedReportingObserver.DefaultRenderer
                        )
                    ),
                canNotify
                )
                                         .InnerActorBuilder(iactor) as ReportingActor;

            reportingActor.Should().BeEquivalentTo(expectedReportingActor, o => o.Excluding(a => a.Actor)
                                                   .Excluding(a => a.MeasureTime.Now)
                                                   .Excluding((IMemberInfo m) => m.RuntimeType == typeof(DateTimeOffset))
                                                   .RespectingRuntimeTypes());

            var expectedSeleniumReporter = new SeleniumReporter(xmlDocumentObserver, new SaveScreenshotsToFileOnComplete(screenshotDirectory));

            actualSeleniumReporter.Should().BeEquivalentTo(expectedSeleniumReporter, o => o.Excluding((IMemberInfo m) => m.RuntimeType == typeof(DateTimeOffset)));
        }
Example #5
0
 public void ScreenshotReport()
 {
     if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
     {
         SeleniumReporter.TakeScreenshot(driver, TestContext.CurrentContext.Test.Name);
     }
     else
     {
         SeleniumReporter.DeleteScreenshotIfExist(TestContext.CurrentContext.Test.Name);
     }
 }
Example #6
0
 public void ScreenshotReport()
 {
     if (TestContext.CurrentContext.Result.FailCount > 0)
     {
         //SeleniumReporter.TakeScreenshot(driver, TestContext.CurrentContext.Test.FullName.Remove(0,26)); // removing project name part
     }
     else
     {
         SeleniumReporter.DeleteScreenshotIfExist(SeleniumReporter.GetScreenshotFullPath(TestContext.CurrentContext.Test.FullName.Remove(0, 26)));
     }
 }
Example #7
0
        public void GetHtmlDocument_ShouldReturnCorrectValue(
            SeleniumReporter sut,
            [Greedy] XmlDocumentObserver expectedDocumentObserver,
            INamed named)
        {
            // arrange

            SetupObserver(expectedDocumentObserver, named);
            SetupObserver(sut.XmlDocumentObserver, named);
            var expected = expectedDocumentObserver.GetHtmlDocument();
            // act
            var actual = sut.GetHtmlDocument();

            // assert
            actual.Should().Be(expected);
        }
Example #8
0
        public void DownloadAndroidAppVersion()
        {
            AppVersion.Platform = "android";

            SeleniumExecutor.BaseSetUp();
            executor = SeleniumExecutor.GetExecutor();
            executor.OpenPage(SeleniumExecutor.pageDefaultUrl);
            volotea = new HockeyAppPage(executor);

            volotea.FillUserCredentialFields(TestConfiguration.LoginToAccount, TestConfiguration.PasswordToAccount).
            ClickSignInButton().
            SelectAndroidPlatform().
            ClickOnAppVersion("PX-633");
            SeleniumReporter.TakeScreenshot(SeleniumExecutor.GetDriver());
            volotea.ClickDownloadButton();

            executor.BaseTearDown();
        }
Example #9
0
 public void Sut_IsSeleniumReporter(SeleniumReporter sut)
 {
     sut.Should().BeAssignableTo <ISeleniumReporter>();
 }