Skip to content

Commit

Permalink
Adding ClickReliablyOnThenWaitForUrlChangeAsync()
Browse files Browse the repository at this point in the history
  • Loading branch information
Piedone committed Feb 8, 2024
1 parent b73bccf commit 2337e75
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Lombiq.Tests.UI/Extensions/NavigationUITestContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ public static Task ClickReliablyOnUntilPageLeaveAsync(
TimeSpan? interval = null) =>
context.Get(by).ClickReliablyUntilPageLeaveAsync(context, timeout, interval);

/// <summary>
/// A convenience method that merges <see cref="ElementRetrievalUITestContextExtensions.Get"/> and <see
/// cref="NavigationWebElementExtensions.ClickReliablyThenWaitForUrlChangeAsync(IWebElement, UITestContext, TimeSpan?,
/// TimeSpan?)"/> so the <paramref name="context"/> doesn't have to be passed twice.
/// </summary>
public static Task ClickReliablyOnThenWaitForUrlChangeAsync(
this UITestContext context,
By by,
TimeSpan? timeout = null,
TimeSpan? interval = null) =>
context.Get(by).ClickReliablyThenWaitForUrlChangeAsync(context, timeout, interval);

/// <summary>
/// Switches control to JS alert box, accepts it, and switches control back to main document or first frame.
/// </summary>
Expand Down
23 changes: 22 additions & 1 deletion Lombiq.Tests.UI/Extensions/NavigationWebElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ 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, int)"/> instead.
/// cref="NavigationUITestContextExtensions.ClickReliablyOnUntilPageLeaveAsync(UITestContext, By, TimeSpan?, TimeSpan?)"/>
/// instead.
/// </summary>
public static Task ClickReliablyUntilPageLeaveAsync(
this IWebElement element,
Expand All @@ -82,4 +83,24 @@ public static Task ClickReliablyUntilPageLeaveAsync(
},
timeout,
interval);

/// <summary>
/// Repeatedly clicks an element until the browser leaves the page. If you're doing a Get() before then use <see
/// cref="NavigationUITestContextExtensions.ClickReliablyOnThenWaitForUrlChangeAsync(UITestContext, By, TimeSpan?, TimeSpan?)"/>
/// instead.
/// </summary>
public static async Task ClickReliablyThenWaitForUrlChangeAsync(
this IWebElement element,
UITestContext context,
TimeSpan? timeout = null,
TimeSpan? interval = null)
{
var originalUri = context.GetCurrentUri();
await element.ClickReliablyAsync(context);

context.DoWithRetriesOrFail(
() => context.GetCurrentUri() != originalUri,
timeout,
interval);
}
}

0 comments on commit 2337e75

Please sign in to comment.