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
        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 #3
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 #4
0
        public void GetXmlDocument_ShouldReturnCorrectValue(
            [Frozen] IMeasureDuration measureDuration,
            [Greedy] XmlDocumentObserver expectedDocumentObserver,
            INamed named,
            IFixture fixture,
            DateTimeOffset date)
        {
            // arrange
            fixture.Customize <XmlDocumentObserver>(c => c.FromFactory(new MethodInvoker(new GreedyConstructorQuery())));
            var sut = fixture.Create <SeleniumReporter>();

            Mock.Get(measureDuration).Setup(m => m.Now).Returns(date);
            SetupObserver(expectedDocumentObserver, named);
            SetupObserver(sut.XmlDocumentObserver, named);
            var expected = expectedDocumentObserver.GetXmlDocument();
            // act
            var actual = sut.GetXmlDocument();

            // assert
            actual.ToString().Should().Be(expected.ToString());
        }
Example #5
0
 private static void SetupObserver(XmlDocumentObserver expectedDocumentObserver, INamed named)
 {
     expectedDocumentObserver.OnNext(new ActionNotification(named, 0, new BeforeActionNotificationContent(DateTimeOffset.MinValue, CommandType.Action)));
     expectedDocumentObserver.OnNext(new ActionNotification(named, 0, new AfterActionNotificationContent(TimeSpan.FromSeconds(1))));
 }
Example #6
0
 /// <inheritdoc />
 public XDocument GetXmlDocument()
 {
     return(XmlDocumentObserver.GetXmlDocument());
 }
Example #7
0
 /// <inheritdoc />
 public string GetHtmlDocument()
 {
     return(XmlDocumentObserver.GetHtmlDocument());
 }
Example #8
0
 /// <summary>
 /// Creates a new instance of <see cref="SeleniumReporter"/>
 /// </summary>
 /// <param name="xmlDocumentObserver"></param>
 /// <param name="screenshotInfoObserver"></param>
 public SeleniumReporter(XmlDocumentObserver xmlDocumentObserver, IObserver <ScreenshotInfo> screenshotInfoObserver)
 {
     XmlDocumentObserver    = xmlDocumentObserver ?? throw new ArgumentNullException(nameof(xmlDocumentObserver));
     ScreenshotInfoObserver = screenshotInfoObserver ?? throw new ArgumentNullException(nameof(screenshotInfoObserver));
 }
 public void Sut_IsActionFileAttachmentObserver(XmlDocumentObserver sut)
 {
     sut.Should().BeAssignableTo <IObserver <ActionFileAttachment> >();
 }
 public void Sut_IsActionNotificationObserver(XmlDocumentObserver sut)
 {
     sut.Should().BeAssignableTo <IObserver <ActionNotification> >();
 }