예제 #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));
        }
예제 #2
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)));
        }
예제 #3
0
        public static Actor WithSeleniumReporting(
            this Actor actor,
            string screenshotDirectory,
            string screenshotNameOrFormat,
            out ISeleniumReporter seleniumReporter,
            params IObserver <string>[] textOutputObservers)
        {
            var configuration = new SeleniumReportingConfiguration(screenshotDirectory, screenshotNameOrFormat)
                                .AddTextObservers(textOutputObservers);

            return(actor.WithSeleniumReporting(configuration, out seleniumReporter));
        }