public void Before() { var screenshotName = Context.ScenarioInfo.Title; #if DEBUG var delay = IsLiveUnitTesting ? TimeSpan.Zero : TimeSpan.FromSeconds(1); #else var delay = TimeSpan.Zero; #endif if (IsLiveUnitTesting) { delay = TimeSpan.Zero; } var actorSource = new Actor("John"); IActorFacade actor = actorSource; if (TestLevel == TestLevel.UI) { var driver = CreateWebDriver(); actor = actorSource.WithSeleniumReporting( new SeleniumReportingConfiguration( GetScreenshotsPath(), screenshotName) .AddTextObservers(new DebugObserver()) .WithCanNotify(new CanNotify()) .WithScreenshotPng() .WithTakeScreenshotStrategy(new TakeScreenshotOnErrorStrategy()), out var seleniumReporter) .HighlightTargets() .SlowSelenium(delay) .CanUse(seleniumReporter) .CanUse(WebBrowser.With(driver)); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); Context.Set(driver); } // Indicates what level of automation is supported by the current scenario var levels = new[] { TestLevel.UI, TestLevel.Api }.Where(l => l >= TestLevel).ToArray(); actor = actor.CanUse <IActionTags <TestLevel> >(ActionTags.Create(levels)) .CanUse(ClientFactory()); Context.Set(actor); if (TestLevel == TestLevel.UI) { actor.Given(Open.TheApplication()); } }
/// <summary> /// Give an ability to the actor if the predicate is true /// </summary> /// <typeparam name="T">The type of the ability</typeparam> /// <param name="actor"></param> /// <param name="doSomething">Ability</param> /// <param name="predicate">A value indicating if the ability should be added</param> /// <returns>A new actor with the given ability</returns> public static IActorFacade CanUseIf <T>(this IActorFacade actor, Func <T> doSomething, bool predicate) where T : class { if (actor is null) { throw new ArgumentNullException(nameof(actor)); } if (doSomething is null) { throw new ArgumentNullException(nameof(doSomething)); } if (predicate) { return(actor.CanUse(doSomething())); } return(actor); }