diff --git a/src/Atata.Tests/UITestFixture.cs b/src/Atata.Tests/UITestFixture.cs index 25bd1817..cbf19a90 100644 --- a/src/Atata.Tests/UITestFixture.cs +++ b/src/Atata.Tests/UITestFixture.cs @@ -9,8 +9,8 @@ public abstract class UITestFixture { private StringListLogConsumer stringListLogConsumer; - public IEnumerable LogEntries => stringListLogConsumer.Items; - + public IEnumerable LogEntries => stringListLogConsumer.Items; + [SetUp] public void SetUp() { @@ -18,7 +18,7 @@ public void SetUp() stringListLogConsumer = new StringListLogConsumer(); - AtataContext.Build(). + AtataContext.Configure(). UseChrome(). WithArguments("disable-extensions", "no-sandbox", "start-maximized"). UseBaseUrl(baseUrl). diff --git a/src/Atata/Context/AtataBuildingContext.cs b/src/Atata/Context/AtataBuildingContext.cs index 85aab5dc..37d45f20 100644 --- a/src/Atata/Context/AtataBuildingContext.cs +++ b/src/Atata/Context/AtataBuildingContext.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; +using System.Linq; namespace Atata { - public class AtataBuildingContext + public class AtataBuildingContext : ICloneable { internal AtataBuildingContext() { @@ -43,5 +44,26 @@ internal AtataBuildingContext() /// Gets or sets the type of the assertion exception. The default value is typeof(Atata.AssertionException). /// public Type AssertionExceptionType { get; set; } = typeof(AssertionException); + + object ICloneable.Clone() + { + return Clone(); + } + + /// + /// Creates a copy of the current instance. + /// + /// The copied instance. + public AtataBuildingContext Clone() + { + AtataBuildingContext copy = (AtataBuildingContext)MemberwiseClone(); + + copy.DriverFactories = DriverFactories.ToList(); + copy.LogConsumers = LogConsumers.ToList(); + copy.ScreenshotConsumers = ScreenshotConsumers.ToList(); + copy.CleanUpActions = CleanUpActions.ToList(); + + return copy; + } } } diff --git a/src/Atata/Context/AtataContext.cs b/src/Atata/Context/AtataContext.cs index d793e32a..34c5ce13 100644 --- a/src/Atata/Context/AtataContext.cs +++ b/src/Atata/Context/AtataContext.cs @@ -31,6 +31,11 @@ public static AtataContext Current internal set { current = value; } } + /// + /// Gets the global configuration. + /// + public static AtataContextBuilder GlobalConfiguration { get; } = new AtataContextBuilder(new AtataBuildingContext()); + /// /// Gets the build start date and time. Contains the same value for all the tests being executed within one build. /// @@ -91,9 +96,20 @@ public ReadOnlyCollection TemporarilyPreservedPageObjects get { return TemporarilyPreservedPageObjectList.ToReadOnly(); } } + [Obsolete("Use Configure() instead.")] // Obsolete since v0.14.0. public static AtataContextBuilder Build() { - return new AtataContextBuilder(new AtataBuildingContext()); + return Configure(); + } + + /// + /// Creates instance for configuration. Sets the value to copied from . + /// + /// The created instance. + public static AtataContextBuilder Configure() + { + AtataBuildingContext buildingContext = GlobalConfiguration.BuildingContext.Clone(); + return new AtataContextBuilder(buildingContext); } internal static void InitGlobalVariables() diff --git a/src/Atata/Go.cs b/src/Atata/Go.cs index bea019b5..0bff13b9 100644 --- a/src/Atata/Go.cs +++ b/src/Atata/Go.cs @@ -93,8 +93,7 @@ public static T ToPreviousWindow(T pageObject = null, bool temporarily = fals private static T To(T pageObject, GoOptions options) where T : PageObject { - if (AtataContext.Current == null) - AtataContext.Build().SetUp(); + CheckAtataContext(); if (AtataContext.Current.PageObject == null) { @@ -123,8 +122,7 @@ private static T To(T pageObject, GoOptions options) /// The URL. public static void ToUrl(string url) { - if (AtataContext.Current == null) - AtataContext.Build().SetUp(); + CheckAtataContext(); Uri absoluteUri; @@ -156,6 +154,12 @@ public static void ToUrl(string url) Navigate(absoluteUri); } + private static void CheckAtataContext() + { + if (AtataContext.Current == null) + AtataContext.Configure().SetUp(); + } + private static void Navigate(Uri uri) { AtataContext.Current.Log.Info($"Go to URL \"{uri}\"");