Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-185: Improved ScrollTo() and ClickReliablyAsync() #199

Merged
merged 4 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,12 @@ private static async Task SetFieldDropdownByIndexAsync(UITestContext context, st

/// <summary>
/// A convenience method that merges <see cref="ElementRetrievalUITestContextExtensions.Get"/> and <see
/// cref="NavigationWebElementExtensions.ClickReliablyAsync(IWebElement,UITestContext)"/> so the <paramref
/// cref="NavigationWebElementExtensions.ClickReliablyAsync(IWebElement, UITestContext, int)"/> so the <paramref
/// name="context"/> doesn't have to be passed twice.
/// </summary>
public static Task ClickReliablyOnAsync(this UITestContext context, By by) => context.Get(by).ClickReliablyAsync(context);
/// <param name="maxTries">The maximum number of clicks attempted altogether, if retries are needed.</param>
public static Task ClickReliablyOnAsync(this UITestContext context, By by, int maxTries = 3) =>
context.Get(by).ClickReliablyAsync(context, maxTries);

/// <summary>
/// A convenience method that merges <see cref="ElementRetrievalUITestContextExtensions.Get"/> and <see
Expand Down
12 changes: 8 additions & 4 deletions Lombiq.Tests.UI/Extensions/NavigationWebElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using OpenQA.Selenium;
using System;
using System.Threading.Tasks;
using Xunit.Abstractions;

namespace Lombiq.Tests.UI.Extensions;

Expand All @@ -11,7 +12,7 @@ public static class NavigationWebElementExtensions
/// <summary>
/// Clicks an element even if the default Click() will sometimes fail to do so. It's more reliable than Click() but
/// still not perfect. If you're doing a Get() before then use <see
/// cref="NavigationUITestContextExtensions.ClickReliablyOnAsync(UITestContext, By)"/> instead.
/// cref="NavigationUITestContextExtensions.ClickReliablyOnAsync(UITestContext, By, int)"/> instead.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -21,7 +22,8 @@ public static class NavigationWebElementExtensions
/// https://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error.
/// </para>
/// </remarks>
public static Task ClickReliablyAsync(this IWebElement element, UITestContext context) =>
/// <param name="maxTries">The maximum number of clicks attempted altogether, if retries are needed.</param>
public static Task ClickReliablyAsync(this IWebElement element, UITestContext context, int maxTries = 3) =>
context.ExecuteLoggedAsync(
nameof(ClickReliablyAsync),
element,
Expand All @@ -34,7 +36,6 @@ await context.Configuration.Events.BeforeClick

// When the button is under some overhanging UI element, the MoveToElement sometimes fails with the
// "move target out of bounds" exception message. In this case it should be retried.
const int maxTries = 3;
var notFound = true;
for (var i = 1; notFound && i <= maxTries; i++)
{
Expand All @@ -45,6 +46,9 @@ await context.Configuration.Events.BeforeClick
}
catch (WebDriverException ex) when (i < maxTries && ex.Message.Contains("move target out of bounds"))
{
context.Configuration.TestOutputHelper.WriteLineTimestampedAndDebug(
"\"move target out of bounds\" exception, retrying the click.");

await Task.Delay(RetrySettings.Interval);
}
}
Expand All @@ -63,7 +67,7 @@ await context.Configuration.Events.AfterClick

/// <summary>
/// Repeatedly clicks an element until the browser leaves the page. If you're doing a Get() before then use <see
/// cref="NavigationUITestContextExtensions.ClickReliablyOnAsync(UITestContext, By)"/> instead.
/// cref="NavigationUITestContextExtensions.ClickReliablyOnAsync(UITestContext, By, int)"/> instead.
/// </summary>
public static void ClickReliablyUntilPageLeave(
this IWebElement element,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ namespace Lombiq.Tests.UI.Extensions;

public static class ScrollingUITestContextExtensions
{
/// <summary>
/// Scrolls to a selected element in the document.
/// </summary>
public static void ScrollTo(this UITestContext context, By by) =>
context.ScrollTo(context.Get(by).Location);

/// <summary>
/// Scrolls to a particular set of coordinates in the document.
/// </summary>
Expand Down