Skip to content

Commit

Permalink
#74 AtataContext global configuration; #73 Rename Build method of Ata…
Browse files Browse the repository at this point in the history
…taContext to Configure
  • Loading branch information
YevgeniyShunevych committed Sep 15, 2017
1 parent e36fc63 commit 90f3852
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Atata.Tests/UITestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ public abstract class UITestFixture
{
private StringListLogConsumer stringListLogConsumer;

public IEnumerable<LogEventInfo> LogEntries => stringListLogConsumer.Items;

public IEnumerable<LogEventInfo> LogEntries => stringListLogConsumer.Items;

[SetUp]
public void SetUp()
{
string baseUrl = ConfigurationManager.AppSettings["TestAppUrl"];

stringListLogConsumer = new StringListLogConsumer();

AtataContext.Build().
AtataContext.Configure().
UseChrome().
WithArguments("disable-extensions", "no-sandbox", "start-maximized").
UseBaseUrl(baseUrl).
Expand Down
24 changes: 23 additions & 1 deletion src/Atata/Context/AtataBuildingContext.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atata
{
public class AtataBuildingContext
public class AtataBuildingContext : ICloneable
{
internal AtataBuildingContext()
{
Expand Down Expand Up @@ -43,5 +44,26 @@ internal AtataBuildingContext()
/// Gets or sets the type of the assertion exception. The default value is typeof(Atata.AssertionException).
/// </summary>
public Type AssertionExceptionType { get; set; } = typeof(AssertionException);

object ICloneable.Clone()
{
return Clone();
}

/// <summary>
/// Creates a copy of the current instance.
/// </summary>
/// <returns>The copied <see cref="AtataBuildingContext"/> instance.</returns>
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;
}
}
}
18 changes: 17 additions & 1 deletion src/Atata/Context/AtataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public static AtataContext Current
internal set { current = value; }
}

/// <summary>
/// Gets the global configuration.
/// </summary>
public static AtataContextBuilder GlobalConfiguration { get; } = new AtataContextBuilder(new AtataBuildingContext());

/// <summary>
/// Gets the build start date and time. Contains the same value for all the tests being executed within one build.
/// </summary>
Expand Down Expand Up @@ -91,9 +96,20 @@ public ReadOnlyCollection<UIComponent> 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();
}

/// <summary>
/// Creates <see cref="AtataContextBuilder"/> instance for <see cref="AtataContext"/> configuration. Sets the value to <see cref="AtataContextBuilder.BuildingContext"/> copied from <see cref="GlobalConfiguration"/>.
/// </summary>
/// <returns>The created <see cref="AtataContextBuilder"/> instance.</returns>
public static AtataContextBuilder Configure()
{
AtataBuildingContext buildingContext = GlobalConfiguration.BuildingContext.Clone();
return new AtataContextBuilder(buildingContext);
}

internal static void InitGlobalVariables()
Expand Down
12 changes: 8 additions & 4 deletions src/Atata/Go.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public static T ToPreviousWindow<T>(T pageObject = null, bool temporarily = fals
private static T To<T>(T pageObject, GoOptions options)
where T : PageObject<T>
{
if (AtataContext.Current == null)
AtataContext.Build().SetUp();
CheckAtataContext();

if (AtataContext.Current.PageObject == null)
{
Expand Down Expand Up @@ -123,8 +122,7 @@ private static T To<T>(T pageObject, GoOptions options)
/// <param name="url">The URL.</param>
public static void ToUrl(string url)
{
if (AtataContext.Current == null)
AtataContext.Build().SetUp();
CheckAtataContext();

Uri absoluteUri;

Expand Down Expand Up @@ -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}\"");
Expand Down

0 comments on commit 90f3852

Please sign in to comment.