Skip to content

Commit

Permalink
#159 Add ClickAndGo method to Control<TOwner>
Browse files Browse the repository at this point in the history
  • Loading branch information
YevgeniyShunevych committed Mar 20, 2018
1 parent 2f327d6 commit 9848feb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
53 changes: 45 additions & 8 deletions src/Atata/Components/Control`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ protected virtual bool GetIsEnabled()
}

/// <summary>
/// Clicks the control. Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers.
/// Clicks the control.
/// Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers.
/// </summary>
/// <returns>The instance of the owner page object.</returns>
public TOwner Click()
Expand All @@ -48,7 +49,37 @@ protected virtual void OnClick()
}

/// <summary>
/// Hovers the control. Also executes <see cref="TriggerEvents.BeforeHover" /> and <see cref="TriggerEvents.AfterHover" /> triggers.
/// Clicks the control and performs the navigation to the page object of <typeparamref name="TNavigateTo"/> type.
/// Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers.
/// </summary>
/// <typeparam name="TNavigateTo">The type of the page object to navigate to.</typeparam>
/// <param name="navigateToPageObject">The page object instance to navigate to.</param>
/// <param name="temporarily">If set to <c>true</c> navigates temporarily preserving current page object state. If is not set, checks <see cref="GoTemporarilyAttribute"/>.</param>
/// <returns>The instance of <typeparamref name="TNavigateTo"/>.</returns>
public TNavigateTo ClickAndGo<TNavigateTo>(TNavigateTo navigateToPageObject = null, bool? temporarily = null)
where TNavigateTo : PageObject<TNavigateTo>
{
Click();

return OnGo(navigateToPageObject, temporarily);
}

protected virtual TNavigateTo OnGo<TNavigateTo>(TNavigateTo navigateToPageObject = null, bool? temporarily = null)
where TNavigateTo : PageObject<TNavigateTo>
{
bool isTemporarily = temporarily
?? Metadata.Get<GoTemporarilyAttribute>(AttributeLevels.DeclaredAndComponent)?.IsTemporarily
?? false;

TNavigateTo pageObject = navigateToPageObject
?? (TNavigateTo)Metadata.Get<NavigationPageObjectCreatorAttribute>(AttributeLevels.DeclaredAndComponent)?.Creator?.Invoke();

return Go.To(pageObject: pageObject, navigate: false, temporarily: isTemporarily);
}

/// <summary>
/// Hovers the control.
/// Also executes <see cref="TriggerEvents.BeforeHover" /> and <see cref="TriggerEvents.AfterHover" /> triggers.
/// </summary>
/// <returns>The instance of the owner page object.</returns>
public TOwner Hover()
Expand All @@ -70,7 +101,8 @@ protected virtual void OnHover()
}

/// <summary>
/// Focuses the control. Also executes <see cref="TriggerEvents.BeforeFocus" /> and <see cref="TriggerEvents.AfterFocus" /> triggers.
/// Focuses the control.
/// Also executes <see cref="TriggerEvents.BeforeFocus" /> and <see cref="TriggerEvents.AfterFocus" /> triggers.
/// </summary>
/// <returns>The instance of the owner page object.</returns>
public TOwner Focus()
Expand All @@ -92,7 +124,8 @@ protected virtual void OnFocus()
}

/// <summary>
/// Double-clicks the control. Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers.
/// Double-clicks the control.
/// Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers.
/// </summary>
/// <returns>The instance of the owner page object.</returns>
public TOwner DoubleClick()
Expand All @@ -114,7 +147,8 @@ protected virtual void OnDoubleClick()
}

/// <summary>
/// Right-clicks the control. Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers.
/// Right-clicks the control.
/// Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers.
/// </summary>
/// <returns>The instance of the owner page object.</returns>
public TOwner RightClick()
Expand All @@ -136,7 +170,8 @@ protected virtual void OnRightClick()
}

/// <summary>
/// Drags and drops the control to the target control returned by <paramref name="targetSelector"/>. By default uses <see cref="DragAndDropUsingActionsAttribute"/>.
/// Drags and drops the control to the target control returned by <paramref name="targetSelector"/>.
/// By default uses <see cref="DragAndDropUsingActionsAttribute"/>.
/// Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers.
/// </summary>
/// <param name="targetSelector">The target control selector.</param>
Expand All @@ -151,7 +186,8 @@ public TOwner DragAndDropTo(Func<TOwner, Control<TOwner>> targetSelector)
}

/// <summary>
/// Drags and drops the control to the target control. By default uses <see cref="DragAndDropUsingActionsAttribute"/>.
/// Drags and drops the control to the target control.
/// By default uses <see cref="DragAndDropUsingActionsAttribute"/>.
/// Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers.
/// </summary>
/// <param name="target">The target control.</param>
Expand Down Expand Up @@ -205,7 +241,8 @@ protected virtual void OnDragAndDropToOffset(int offsetX, int offsetY)
}

/// <summary>
/// Scrolls to the control. By default uses <see cref="ScrollUsingMoveToElementAttribute"/> behavior.
/// Scrolls to the control.
/// By default uses <see cref="ScrollUsingMoveToElementAttribute"/> behavior.
/// Also executes <see cref="TriggerEvents.BeforeScroll" /> and <see cref="TriggerEvents.AfterScroll" /> triggers.
/// </summary>
/// <returns>The instance of the owner page object.</returns>
Expand Down
3 changes: 3 additions & 0 deletions src/Atata/Components/IControl`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public interface IControl<TOwner> : IUIComponent<TOwner>
{
TOwner Click();

TNavigateTo ClickAndGo<TNavigateTo>(TNavigateTo navigateToPageObject = null, bool? temporarily = null)
where TNavigateTo : PageObject<TNavigateTo>;

TOwner Hover();

TOwner Focus();
Expand Down
21 changes: 3 additions & 18 deletions src/Atata/Extensions/INavigableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;

namespace Atata
namespace Atata
{
public static class INavigableExtensions
{
/// <summary>
/// Clicks the control and performs the navigation to the page object of <typeparamref name="TNavigateTo"/> type.
/// Also executes <see cref="TriggerEvents.BeforeClick" /> and <see cref="TriggerEvents.AfterClick" /> triggers.
/// </summary>
/// <typeparam name="TNavigateTo">The type of the page object to navigate to.</typeparam>
/// <typeparam name="TOwner">The type of the owner page object.</typeparam>
Expand All @@ -15,21 +14,7 @@ public static TNavigateTo ClickAndGo<TNavigateTo, TOwner>(this INavigable<TNavig
where TNavigateTo : PageObject<TNavigateTo>
where TOwner : PageObject<TOwner>
{
navigableControl.Click();

bool temporarily = navigableControl.Metadata.
Get<GoTemporarilyAttribute>(AttributeLevels.DeclaredAndComponent)?.
IsTemporarily ?? false;

Func<object> navigationPageObjectCreator = navigableControl.Metadata.
Get<NavigationPageObjectCreatorAttribute>(AttributeLevels.DeclaredAndComponent)?.
Creator;

TNavigateTo pageObject = navigationPageObjectCreator != null
? (TNavigateTo)navigationPageObjectCreator()
: null;

return Go.To(pageObject: pageObject, navigate: false, temporarily: temporarily);
return navigableControl.ClickAndGo<TNavigateTo>();
}
}
}

0 comments on commit 9848feb

Please sign in to comment.